@hasna/switcher 0.2.5 → 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/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.5";
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.5",
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: {
@@ -6738,7 +6821,7 @@ function createHandler(store, authentication, providerEnv = process.env, resolve
6738
6821
  }
6739
6822
  if (resource === "providers" && id2 && parts[3] === "refresh" && parts.length === 4 && request.method === "POST") {
6740
6823
  if (store.engine === "postgresql")
6741
- await db.unsafe("SELECT id FROM switcher_providers WHERE id = $1 FOR SHARE", [id2]);
6824
+ await db.unsafe("SELECT id FROM switcher_providers WHERE id = $1 FOR UPDATE", [id2]);
6742
6825
  const provider = await store.get("providers", id2, db);
6743
6826
  if (!refreshed || provider.version !== refreshed.provider.version)
6744
6827
  throw new Fault(409, "provider_changed", "Provider changed during discovery; refresh again.");
@@ -6755,7 +6838,7 @@ function createHandler(store, authentication, providerEnv = process.env, resolve
6755
6838
  }
6756
6839
  if (resource === "providers" && id2 && parts[3] === "catalog" && parts.length === 4 && request.method === "PUT") {
6757
6840
  if (store.engine === "postgresql")
6758
- await db.unsafe("SELECT id FROM switcher_providers WHERE id = $1 FOR SHARE", [id2]);
6841
+ await db.unsafe("SELECT id FROM switcher_providers WHERE id = $1 FOR UPDATE", [id2]);
6759
6842
  const provider = await store.get("providers", id2, db);
6760
6843
  if (provider.version !== version())
6761
6844
  throw new Fault(409, "provider_changed", "Provider changed during local discovery; refresh again.");
@@ -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
- resolved = resolvePolicyModel(policy, requested);
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) {
@@ -8152,11 +8402,16 @@ function createInferenceGateway(input, timing = {}) {
8152
8402
  throw new Error("provider_request_failed");
8153
8403
  if (!response.ok) {
8154
8404
  const overflow = await isContextOverflow(response);
8405
+ const paymentRequired = response.status === 402;
8155
8406
  if (overflow)
8156
8407
  current.reason = "context_length_exceeded";
8408
+ else if (paymentRequired)
8409
+ current.reason = "provider_payment_required";
8157
8410
  release();
8158
8411
  if (overflow)
8159
8412
  return Response.json({ type: "error", error: { type: "invalid_request_error", code: "context_length_exceeded", message: "prompt is too long: the provider context window was exceeded. Compact the conversation or start a new session." } }, { status: 400 });
8413
+ if (paymentRequired)
8414
+ return fail(402, "provider_payment_required", "The selected provider rejected this request for billing or credit limits (HTTP 402). Check the account balance, API-key spending limit, and requested output-token budget before retrying.");
8160
8415
  const rejected = fail(response.status >= 300 && response.status < 400 ? 502 : response.status, `upstream_http_${response.status}`);
8161
8416
  const retryAfter = response.headers.get("retry-after");
8162
8417
  if ((response.status === 429 || response.status === 503) && retryAfter && retryAfter.length <= 128 && (/^\d+$/.test(retryAfter) || Number.isFinite(Date.parse(retryAfter))))
@@ -8230,8 +8485,8 @@ function createInferenceGateway(input, timing = {}) {
8230
8485
  }
8231
8486
 
8232
8487
  // src/codex-model-policy.ts
8233
- import { mkdir as mkdir5, readFile as readFile2, realpath as realpath3, stat as stat4, writeFile as writeFile4 } from "fs/promises";
8234
- import { dirname as dirname4, isAbsolute as isAbsolute6, join as join6, resolve as resolve5 } from "path";
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";
8235
8490
  import { execFileSync as execFileSync2 } from "child_process";
8236
8491
  import { createHash as createHash7 } from "crypto";
8237
8492
  var dict = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
@@ -8251,7 +8506,7 @@ function codexAgentsFromEffectiveConfig(config, trustedProject = true, baseDir)
8251
8506
  const rawConfigFile = value.config_file;
8252
8507
  if (rawConfigFile !== undefined && typeof rawConfigFile !== "string")
8253
8508
  throw new Error(`Codex agents.${name}.config_file must be a string.`);
8254
- const configFile = rawConfigFile === undefined ? undefined : isAbsolute6(rawConfigFile) ? rawConfigFile : baseDir ? resolve5(baseDir, rawConfigFile) : undefined;
8509
+ const configFile = rawConfigFile === undefined ? undefined : isAbsolute8(rawConfigFile) ? rawConfigFile : baseDir ? resolve5(baseDir, rawConfigFile) : undefined;
8255
8510
  if (rawConfigFile !== undefined && !configFile)
8256
8511
  throw new Error(`Codex agents.${name}.config_file must be absolute after precedence resolution.`);
8257
8512
  const definition = { trusted: trustedProject, config_file: configFile };
@@ -8380,16 +8635,16 @@ async function writeCodexAgentOverrides(result, stateDir) {
8380
8635
  const paths = {};
8381
8636
  for (const agent of result.agents) {
8382
8637
  const digest = createHash7("sha256").update(agent.name).digest("hex").slice(0, 16);
8383
- const path = join6(root, `agent-${digest}.toml`);
8384
- await writeFile4(path, renderCodexAgentToml(agent.config), { encoding: "utf8", mode: 384, flag: "wx" });
8638
+ const path = join9(root, `agent-${digest}.toml`);
8639
+ await writeFile7(path, renderCodexAgentToml(agent.config), { encoding: "utf8", mode: 384, flag: "wx" });
8385
8640
  paths[agent.name] = path;
8386
8641
  }
8387
8642
  return paths;
8388
8643
  }
8389
8644
  async function prepareCodexModelPolicy(input) {
8390
- const home = resolve5(input.home ?? process.env.CODEX_HOME ?? join6(process.env.HOME ?? "/", ".codex"));
8645
+ const home = resolve5(input.home ?? process.env.CODEX_HOME ?? join9(process.env.HOME ?? "/", ".codex"));
8391
8646
  const cwd = resolve5(input.cwd);
8392
- const globalPath = join6(home, "config.toml");
8647
+ const globalPath = join9(home, "config.toml");
8393
8648
  const readConfig = async (path) => {
8394
8649
  let info;
8395
8650
  try {
@@ -8401,7 +8656,7 @@ async function prepareCodexModelPolicy(input) {
8401
8656
  }
8402
8657
  if (!info.isFile() || info.size > 1024 * 1024)
8403
8658
  throw new Error(`Codex config must be a regular file no larger than 1 MiB: ${path}`);
8404
- const text = await readFile2(path, "utf8");
8659
+ const text = await readFile4(path, "utf8");
8405
8660
  if (Buffer.byteLength(text) > 1024 * 1024)
8406
8661
  throw new Error(`Codex config exceeds 1 MiB: ${path}`);
8407
8662
  try {
@@ -8413,7 +8668,7 @@ async function prepareCodexModelPolicy(input) {
8413
8668
  const global = await readConfig(globalPath) ?? {};
8414
8669
  const projects = dict(global.projects) ? global.projects : {};
8415
8670
  const markers = global.project_root_markers ?? [".git"];
8416
- if (!Array.isArray(markers) || markers.some((m) => typeof m !== "string" || isAbsolute6(m) || m.includes("..")))
8671
+ if (!Array.isArray(markers) || markers.some((m) => typeof m !== "string" || isAbsolute8(m) || m.includes("..")))
8417
8672
  throw new Error("Unsupported Codex project root markers.");
8418
8673
  const ancestorDirs = [];
8419
8674
  for (let dir = cwd;; dir = dirname4(dir)) {
@@ -8426,9 +8681,9 @@ async function prepareCodexModelPolicy(input) {
8426
8681
  for (const dir of ancestorDirs)
8427
8682
  for (const marker of markers) {
8428
8683
  try {
8429
- const info = await stat4(join6(dir, marker));
8684
+ const info = await stat4(join9(dir, marker));
8430
8685
  if (marker === ".git" && info.isDirectory())
8431
- await stat4(join6(dir, marker, "HEAD"));
8686
+ await stat4(join9(dir, marker, "HEAD"));
8432
8687
  projectRoot = dir;
8433
8688
  break findRoot;
8434
8689
  } catch {}
@@ -8453,7 +8708,7 @@ async function prepareCodexModelPolicy(input) {
8453
8708
  const layers = [{ path: globalPath, config: global }];
8454
8709
  const projectDirs = ancestorDirs.slice(0, ancestorDirs.indexOf(projectRoot) + 1).reverse();
8455
8710
  for (const dir of projectDirs) {
8456
- const path = join6(dir, ".codex", "config.toml");
8711
+ const path = join9(dir, ".codex", "config.toml");
8457
8712
  if (path === globalPath)
8458
8713
  continue;
8459
8714
  const decision = await trust(dir) ?? projectTrust ?? repoTrust;
@@ -8482,13 +8737,13 @@ async function prepareCodexModelPolicy(input) {
8482
8737
  return { ...result, agentConfigPaths: await writeCodexAgentOverrides(result, input.stateDir), configPaths: loaded };
8483
8738
  }
8484
8739
  async function readCodexAgentConfig(path) {
8485
- if (!isAbsolute6(path))
8740
+ if (!isAbsolute8(path))
8486
8741
  throw new Error("Codex agent config_file must be absolute before launch.");
8487
8742
  const canonical = await realpath3(path);
8488
8743
  const info = await stat4(canonical);
8489
8744
  if (!info.isFile() || info.size > 1024 * 1024)
8490
8745
  throw new Error(`Codex agent config must be a regular file no larger than 1 MiB: ${path}`);
8491
- const text = await readFile2(canonical, "utf8");
8746
+ const text = await readFile4(canonical, "utf8");
8492
8747
  try {
8493
8748
  return Bun.TOML.parse(text);
8494
8749
  } catch {
@@ -8497,29 +8752,29 @@ async function readCodexAgentConfig(path) {
8497
8752
  }
8498
8753
 
8499
8754
  // src/harnesses.ts
8500
- import { access as access3, mkdir as mkdir10, readFile as readFile4, readdir as readdir4, writeFile as writeFile10, rm as rm2 } from "fs/promises";
8501
- import { basename as basename2, dirname as dirname7, join as join12, isAbsolute as isAbsolute11, resolve as resolve8 } from "path";
8502
- import { homedir as homedir7, tmpdir } from "os";
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";
8503
8758
  import { createHash as createHash9, randomUUID as randomUUID4, timingSafeEqual as timingSafeEqual5 } from "crypto";
8504
8759
  import { execFile as execFile2 } from "child_process";
8505
8760
  import { promisify as promisify2 } from "util";
8506
8761
  import { createConnection } from "net";
8507
8762
 
8508
8763
  // src/aider-config.ts
8509
- import { readFile as readFile3, writeFile as writeFile5, lstat as lstat3, copyFile, rename, realpath as realpath4, access as access2 } from "fs/promises";
8764
+ import { readFile as readFile5, writeFile as writeFile8, lstat as lstat5, copyFile, rename, realpath as realpath4, access as access2 } from "fs/promises";
8510
8765
  import { constants as constants3 } from "fs";
8511
- import { dirname as dirname5, basename, join as join7, resolve as resolve6, isAbsolute as isAbsolute7 } from "path";
8512
- import { homedir as homedir5 } from "os";
8766
+ import { dirname as dirname5, basename, join as join10, resolve as resolve6, isAbsolute as isAbsolute9 } from "path";
8767
+ import { homedir as homedir6 } from "os";
8513
8768
  import { parseDocument as parseDocument2 } from "yaml";
8514
8769
  var KEY2 = "SWITCHER_HARNESS_API_KEY";
8515
8770
  var object3 = (v) => !!v && typeof v === "object" && !Array.isArray(v);
8516
8771
  async function data(path) {
8517
8772
  let text;
8518
8773
  try {
8519
- const stat5 = await lstat3(path);
8774
+ const stat5 = await lstat5(path);
8520
8775
  if (!stat5.isFile() || stat5.size > 1024 * 1024)
8521
8776
  throw new Error("unsupported");
8522
- text = await readFile3(path, "utf8");
8777
+ text = await readFile5(path, "utf8");
8523
8778
  } catch (error) {
8524
8779
  if (error.code === "ENOENT")
8525
8780
  return;
@@ -8550,9 +8805,9 @@ async function gitRoot(path) {
8550
8805
  parent = dirname5(parent);
8551
8806
  }
8552
8807
  }
8553
- for (let dir = join7(parent, ...missing);; dir = dirname5(dir)) {
8808
+ for (let dir = join10(parent, ...missing);; dir = dirname5(dir)) {
8554
8809
  try {
8555
- await lstat3(join7(dir, ".git"));
8810
+ await lstat5(join10(dir, ".git"));
8556
8811
  return dir;
8557
8812
  } catch (error) {
8558
8813
  if (!["ENOENT", "ENOTDIR"].includes(error.code ?? ""))
@@ -8565,9 +8820,9 @@ async function gitRoot(path) {
8565
8820
  var falseValue = (v) => v === undefined || v === null || v === false || v === 0 || typeof v === "string" && ["", "false", "no", "off", "0"].includes(v.toLowerCase());
8566
8821
  var startup = `yes-always gui browser upgrade install-main-branch just-check-update apply-clipboard-edits test lint commit`.split(" ");
8567
8822
  var safeParameters = new Set(`max_tokens temperature top_p top_k min_p stop seed reasoning_effort thinking`.split(" "));
8568
- var expandHome = (path, home) => path === "~" ? home : path.startsWith("~/") ? join7(home, path.slice(2)) : path;
8569
- async function validateAiderConfiguration(cwd, args = [], home = process.env.HOME ?? homedir5()) {
8570
- if (!isAbsolute7(home))
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))
8571
8826
  throw new Error("Aider requires an absolute HOME to preserve native instruction paths.");
8572
8827
  const parsed = aiderArguments(args), cwdRoot = await gitRoot(cwd);
8573
8828
  const roots = new Set([resolve6(home), ...cwdRoot ? [cwdRoot] : [], resolve6(cwd)]);
@@ -8578,7 +8833,7 @@ async function validateAiderConfiguration(cwd, args = [], home = process.env.HOM
8578
8833
  }
8579
8834
  let effective = {};
8580
8835
  for (const root of roots) {
8581
- const path = join7(root, ".aider.conf.yml"), value = await data(path);
8836
+ const path = join10(root, ".aider.conf.yml"), value = await data(path);
8582
8837
  if (value !== undefined) {
8583
8838
  if (!object3(value))
8584
8839
  throw new Error(`Aider configuration must be a mapping: ${path}`);
@@ -8603,13 +8858,13 @@ async function validateAiderConfiguration(cwd, args = [], home = process.env.HOM
8603
8858
  }
8604
8859
  effective = { ...effective, ...normalized };
8605
8860
  }
8606
- const settings2 = await data(join7(root, ".aider.model.settings.yml"));
8861
+ const settings2 = await data(join10(root, ".aider.model.settings.yml"));
8607
8862
  if (settings2 !== undefined) {
8608
8863
  if (!Array.isArray(settings2))
8609
8864
  throw new Error("Aider model settings must be a list.");
8610
8865
  for (const entry of settings2)
8611
8866
  if (!object3(entry) || entry.extra_params !== undefined && (!object3(entry.extra_params) || Object.keys(entry.extra_params).some((key) => !safeParameters.has(key))))
8612
- throw new Error(`Aider custom transport or callback model settings cannot be preserved safely: ${join7(root, ".aider.model.settings.yml")}`);
8867
+ throw new Error(`Aider custom transport or callback model settings cannot be preserved safely: ${join10(root, ".aider.model.settings.yml")}`);
8613
8868
  }
8614
8869
  }
8615
8870
  if (effective.read !== undefined && !(typeof effective.read === "string" || Array.isArray(effective.read) && effective.read.every((v) => typeof v === "string")))
@@ -8630,7 +8885,7 @@ function aiderModelName(protocol, id2) {
8630
8885
  return `${protocol === "anthropic-messages" ? "anthropic" : protocol === "openai-responses" ? "openai/responses" : "openai"}/${id2}`;
8631
8886
  }
8632
8887
  async function historyFile(path) {
8633
- const stat5 = await lstat3(path);
8888
+ const stat5 = await lstat5(path);
8634
8889
  if (!stat5.isFile() || stat5.isSymbolicLink() || stat5.size > 64 * 1024 * 1024 || process.platform !== "win32" && ((stat5.mode & 63) !== 0 || stat5.uid !== process.getuid?.()))
8635
8890
  throw new Error("Aider history must be an owner-only regular file smaller than 64 MiB.");
8636
8891
  }
@@ -8645,7 +8900,7 @@ async function prepareAider(input) {
8645
8900
  const files = parsed.args.splice(literal2).slice(1);
8646
8901
  parsed.args.push(...files.map((path) => resolve6(input.cwd, path)));
8647
8902
  }
8648
- const sourceHome = process.env.HOME ?? homedir5();
8903
+ const sourceHome = process.env.HOME ?? homedir6();
8649
8904
  for (let i = 0;i < parsed.args.length; i++) {
8650
8905
  if (parsed.args[i] === "--read") {
8651
8906
  i++;
@@ -8653,39 +8908,39 @@ async function prepareAider(input) {
8653
8908
  } else if (parsed.args[i].startsWith("--read="))
8654
8909
  parsed.args[i] = "--read=" + expandHome(parsed.args[i].slice(7), sourceHome);
8655
8910
  }
8656
- const home = join7(input.stateDir, "aider-home");
8911
+ const home = join10(input.stateDir, "aider-home");
8657
8912
  await privateDirectory(home);
8658
- const originalHome = process.env.HOME ?? homedir5();
8659
- const gitSources = process.env.GIT_CONFIG_GLOBAL ? [resolve6(process.env.GIT_CONFIG_GLOBAL)] : [join7(process.env.XDG_CONFIG_HOME ?? join7(originalHome, ".config"), "git", "config"), join7(originalHome, ".gitconfig")];
8660
- const gitConfig = join7(home, ".gitconfig");
8661
- await writeFile5(gitConfig, gitSources.map((path) => `[include]
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]
8662
8917
  path = ${JSON.stringify(path)}
8663
8918
  `).join(""), { mode: 384, flag: "wx" });
8664
- const sessions = input.sessionDir ?? join7(input.stateDir, "sessions");
8919
+ const sessions = input.sessionDir ?? join10(input.stateDir, "sessions");
8665
8920
  await privateDirectory(sessions);
8666
- const id2 = crypto.randomUUID(), history = join7(sessions, `${id2}.chat.md`), inputHistory = join7(sessions, `${id2}.input`);
8921
+ const id2 = crypto.randomUUID(), history = join10(sessions, `${id2}.chat.md`), inputHistory = join10(sessions, `${id2}.input`);
8667
8922
  if (parsed.restore) {
8668
- const latest = join7(sessions, "latest.json");
8923
+ const latest = join10(sessions, "latest.json");
8669
8924
  await historyFile(latest).catch(() => {
8670
8925
  throw new Error("No valid completed Aider history is available for this profile.");
8671
8926
  });
8672
- const previous = JSON.parse(await readFile3(latest, "utf8"));
8927
+ const previous = JSON.parse(await readFile5(latest, "utf8"));
8673
8928
  if (!object3(previous) || typeof previous.id !== "string" || !/^[-a-f0-9]{36}$/.test(previous.id))
8674
8929
  throw new Error("Invalid Aider history reference.");
8675
- const source = join7(sessions, `${previous.id}.chat.md`);
8930
+ const source = join10(sessions, `${previous.id}.chat.md`);
8676
8931
  await historyFile(source);
8677
8932
  await copyFile(source, history, 1);
8678
8933
  } else
8679
- await writeFile5(history, "", { mode: 384, flag: "wx" });
8680
- const originalHistoryLength = (await readFile3(history, "utf8")).length;
8681
- await writeFile5(inputHistory, "", { mode: 384, flag: "wx" });
8934
+ await writeFile8(history, "", { mode: 384, flag: "wx" });
8935
+ const originalHistoryLength = (await readFile5(history, "utf8")).length;
8936
+ await writeFile8(inputHistory, "", { mode: 384, flag: "wx" });
8682
8937
  const model2 = aiderModelName(input.protocol, input.model);
8683
8938
  const weakModel = aiderModelName(input.protocol, input.compiledPolicy?.roles.weak ?? input.model), editorModel = aiderModelName(input.protocol, input.compiledPolicy?.roles.editor ?? input.model);
8684
8939
  const extra = { api_base: input.protocol === "anthropic-messages" ? input.baseUrl.replace(/\/v1$/i, "") : input.baseUrl, api_key: `os.environ/${KEY2}` };
8685
- const settings2 = join7(input.stateDir, "aider-model-settings.json"), metadata = join7(input.stateDir, "aider-model-metadata.json"), config = join7(input.stateDir, "aider-config.json"), empty = join7(input.stateDir, "aider-empty.env");
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");
8686
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 }));
8687
- await writeFile5(settings2, JSON.stringify([...definitions, { name: "aider/extra_params", extra_params: extra }]), { mode: 384, flag: "wx" });
8688
- await writeFile5(metadata, JSON.stringify(Object.fromEntries(input.models.map((m) => [aiderModelName(input.protocol, m.id), {
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), {
8689
8944
  ...m.contextWindow ? { max_input_tokens: m.contextWindow } : {},
8690
8945
  ...m.maxOutputTokens ? { max_output_tokens: m.maxOutputTokens, max_tokens: m.maxOutputTokens } : {},
8691
8946
  litellm_provider: input.protocol === "anthropic-messages" ? "anthropic" : "openai",
@@ -8694,14 +8949,14 @@ async function prepareAider(input) {
8694
8949
  }]))), { mode: 384, flag: "wx" });
8695
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(" "));
8696
8951
  const preserved = Object.fromEntries(Object.entries(global).filter(([key]) => !ignored.has(key) && !startup.includes(key)));
8697
- await writeFile5(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" });
8698
- await writeFile5(empty, "", { mode: 384, flag: "wx" });
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" });
8699
8954
  const aliases = ["--alias", `switcher-${id2}:${model2}`];
8700
8955
  let cleaned = false;
8701
8956
  return {
8702
8957
  executable: input.executable ?? "aider",
8703
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],
8704
- env: { HOME: home, XDG_CONFIG_HOME: join7(home, "config"), XDG_CACHE_HOME: join7(home, "cache"), XDG_DATA_HOME: join7(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 },
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 },
8705
8960
  configPaths: [config, settings2, metadata, empty, gitConfig],
8706
8961
  warnings: [
8707
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."] : [],
@@ -8715,11 +8970,11 @@ async function prepareAider(input) {
8715
8970
  return;
8716
8971
  cleaned = true;
8717
8972
  await historyFile(history);
8718
- if (!/^#### /m.test((await readFile3(history, "utf8")).slice(originalHistoryLength)))
8973
+ if (!/^#### /m.test((await readFile5(history, "utf8")).slice(originalHistoryLength)))
8719
8974
  return;
8720
- const pending = join7(sessions, `${id2}.latest.json`);
8721
- await writeFile5(pending, JSON.stringify({ id: id2 }), { mode: 384, flag: "wx" });
8722
- await rename(pending, join7(sessions, "latest.json"));
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"));
8723
8978
  }
8724
8979
  };
8725
8980
  }
@@ -8801,9 +9056,9 @@ function validateGrokResume(args) {
8801
9056
  }
8802
9057
 
8803
9058
  // src/cline-backend.ts
8804
- import { mkdir as mkdir6, writeFile as writeFile6 } from "fs/promises";
9059
+ import { mkdir as mkdir6, writeFile as writeFile9 } from "fs/promises";
8805
9060
  import { randomUUID as randomUUID2 } from "crypto";
8806
- import { isAbsolute as isAbsolute8, join as join8 } from "path";
9061
+ import { isAbsolute as isAbsolute10, join as join11 } from "path";
8807
9062
  var ENV_BY_PROTOCOL = {
8808
9063
  "anthropic-messages": "ANTHROPIC_API_KEY",
8809
9064
  "openai-responses": "OPENAI_API_KEY",
@@ -8829,7 +9084,7 @@ function modelEntry(model2, protocol) {
8829
9084
  };
8830
9085
  }
8831
9086
  async function writeJson(path, value) {
8832
- await writeFile6(path, `${JSON.stringify(value, null, 2)}
9087
+ await writeFile9(path, `${JSON.stringify(value, null, 2)}
8833
9088
  `, { mode: 384, flag: "wx" });
8834
9089
  return path;
8835
9090
  }
@@ -8849,18 +9104,18 @@ async function prepareClineLaunch(input) {
8849
9104
  throw new Error(`Cline ${input.protocol} uses ${mapping.authStyle} authentication; use a provider with the native Cline auth contract.`);
8850
9105
  if (input.credential && /[\r\n]/.test(input.credential))
8851
9106
  throw new Error("Provider credential contains invalid header characters.");
8852
- if (!isAbsolute8(input.stateDir) || !isAbsolute8(input.cwd))
9107
+ if (!isAbsolute10(input.stateDir) || !isAbsolute10(input.cwd))
8853
9108
  throw new Error("Launch state and working directories must be absolute.");
8854
- const dataDir = join8(input.stateDir, "cline-data");
8855
- const sessionDir = input.sessionDir ?? join8(dataDir, "sessions");
8856
- const launchDir = join8(input.stateDir, `cline-launch-${randomUUID2()}`);
8857
- const settingsDir = join8(launchDir, "settings");
8858
- const configDir = join8(launchDir, "config");
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");
8859
9114
  await mkdir6(settingsDir, { recursive: true, mode: 448 });
8860
9115
  await mkdir6(configDir, { recursive: true, mode: 448 });
8861
9116
  const baseUrl = endpoint(input.baseUrl);
8862
9117
  const providerId = mapping.providerId;
8863
- const providersPath = await writeJson(join8(settingsDir, "providers.json"), {
9118
+ const providersPath = await writeJson(join11(settingsDir, "providers.json"), {
8864
9119
  version: 1,
8865
9120
  lastUsedProvider: providerId,
8866
9121
  modes: {},
@@ -8880,7 +9135,7 @@ async function prepareClineLaunch(input) {
8880
9135
  }
8881
9136
  }
8882
9137
  });
8883
- const modelsPath = await writeJson(join8(settingsDir, "models.json"), {
9138
+ const modelsPath = await writeJson(join11(settingsDir, "models.json"), {
8884
9139
  version: 1,
8885
9140
  providers: {
8886
9141
  [providerId]: {
@@ -8929,10 +9184,10 @@ async function prepareClineLaunch(input) {
8929
9184
  }
8930
9185
 
8931
9186
  // src/opencode2-config.ts
8932
- import { mkdir as mkdir7, open as open2, realpath as realpath5, readdir as readdir3, stat as stat5, writeFile as writeFile7 } from "fs/promises";
9187
+ import { mkdir as mkdir7, open as open2, realpath as realpath5, readdir as readdir3, stat as stat5, writeFile as writeFile10 } from "fs/promises";
8933
9188
  import { constants as constants4 } from "fs";
8934
- import { dirname as dirname6, isAbsolute as isAbsolute9, join as join9, relative as relative4, resolve as resolve7 } from "path";
8935
- import { homedir as homedir6 } from "os";
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";
8936
9191
  import { randomUUID as randomUUID3 } from "crypto";
8937
9192
  import { Database as Database2 } from "bun:sqlite";
8938
9193
  import { parse as parse3, parseTree as parseTree3 } from "jsonc-parser";
@@ -8947,7 +9202,7 @@ var maxTotalBytes2 = 8 * 1024 * 1024;
8947
9202
  var maxFiles2 = 256;
8948
9203
  var inside2 = (root, path) => {
8949
9204
  const rel = relative4(root, path);
8950
- return rel === "" || !isAbsolute9(rel) && rel !== ".." && !rel.startsWith("../");
9205
+ return rel === "" || !isAbsolute11(rel) && rel !== ".." && !rel.startsWith("../");
8951
9206
  };
8952
9207
  var action = (value) => ({ bash: "shell", task: "subagent", write: "edit", patch: "edit" })[value] ?? value;
8953
9208
  function invalid2(path, field) {
@@ -8999,7 +9254,7 @@ function permissions(value, path, home) {
8999
9254
  literal2(item.resource, path, "permission resource");
9000
9255
  if (!["read", "edit", "external_directory"].includes(item.action))
9001
9256
  return item;
9002
- const resource = item.resource === "~" || item.resource === "$HOME" ? home : item.resource.startsWith("~/") ? join9(home, item.resource.slice(2)) : item.resource.startsWith("$HOME/") || item.resource.startsWith("$HOME\\") ? join9(home, item.resource.slice(6)) : item.resource;
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;
9003
9258
  return { ...item, resource };
9004
9259
  });
9005
9260
  }
@@ -9027,8 +9282,8 @@ function jsonc2(text, path) {
9027
9282
  return record2(value, path, "configuration object");
9028
9283
  }
9029
9284
  async function checkRemoteConfiguration(dataHome) {
9030
- const path = join9(dataHome, "opencode", "opencode.db");
9031
- const legacyAuth = await stat5(join9(dataHome, "opencode", "auth.json")).then(() => true, (error) => {
9285
+ const path = join12(dataHome, "opencode", "opencode.db");
9286
+ const legacyAuth = await stat5(join12(dataHome, "opencode", "auth.json")).then(() => true, (error) => {
9032
9287
  if (error.code === "ENOENT")
9033
9288
  return false;
9034
9289
  throw error;
@@ -9068,16 +9323,16 @@ async function checkRemoteConfiguration(dataHome) {
9068
9323
  }
9069
9324
  async function isolateOpenCode2(cwd, stateDir, providerID, env = process.env) {
9070
9325
  for (const name of ["HOME", "XDG_CONFIG_HOME", "XDG_DATA_HOME", "OPENCODE_CONFIG_DIR"])
9071
- if (env[name] && !isAbsolute9(env[name]))
9326
+ if (env[name] && !isAbsolute11(env[name]))
9072
9327
  throw new Error(`OpenCode 2 requires an absolute ${name} to preserve native configuration authority.`);
9073
- const home = resolve7(env.HOME || homedir6());
9074
- const configRoot = resolve7(env.OPENCODE_CONFIG_DIR || join9(env.XDG_CONFIG_HOME || join9(home, ".config"), "opencode"));
9328
+ const home = resolve7(env.HOME || homedir7());
9329
+ const configRoot = resolve7(env.OPENCODE_CONFIG_DIR || join12(env.XDG_CONFIG_HOME || join12(home, ".config"), "opencode"));
9075
9330
  const canonicalConfigRoot = await realpath5(configRoot).catch((error) => {
9076
9331
  if (error.code === "ENOENT")
9077
9332
  return configRoot;
9078
9333
  throw error;
9079
9334
  });
9080
- const dataHome = resolve7(env.XDG_DATA_HOME || join9(home, ".local", "share"));
9335
+ const dataHome = resolve7(env.XDG_DATA_HOME || join12(home, ".local", "share"));
9081
9336
  await checkRemoteConfiguration(dataHome);
9082
9337
  let files = 0, total = 0;
9083
9338
  const paths = [];
@@ -9117,7 +9372,7 @@ async function isolateOpenCode2(cwd, stateDir, providerID, env = process.env) {
9117
9372
  invalid2(path, "agent prompt environment reference");
9118
9373
  let result = "", cursor = 0;
9119
9374
  for (const match of text.matchAll(/\{file:([^}]+)\}/g)) {
9120
- const requested = match[1].startsWith("~/") ? join9(home, match[1].slice(2)) : resolve7(dirname6(path), match[1]);
9375
+ const requested = match[1].startsWith("~/") ? join12(home, match[1].slice(2)) : resolve7(dirname6(path), match[1]);
9121
9376
  const content = (await read(requested, false)).trim();
9122
9377
  literal2(content, requested, "nested prompt variable reference");
9123
9378
  result += text.slice(cursor, match.index) + content;
@@ -9139,7 +9394,7 @@ async function isolateOpenCode2(cwd, stateDir, providerID, env = process.env) {
9139
9394
  }
9140
9395
  async function agentsDirectory(directory2) {
9141
9396
  for (const source of ["agent", "agents", "mode", "modes"]) {
9142
- const base = join9(directory2, source), entries = [];
9397
+ const base = join12(directory2, source), entries = [];
9143
9398
  const visited = new Set;
9144
9399
  let examined = 0;
9145
9400
  async function walk(dir, depth) {
@@ -9158,7 +9413,7 @@ async function isolateOpenCode2(cwd, stateDir, providerID, env = process.env) {
9158
9413
  if (depth > 16 || (examined += names.length) > maxFiles2)
9159
9414
  throw new Error("OpenCode 2 agent policy exceeds its bounded directory limit.");
9160
9415
  for (const name of names) {
9161
- const path = join9(dir, name);
9416
+ const path = join12(dir, name);
9162
9417
  const info = await stat5(path);
9163
9418
  if (info.isDirectory()) {
9164
9419
  if (source === "agent" || source === "agents")
@@ -9192,8 +9447,8 @@ async function isolateOpenCode2(cwd, stateDir, providerID, env = process.env) {
9192
9447
  }
9193
9448
  }
9194
9449
  async function directory(path) {
9195
- await document(join9(path, "opencode.json"));
9196
- await document(join9(path, "opencode.jsonc"));
9450
+ await document(join12(path, "opencode.json"));
9451
+ await document(join12(path, "opencode.jsonc"));
9197
9452
  await agentsDirectory(path);
9198
9453
  }
9199
9454
  await directory(configRoot);
@@ -9208,11 +9463,11 @@ async function isolateOpenCode2(cwd, stateDir, providerID, env = process.env) {
9208
9463
  const projectEnabled = !["1", "true"].includes((env.OPENCODE_CONFIG_PROJECT_DISABLE ?? env.OPENCODE_DISABLE_PROJECT_CONFIG ?? "").toLowerCase());
9209
9464
  if (projectEnabled) {
9210
9465
  for (const path of [...ancestors].reverse()) {
9211
- await document(join9(path, "opencode.json"));
9212
- await document(join9(path, "opencode.jsonc"));
9466
+ await document(join12(path, "opencode.json"));
9467
+ await document(join12(path, "opencode.jsonc"));
9213
9468
  }
9214
9469
  for (const path of [...ancestors].reverse()) {
9215
- const candidate = join9(path, ".opencode");
9470
+ const candidate = join12(path, ".opencode");
9216
9471
  const canonical = await realpath5(candidate).catch((error) => {
9217
9472
  if (error.code === "ENOENT")
9218
9473
  return candidate;
@@ -9223,7 +9478,7 @@ async function isolateOpenCode2(cwd, stateDir, providerID, env = process.env) {
9223
9478
  }
9224
9479
  }
9225
9480
  if (env.OPENCODE_CONFIG_CONTENT)
9226
- documents.push({ path: join9(cwd, "OPENCODE_CONFIG_CONTENT"), value: jsonc2(env.OPENCODE_CONFIG_CONTENT, "OPENCODE_CONFIG_CONTENT") });
9481
+ documents.push({ path: join12(cwd, "OPENCODE_CONFIG_CONTENT"), value: jsonc2(env.OPENCODE_CONFIG_CONTENT, "OPENCODE_CONFIG_CONTENT") });
9227
9482
  const policy = [];
9228
9483
  const agents = Object.create(null);
9229
9484
  let defaultAgent;
@@ -9316,34 +9571,34 @@ async function isolateOpenCode2(cwd, stateDir, providerID, env = process.env) {
9316
9571
  instructions.push(`Instructions from: ${path}
9317
9572
  ${content}`);
9318
9573
  }
9319
- await instruction(join9(configRoot, "AGENTS.md"));
9574
+ await instruction(join12(configRoot, "AGENTS.md"));
9320
9575
  if (projectEnabled) {
9321
9576
  let stop = resolve7(cwd);
9322
9577
  if (inside2(home, resolve7(cwd)))
9323
9578
  stop = home;
9324
9579
  else
9325
9580
  for (const path of ancestors) {
9326
- if (await stat5(join9(path, ".git")).then(() => true, () => false)) {
9581
+ if (await stat5(join12(path, ".git")).then(() => true, () => false)) {
9327
9582
  stop = path;
9328
9583
  break;
9329
9584
  }
9330
9585
  }
9331
9586
  for (const path of ancestors) {
9332
- await instruction(join9(path, "AGENTS.md"));
9587
+ await instruction(join12(path, "AGENTS.md"));
9333
9588
  if (path === stop)
9334
9589
  break;
9335
9590
  }
9336
9591
  }
9337
- const privateHome = join9(stateDir, "opencode-home"), privateConfig = join9(stateDir, "opencode-config");
9338
- const instructionFile = join9(privateConfig, "opencode", "AGENTS.md");
9592
+ const privateHome = join12(stateDir, "opencode-home"), privateConfig = join12(stateDir, "opencode-config");
9593
+ const instructionFile = join12(privateConfig, "opencode", "AGENTS.md");
9339
9594
  await mkdir7(dirname6(instructionFile), { recursive: true, mode: 448 });
9340
9595
  await mkdir7(privateHome, { recursive: true, mode: 448 });
9341
- await writeFile7(instructionFile, instructions.join(`
9596
+ await writeFile10(instructionFile, instructions.join(`
9342
9597
 
9343
9598
  `), { flag: "wx", mode: 384 });
9344
9599
  return {
9345
9600
  config: { permissions: policy, agents, ...defaultAgent ? { default_agent: defaultAgent } : {}, experimental: { policies: [{ action: "provider.use", resource: "*", effect: "deny" }, { action: "provider.use", resource: providerID, effect: "allow" }] } },
9346
- env: { HOME: privateHome, XDG_CONFIG_HOME: privateConfig, OPENCODE_CONFIG_DIR: join9(privateConfig, "opencode"), XDG_CACHE_HOME: join9(stateDir, "opencode-cache"), XDG_STATE_HOME: join9(stateDir, "opencode-state"), XDG_DATA_HOME: dataHome, OPENCODE_DISABLE_PROJECT_CONFIG: "true", OPENCODE_CONFIG_PROJECT_DISABLE: "true", OPENCODE_DISABLE_MODELS_FETCH: "true" },
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" },
9347
9602
  instructionFile,
9348
9603
  sourcePaths: paths
9349
9604
  };
@@ -9358,8 +9613,8 @@ function openCode2ConfigText(config, providerID, keyEnv) {
9358
9613
  }
9359
9614
 
9360
9615
  // src/omp-backend.ts
9361
- import { mkdir as mkdir8, rm, writeFile as writeFile8 } from "fs/promises";
9362
- import { join as join10 } from "path";
9616
+ import { mkdir as mkdir8, rm, writeFile as writeFile11 } from "fs/promises";
9617
+ import { join as join13 } from "path";
9363
9618
  var KEY3 = "SWITCHER_HARNESS_API_KEY";
9364
9619
  var API = {
9365
9620
  "anthropic-messages": "anthropic-messages",
@@ -9384,8 +9639,8 @@ async function prepareOmpLaunch(input) {
9384
9639
  const baseUrl = endpoint(input.baseUrl);
9385
9640
  if (input.credential && /[\r\n]/.test(input.credential))
9386
9641
  throw new Error("Provider credential contains invalid header characters.");
9387
- const agentDir = join10(input.stateDir, "omp-agent");
9388
- const sessionDir = input.sessionDir ?? join10(input.stateDir, "sessions");
9642
+ const agentDir = join13(input.stateDir, "omp-agent");
9643
+ const sessionDir = input.sessionDir ?? join13(input.stateDir, "sessions");
9389
9644
  await mkdir8(agentDir, { recursive: true, mode: 448 });
9390
9645
  await mkdir8(sessionDir, { recursive: true, mode: 448 });
9391
9646
  const api = API[input.protocol];
@@ -9411,12 +9666,12 @@ async function prepareOmpLaunch(input) {
9411
9666
  provider.apiKey = KEY3;
9412
9667
  provider.authHeader = true;
9413
9668
  }
9414
- const modelsPath = join10(agentDir, "models.yml");
9415
- const configPath = join10(agentDir, "config.yml");
9669
+ const modelsPath = join13(agentDir, "models.yml");
9670
+ const configPath = join13(agentDir, "config.yml");
9416
9671
  const selector = `switcher/${input.model}`;
9417
- await writeFile8(modelsPath, JSON.stringify({ providers: { switcher: provider } }, null, 2) + `
9672
+ await writeFile11(modelsPath, JSON.stringify({ providers: { switcher: provider } }, null, 2) + `
9418
9673
  `, { mode: 384, flag: "wx" });
9419
- await writeFile8(configPath, JSON.stringify({
9674
+ await writeFile11(configPath, JSON.stringify({
9420
9675
  enabledModels: ["switcher/**"],
9421
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}` }
9422
9677
  }, null, 2) + `
@@ -9489,8 +9744,8 @@ function compileHermesModelPolicy(currentModel, roles2, baseUrl, apiMode = "chat
9489
9744
 
9490
9745
  // src/hermes-backend.ts
9491
9746
  import { createHash as createHash8, timingSafeEqual as timingSafeEqual4 } from "crypto";
9492
- import { mkdir as mkdir9, symlink as symlink2, writeFile as writeFile9 } from "fs/promises";
9493
- import { isAbsolute as isAbsolute10, join as join11 } from "path";
9747
+ import { mkdir as mkdir9, symlink as symlink3, writeFile as writeFile12 } from "fs/promises";
9748
+ import { isAbsolute as isAbsolute12, join as join14 } from "path";
9494
9749
  var hermesApiMode = {
9495
9750
  "anthropic-messages": "anthropic_messages",
9496
9751
  "openai-responses": "codex_responses",
@@ -9634,7 +9889,7 @@ function createHermesBridge(input, timing = {}) {
9634
9889
  };
9635
9890
  }
9636
9891
  async function prepareHermesLaunch(input) {
9637
- if (!isAbsolute10(input.stateDir) || !isAbsolute10(input.cwd))
9892
+ if (!isAbsolute12(input.stateDir) || !isAbsolute12(input.cwd))
9638
9893
  throw new Error("Launch state and working directories must be absolute.");
9639
9894
  if (input.protocol !== "anthropic-messages" && input.protocol !== "openai-responses" && input.protocol !== "openai-chat")
9640
9895
  throw new Error("Hermes does not support this provider protocol.");
@@ -9644,12 +9899,12 @@ async function prepareHermesLaunch(input) {
9644
9899
  throw new Error("Hermes cannot safely select model IDs that differ only by letter case; update the provider catalog.");
9645
9900
  if (input.credential && /[\r\n]/.test(input.credential))
9646
9901
  throw new Error("Provider credential contains invalid header characters.");
9647
- const sessionDir = input.sessionDir ?? join11(input.stateDir, "hermes-session");
9648
- const sessionsDir = join11(sessionDir, "sessions");
9902
+ const sessionDir = input.sessionDir ?? join14(input.stateDir, "hermes-session");
9903
+ const sessionsDir = join14(sessionDir, "sessions");
9649
9904
  await mkdir9(input.stateDir, { recursive: true, mode: 448 });
9650
9905
  await mkdir9(sessionsDir, { recursive: true, mode: 448 });
9651
- await symlink2(join11(sessionDir, "state.db"), join11(input.stateDir, "state.db"));
9652
- await symlink2(sessionsDir, join11(input.stateDir, "sessions"));
9906
+ await symlink3(join14(sessionDir, "state.db"), join14(input.stateDir, "state.db"));
9907
+ await symlink3(sessionsDir, join14(input.stateDir, "sessions"));
9653
9908
  const bridge = createHermesBridge(input);
9654
9909
  let policy;
9655
9910
  try {
@@ -9677,9 +9932,9 @@ async function prepareHermesLaunch(input) {
9677
9932
  }
9678
9933
  }
9679
9934
  };
9680
- const configPath = join11(input.stateDir, "config.yaml");
9935
+ const configPath = join14(input.stateDir, "config.yaml");
9681
9936
  try {
9682
- await writeFile9(configPath, JSON.stringify(config, null, 2) + `
9937
+ await writeFile12(configPath, JSON.stringify(config, null, 2) + `
9683
9938
  `, { mode: 384, flag: "wx" });
9684
9939
  } catch (error) {
9685
9940
  await bridge.cleanup();
@@ -9694,7 +9949,7 @@ async function prepareHermesLaunch(input) {
9694
9949
  SWITCHER_HERMES_AUX_API_KEY: bridge.token,
9695
9950
  OPENAI_API_KEY: bridge.token,
9696
9951
  OPENAI_BASE_URL: bridge.baseUrl,
9697
- CODEX_HOME: join11(input.stateDir, "codex-home")
9952
+ CODEX_HOME: join14(input.stateDir, "codex-home")
9698
9953
  },
9699
9954
  configPaths: [configPath],
9700
9955
  warnings: [
@@ -9708,6 +9963,8 @@ async function prepareHermesLaunch(input) {
9708
9963
 
9709
9964
  // src/harness-installation.ts
9710
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" },
9711
9968
  claude: {
9712
9969
  displayName: "Claude Code",
9713
9970
  executable: "claude",
@@ -9836,8 +10093,8 @@ var execute2 = promisify2(execFile2);
9836
10093
  var KEY4 = "SWITCHER_HARNESS_API_KEY";
9837
10094
  var quote = (value) => JSON.stringify(value);
9838
10095
  async function detectHarness(harness, override) {
9839
- const executable = override ?? Bun.which(harness) ?? harness;
9840
10096
  const installation = harnessInstallation(harness);
10097
+ const executable = override ?? Bun.which(installation.executable) ?? installation.executable;
9841
10098
  try {
9842
10099
  const { stdout, stderr } = await execute2(executable, ["--version"], { timeout: 8000, maxBuffer: 65536, env: childEnvironment() });
9843
10100
  return { harness, executable, available: true, version: (stdout.trim() || stderr.trim()).slice(0, 200), installation };
@@ -9852,6 +10109,10 @@ async function validateHarnessConfiguration(harness, cwd, args = []) {
9852
10109
  await validateAiderConfiguration(cwd, args);
9853
10110
  if (harness === "gemini")
9854
10111
  await validateGeminiConfiguration(cwd);
10112
+ if (harness === "antigravity")
10113
+ await validateAntigravityConfiguration(cwd);
10114
+ if (harness === "junie")
10115
+ await validateJunieConfiguration(cwd);
9855
10116
  }
9856
10117
  var versionAtLeast2 = (raw, minimum) => {
9857
10118
  const match = raw?.match(/(\d+)\.(\d+)\.(\d+)/);
@@ -9867,6 +10128,10 @@ var versionAtLeast2 = (raw, minimum) => {
9867
10128
  return true;
9868
10129
  };
9869
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.");
9870
10135
  if (harness === "kilo" && !versionAtLeast2(version, [7, 5, 15]))
9871
10136
  throw new Error("Kilo >=7.5.15 is required by this scoped provider bridge.");
9872
10137
  if (harness === "omp" && !versionAtLeast2(version, [18, 1, 11]))
@@ -9900,8 +10165,8 @@ function validateHarnessVersion(harness, version) {
9900
10165
  throw new Error("Gemini CLI 0.58.0 is required by the verified native settings and argument contract.");
9901
10166
  }
9902
10167
  async function jsonFile(dir, name, value) {
9903
- const path = join12(dir, name);
9904
- await writeFile10(path, JSON.stringify(value, null, 2) + `
10168
+ const path = join15(dir, name);
10169
+ await writeFile13(path, JSON.stringify(value, null, 2) + `
9905
10170
  `, { mode: 384, flag: "wx" });
9906
10171
  return path;
9907
10172
  }
@@ -9909,7 +10174,7 @@ async function projectInstructionPaths(cwd) {
9909
10174
  let dir = resolve8(cwd);
9910
10175
  while (true) {
9911
10176
  for (const name of ["AGENTS.md", "CLAUDE.md", "CONTEXT.md"]) {
9912
- const path = join12(dir, name);
10177
+ const path = join15(dir, name);
9913
10178
  if (await access3(path).then(() => true, () => false))
9914
10179
  return [path];
9915
10180
  }
@@ -9986,7 +10251,7 @@ function expandHomePattern(value) {
9986
10251
  const record3 = value;
9987
10252
  const output = {};
9988
10253
  for (const [key, item] of Object.entries(record3)) {
9989
- const expanded = key === "~" ? homedir7() : key.startsWith("~/") ? join12(homedir7(), key.slice(2)) : key;
10254
+ const expanded = key === "~" ? homedir8() : key.startsWith("~/") ? join15(homedir8(), key.slice(2)) : key;
9990
10255
  output[expanded] = expandHomePattern(item);
9991
10256
  }
9992
10257
  return output;
@@ -10042,7 +10307,7 @@ function decodePolicy(text, file) {
10042
10307
  async function readPolicyFile(file) {
10043
10308
  let text;
10044
10309
  try {
10045
- text = await readFile4(file, "utf8");
10310
+ text = await readFile6(file, "utf8");
10046
10311
  } catch (error) {
10047
10312
  if (error.code === "ENOENT")
10048
10313
  return;
@@ -10062,7 +10327,7 @@ async function agentPolicyFiles(dir, kind) {
10062
10327
  throw error;
10063
10328
  }
10064
10329
  for (const entry of entries) {
10065
- const file = join12(current, entry.name);
10330
+ const file = join15(current, entry.name);
10066
10331
  if (entry.isDirectory())
10067
10332
  await visit(file, root);
10068
10333
  else if (entry.isFile() && entry.name.endsWith(".md"))
@@ -10070,11 +10335,11 @@ async function agentPolicyFiles(dir, kind) {
10070
10335
  }
10071
10336
  };
10072
10337
  for (const rootName of [kind, `${kind}s`])
10073
- await visit(join12(dir, rootName), join12(dir, rootName));
10338
+ await visit(join15(dir, rootName), join15(dir, rootName));
10074
10339
  return result.sort((a, b) => a.file.localeCompare(b.file));
10075
10340
  }
10076
10341
  async function readAgentPolicyFile(file, kind, root) {
10077
- const text = await readFile4(file, "utf8");
10342
+ const text = await readFile6(file, "utf8");
10078
10343
  const match = text.match(/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
10079
10344
  if (!match)
10080
10345
  return;
@@ -10126,9 +10391,9 @@ async function preservedOpenCodePolicy(cwd) {
10126
10391
  result.mode = { ...result.mode ?? {}, [policy.name]: { permission: merged } };
10127
10392
  }
10128
10393
  };
10129
- const originalConfig = join12(process.env.XDG_CONFIG_HOME ?? join12(homedir7(), ".config"), "opencode");
10394
+ const originalConfig = join15(process.env.XDG_CONFIG_HOME ?? join15(homedir8(), ".config"), "opencode");
10130
10395
  for (const name of ["config.json", "opencode.json", "opencode.jsonc"])
10131
- await apply(join12(originalConfig, name));
10396
+ await apply(join15(originalConfig, name));
10132
10397
  await applyMarkdown(originalConfig, "agent");
10133
10398
  await applyMarkdown(originalConfig, "mode");
10134
10399
  if (process.env.OPENCODE_CONFIG)
@@ -10144,22 +10409,22 @@ async function preservedOpenCodePolicy(cwd) {
10144
10409
  }
10145
10410
  for (const current of [...dirs].reverse())
10146
10411
  for (const name of ["opencode.jsonc", "opencode.json"])
10147
- await apply(join12(current, name));
10412
+ await apply(join15(current, name));
10148
10413
  for (const current of dirs) {
10149
- const configDir = join12(current, ".opencode");
10414
+ const configDir = join15(current, ".opencode");
10150
10415
  for (const name of ["opencode.json", "opencode.jsonc"])
10151
- await apply(join12(configDir, name));
10416
+ await apply(join15(configDir, name));
10152
10417
  await applyMarkdown(configDir, "agent");
10153
10418
  await applyMarkdown(configDir, "mode");
10154
10419
  }
10155
- const homeConfig = join12(homedir7(), ".opencode");
10420
+ const homeConfig = join15(homedir8(), ".opencode");
10156
10421
  for (const name of ["opencode.json", "opencode.jsonc"])
10157
- await apply(join12(homeConfig, name));
10422
+ await apply(join15(homeConfig, name));
10158
10423
  await applyMarkdown(homeConfig, "agent");
10159
10424
  await applyMarkdown(homeConfig, "mode");
10160
10425
  if (process.env.OPENCODE_CONFIG_DIR) {
10161
10426
  for (const name of ["opencode.json", "opencode.jsonc"])
10162
- await apply(join12(process.env.OPENCODE_CONFIG_DIR, name));
10427
+ await apply(join15(process.env.OPENCODE_CONFIG_DIR, name));
10163
10428
  await applyMarkdown(process.env.OPENCODE_CONFIG_DIR, "agent");
10164
10429
  await applyMarkdown(process.env.OPENCODE_CONFIG_DIR, "mode");
10165
10430
  }
@@ -10330,20 +10595,20 @@ var PRIME_DAEMON_STARTUP_TIMEOUT_MS = 30000;
10330
10595
  var PRIME_DAEMON_SHUTDOWN_TIMEOUT_MS = 5000;
10331
10596
  function primeSocketPaths(runtimeDir) {
10332
10597
  const basename3 = `p-${randomUUID4().replaceAll("-", "").slice(0, 8)}.sock`;
10333
- const daemonSocket = join12(runtimeDir, basename3);
10598
+ const daemonSocket = join15(runtimeDir, basename3);
10334
10599
  const uid = typeof process.getuid === "function" ? String(process.getuid()) : "user";
10335
- const workerDir = join12(runtimeDir, `prime-agent-${uid}`);
10600
+ const workerDir = join15(runtimeDir, `prime-agent-${uid}`);
10336
10601
  const workerKey = createHash9("sha256").update(daemonSocket).digest("hex").slice(0, 12);
10337
- const workerSocket = join12(workerDir, `worker-${workerKey}-${"x".repeat(12)}.sock`);
10602
+ const workerSocket = join15(workerDir, `worker-${workerKey}-${"x".repeat(12)}.sock`);
10338
10603
  const overlong = [daemonSocket, workerSocket].find((path) => Buffer.byteLength(path, "utf8") > PRIME_UNIX_SOCKET_LIMIT);
10339
- return { daemonSocket, runtimeDir, workerDir, workerPrefix: join12(workerDir, `worker-${workerKey}-`), overlong };
10604
+ return { daemonSocket, runtimeDir, workerDir, workerPrefix: join15(workerDir, `worker-${workerKey}-`), overlong };
10340
10605
  }
10341
10606
  async function primeSocketInfo() {
10342
10607
  const requested = tmpdir();
10343
10608
  const direct = primeSocketPaths(requested);
10344
10609
  if (!direct.overlong)
10345
10610
  return direct;
10346
- const fallback = join12(switcherHome(), "r");
10611
+ const fallback = join15(switcherHome(), "r");
10347
10612
  await privateDirectory(switcherHome());
10348
10613
  await privateDirectory(fallback);
10349
10614
  const scoped = primeSocketPaths(fallback);
@@ -10524,7 +10789,7 @@ async function primeRemainingSockets(socketPath, workerPrefix) {
10524
10789
  const workerDir = workerPrefix.slice(0, workerPrefix.lastIndexOf("/"));
10525
10790
  const prefix = workerPrefix.slice(workerPrefix.lastIndexOf("/") + 1);
10526
10791
  const workers = await readdir4(workerDir).then((entries) => entries.filter((entry) => entry.startsWith(prefix)), () => []);
10527
- return [...daemon ? [socketPath] : [], ...workers.map((entry) => join12(workerDir, entry))];
10792
+ return [...daemon ? [socketPath] : [], ...workers.map((entry) => join15(workerDir, entry))];
10528
10793
  }
10529
10794
  function primeModel(input, api) {
10530
10795
  return input.models.map((model3) => ({
@@ -10542,7 +10807,7 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
10542
10807
  if (!compatible(input.harness, input.protocol))
10543
10808
  throw new Error("Harness and provider protocol are incompatible.");
10544
10809
  validateHarnessVersion(input.harness, input.version);
10545
- if (!isAbsolute11(input.stateDir) || !isAbsolute11(input.cwd))
10810
+ if (!isAbsolute13(input.stateDir) || !isAbsolute13(input.cwd))
10546
10811
  throw new Error("Launch state and working directories must be absolute.");
10547
10812
  if (!input.models.length || !input.models.some((m) => m.id === input.model))
10548
10813
  throw new Error("Selected model is missing from the launch catalog.");
@@ -10561,6 +10826,10 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
10561
10826
  warnings.push(`${missing} catalog models have no declared context limit; native fallback limits may be inaccurate.`);
10562
10827
  if (input.harness === "gemini")
10563
10828
  return prepareGemini(input);
10829
+ if (input.harness === "antigravity")
10830
+ return prepareAntigravity(input);
10831
+ if (input.harness === "junie")
10832
+ return prepareJunie(input);
10564
10833
  if (input.protocol === "gemini-generate-content")
10565
10834
  throw new Error("Harness and provider protocol are incompatible.");
10566
10835
  if (input.harness === "aider")
@@ -10582,7 +10851,8 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
10582
10851
  }
10583
10852
  if (input.harness === "codex") {
10584
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 });
10585
- const file2 = await jsonFile(input.stateDir, "codex-models.json", { models: input.models.map((model3, index) => codexModel(model3, index, providerBaseUrl, model3.id === input.model ? input.reasoning : undefined)) });
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)) });
10586
10856
  configPaths.push(file2);
10587
10857
  configPaths.push(...Object.values(rolePolicy2.agentConfigPaths));
10588
10858
  env[KEY4] = input.credential ?? "switcher-local-no-auth";
@@ -10631,8 +10901,8 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
10631
10901
  throw new Error("Pi cannot safely select model IDs that differ only by letter case; update the provider catalog.");
10632
10902
  const api = { "anthropic-messages": "anthropic-messages", "openai-responses": "openai-responses", "openai-chat": "openai-completions", "gemini-generate-content": "gemini" }[input.protocol];
10633
10903
  const providerId = piProviderId(input, providerBaseUrl);
10634
- const agentDir = join12(input.stateDir, "pi-agent");
10635
- const sessionDir = input.sessionDir ?? join12(input.stateDir, "sessions");
10904
+ const agentDir = join15(input.stateDir, "pi-agent");
10905
+ const sessionDir = input.sessionDir ?? join15(input.stateDir, "sessions");
10636
10906
  const piBaseUrl = input.protocol === "anthropic-messages" ? input.baseUrl.replace(/\/v1$/i, "") : input.baseUrl;
10637
10907
  await mkdir10(agentDir, { recursive: true, mode: 448 });
10638
10908
  await mkdir10(sessionDir, { recursive: true, mode: 448 });
@@ -10657,9 +10927,9 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
10657
10927
  const selected = dshArguments(args);
10658
10928
  const providerId = piProviderId(input, providerBaseUrl);
10659
10929
  const api = { "anthropic-messages": "anthropic-messages", "openai-responses": "openai-responses", "openai-chat": "openai-completions" }[input.protocol];
10660
- const home = join12(input.stateDir, "dsh-home");
10661
- const sessionDir = input.sessionDir ?? join12(input.stateDir, "dsh-state");
10662
- if (!isAbsolute11(sessionDir))
10930
+ const home = join15(input.stateDir, "dsh-home");
10931
+ const sessionDir = input.sessionDir ?? join15(input.stateDir, "dsh-state");
10932
+ if (!isAbsolute13(sessionDir))
10663
10933
  throw new Error("DSH session directory must be absolute.");
10664
10934
  await mkdir10(home, { recursive: true, mode: 448 });
10665
10935
  await mkdir10(sessionDir, { recursive: true, mode: 448 });
@@ -10680,7 +10950,7 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
10680
10950
  }))
10681
10951
  } } } },
10682
10952
  { id: "agent-default-model", config: route2 },
10683
- { id: "session-persistence-jsonl", config: { root: join12(sessionDir, "sessions") } },
10953
+ { id: "session-persistence-jsonl", config: { root: join15(sessionDir, "sessions") } },
10684
10954
  { id: "attachment-local", config: { dshHome: sessionDir } },
10685
10955
  ...selected.profile === "acp" ? [{ id: "acp", config: route2 }] : []
10686
10956
  ];
@@ -10706,15 +10976,15 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
10706
10976
  throw new Error("Prime Agent cannot safely select model IDs that differ only by letter case; update the provider catalog.");
10707
10977
  const api = { "anthropic-messages": "anthropic-messages", "openai-responses": "openai-responses", "openai-chat": "openai-completions" }[input.protocol];
10708
10978
  const providerId = primeProviderId(input, providerBaseUrl);
10709
- const sessionDir = input.sessionDir ?? join12(input.stateDir, "sessions");
10710
- const agentDir = join12(input.stateDir, "prime-agent");
10979
+ const sessionDir = input.sessionDir ?? join15(input.stateDir, "sessions");
10980
+ const agentDir = join15(input.stateDir, "prime-agent");
10711
10981
  const socketInfo = await primeSocketInfo();
10712
10982
  const { daemonSocket, runtimeDir, workerPrefix } = socketInfo;
10713
10983
  const primeBaseUrl = input.protocol === "anthropic-messages" ? input.baseUrl.replace(/\/v1$/i, "") : input.baseUrl;
10714
10984
  await mkdir10(agentDir, { recursive: true, mode: 448 });
10715
10985
  await mkdir10(sessionDir, { recursive: true, mode: 448 });
10716
- const file2 = join12(agentDir, "models.json");
10717
- await writeFile10(file2, JSON.stringify({ providers: { [providerId]: {
10986
+ const file2 = join15(agentDir, "models.json");
10987
+ await writeFile13(file2, JSON.stringify({ providers: { [providerId]: {
10718
10988
  name: "Switcher",
10719
10989
  baseUrl: primeBaseUrl,
10720
10990
  api,
@@ -10805,13 +11075,13 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
10805
11075
  const file2 = await jsonFile(input.stateDir, "opencode-legacy.json", config2);
10806
11076
  configPaths.push(file2);
10807
11077
  env.OPENCODE_CONFIG = file2;
10808
- const sessionDir = input.sessionDir ?? join12(input.stateDir, "sessions");
11078
+ const sessionDir = input.sessionDir ?? join15(input.stateDir, "sessions");
10809
11079
  await mkdir10(sessionDir, { recursive: true, mode: 448 });
10810
- env.XDG_DATA_HOME = join12(sessionDir, "data");
10811
- env.XDG_CONFIG_HOME = join12(input.stateDir, "config");
10812
- env.XDG_CACHE_HOME = join12(input.stateDir, "cache");
10813
- env.XDG_STATE_HOME = join12(input.stateDir, "state");
10814
- env.HOME = join12(input.stateDir, "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");
10815
11085
  env.OPENCODE_DISABLE_PROJECT_CONFIG = "true";
10816
11086
  env.OPENCODE_CONFIG_CONTENT = JSON.stringify(config2);
10817
11087
  env[KEY4] = input.credential ?? "switcher-local-no-auth";
@@ -10835,8 +11105,8 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
10835
11105
  const rolePolicy = compileOpenCodeModelPolicy({ providerId: providerID, mainModel: input.model, roles: input.compiledPolicy?.roles, preservedAgents: Object.entries(isolated.config.agents ?? {}).map(([name, agent]) => ({ ...agent, name })) });
10836
11106
  const modelRef = openCodeInvocationModel(args, rolePolicy, isolated.config.default_agent);
10837
11107
  const config = { ...isolated.config, ...rolePolicy.config, providers: { [providerID]: { name: "Switcher", env: [KEY4], package: `@opencode-ai/ai/providers/${packageName}`, settings: settings2, models } } };
10838
- const file = join12(input.stateDir, "opencode.json");
10839
- await writeFile10(file, openCode2ConfigText(config, providerID, KEY4), { mode: 384, flag: "wx" });
11108
+ const file = join15(input.stateDir, "opencode.json");
11109
+ await writeFile13(file, openCode2ConfigText(config, providerID, KEY4), { mode: 384, flag: "wx" });
10840
11110
  configPaths.push(file, isolated.instructionFile);
10841
11111
  Object.assign(env, isolated.env);
10842
11112
  env.OPENCODE_CONFIG = file;
@@ -10920,9 +11190,11 @@ async function prepareHarnessLaunch(input) {
10920
11190
  validateHarnessVersion(input.harness, input.version);
10921
11191
  if (!compatible(input.harness, input.protocol))
10922
11192
  throw new Error("Harness and provider protocol are incompatible.");
10923
- if (!isAbsolute11(input.stateDir) || !isAbsolute11(input.cwd))
11193
+ if (!isAbsolute13(input.stateDir) || !isAbsolute13(input.cwd))
10924
11194
  throw new Error("Launch state and working directories must be absolute.");
10925
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.");
10926
11198
  input = { ...input, models: input.models.filter((model3) => !modelExpired(model3)) };
10927
11199
  const nativePolicy = compileNativeModelPolicy({ harness: input.harness, mainModel: input.model, roles: compiledPolicy.roles, version: input.version });
10928
11200
  const specialized = new Set(["opencode", "opencode2", "gemini", "hermes"]);
@@ -10935,7 +11207,7 @@ async function prepareHarnessLaunch(input) {
10935
11207
  try {
10936
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";
10937
11209
  const prepared = await prepareTransportLaunch({ ...input, providerBaseUrl: input.baseUrl, baseUrl: bridge.baseUrl, credential: bridge.token, authStyle: nativeAuth, compiledPolicy, nativePolicy });
10938
- return { ...prepared, configPaths: [...prepared.configPaths, catalogPath], warnings: [...prepared.warnings, "Switcher injects model guidance into every managed inference request and permits only the selected model plus explicitly configured role, allowed, and fallback models. The gateway translates the selected credential to the provider authentication header. The full catalog remains discoverable."], cleanup: async () => {
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 () => {
10939
11211
  try {
10940
11212
  await prepared.cleanup?.();
10941
11213
  } finally {
@@ -10951,9 +11223,9 @@ async function prepareHarnessLaunch(input) {
10951
11223
  }
10952
11224
 
10953
11225
  // src/ori-model-policy.ts
10954
- import { isAbsolute as isAbsolute12 } from "path";
11226
+ import { isAbsolute as isAbsolute14 } from "path";
10955
11227
  function prepareOriModelPolicy(target, prepared) {
10956
- if (!isAbsolute12(prepared.executable) || /[\0\r\n]/.test(prepared.executable))
11228
+ if (!isAbsolute14(prepared.executable) || /[\0\r\n]/.test(prepared.executable))
10957
11229
  throw new Error("Ori requires an absolute verified native executable.");
10958
11230
  const entries = Object.entries(prepared.env);
10959
11231
  if (entries.some(([key]) => !/^[A-Z_][A-Z0-9_]*$/.test(key)))
@@ -10977,8 +11249,8 @@ exec "$SWITCHER_ORI_NATIVE_EXECUTABLE" ${prepared.args.map(quote2).join(" ")}
10977
11249
  }
10978
11250
 
10979
11251
  // src/launcher.ts
10980
- import { mkdir as mkdir11, mkdtemp, rm as rm6, writeFile as writeFile14 } from "fs/promises";
10981
- import { join as join16, resolve as resolve9 } from "path";
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";
10982
11254
 
10983
11255
  // src/provider-credential-onboarding.ts
10984
11256
  import { z as z8 } from "zod";
@@ -10988,8 +11260,8 @@ import { createInterface } from "readline/promises";
10988
11260
  // src/credentials.ts
10989
11261
  import { z as z7 } from "zod";
10990
11262
  import { constants as constants5 } from "fs";
10991
- import { open as open3, readdir as readdir5, unlink, link, lstat as lstat4, access as access4, stat as stat6, realpath as realpath6, readlink, rename as rename2 } from "fs/promises";
10992
- import { join as join13, isAbsolute as isAbsolute13, dirname as dirname8, parse as pathParts, resolve as resolvePath, sep as sep2 } from "path";
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";
10993
11265
  import { createHash as createHash10, randomUUID as randomUUID5 } from "crypto";
10994
11266
  import { execFile as execFile3, spawn } from "child_process";
10995
11267
  import { promisify as promisify3 } from "util";
@@ -11015,7 +11287,7 @@ var credentialBindingSchema = z7.object({
11015
11287
  kind: z7.literal("vault"),
11016
11288
  key: vaultKeySchema,
11017
11289
  url: z7.string().max(2000).transform(endpoint).optional(),
11018
- executable: z7.string().max(4096).regex(/^[^\x00-\x1f\x7f]+$/).refine(isAbsolute13, "Secrets executable must be an absolute path"),
11290
+ executable: z7.string().max(4096).regex(/^[^\x00-\x1f\x7f]+$/).refine(isAbsolute15, "Secrets executable must be an absolute path"),
11019
11291
  operator
11020
11292
  }).strict()])
11021
11293
  }).strict().superRefine((binding, ctx) => {
@@ -11031,16 +11303,16 @@ class CredentialBindings {
11031
11303
  directory;
11032
11304
  constructor(env = process.env) {
11033
11305
  this.env = env;
11034
- this.directory = join13(switcherHome(env), "config", "credential-bindings");
11306
+ this.directory = join16(switcherHome(env), "config", "credential-bindings");
11035
11307
  }
11036
11308
  path(name) {
11037
- return join13(this.directory, parse2(reference, name) + ".json");
11309
+ return join16(this.directory, parse2(reference, name) + ".json");
11038
11310
  }
11039
11311
  async readableDirectory() {
11040
- for (const path of [switcherHome(this.env), join13(switcherHome(this.env), "config"), this.directory]) {
11312
+ for (const path of [switcherHome(this.env), join16(switcherHome(this.env), "config"), this.directory]) {
11041
11313
  let info;
11042
11314
  try {
11043
- info = await lstat4(path);
11315
+ info = await lstat6(path);
11044
11316
  } catch (error) {
11045
11317
  if (error.code === "ENOENT")
11046
11318
  return false;
@@ -11106,9 +11378,9 @@ class CredentialBindings {
11106
11378
  if (binding.source.kind === "vault")
11107
11379
  await validateVaultExecutable(binding.source.executable);
11108
11380
  await privateDirectory(switcherHome(this.env));
11109
- await privateDirectory(join13(switcherHome(this.env), "config"));
11381
+ await privateDirectory(join16(switcherHome(this.env), "config"));
11110
11382
  await privateDirectory(this.directory);
11111
- const temporary = join13(this.directory, `.binding-${randomUUID5()}`);
11383
+ const temporary = join16(this.directory, `.binding-${randomUUID5()}`);
11112
11384
  const file = await open3(temporary, "wx", 384);
11113
11385
  try {
11114
11386
  await file.writeFile(JSON.stringify(binding, null, 2) + `
@@ -11164,13 +11436,13 @@ async function inspectVaultExecutable(path, permitWritableFile = false) {
11164
11436
  for (const part of candidate.slice(prefix.length).split(sep2)) {
11165
11437
  if (!part)
11166
11438
  continue;
11167
- prefix = join13(prefix, part);
11439
+ prefix = join16(prefix, part);
11168
11440
  if (seen.has(prefix))
11169
11441
  continue;
11170
11442
  seen.add(prefix);
11171
11443
  if (seen.size > 256)
11172
11444
  throw new Fault(422, "vault_exec_permissions", "The secrets executable path has too many symlink components.");
11173
- const entry = await lstat4(prefix);
11445
+ const entry = await lstat6(prefix);
11174
11446
  const permittedFile = permitWritableFile && prefix === resolved && entry.isFile();
11175
11447
  if (entry.uid !== 0 && entry.uid !== process.getuid?.() || !entry.isSymbolicLink() && !permittedFile && entry.mode & 18)
11176
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.");
@@ -11195,7 +11467,7 @@ async function validateVaultExecutable(path) {
11195
11467
  async function repairVaultExecutablePermissions(path, expectedSha256) {
11196
11468
  if (!/^[a-f0-9]{64}$/.test(expectedSha256))
11197
11469
  throw new Fault(400, "invalid_request", "--sha256 requires the SHA256 of the executable member from a verified package artifact.");
11198
- if (!isAbsolute13(path) || path.length > 4096 || /[\x00-\x1f\x7f]/.test(path))
11470
+ if (!isAbsolute15(path) || path.length > 4096 || /[\x00-\x1f\x7f]/.test(path))
11199
11471
  throw new Fault(400, "invalid_request", "Secrets executable must be an absolute path without control characters.");
11200
11472
  if (process.platform === "win32")
11201
11473
  throw new Fault(422, "vault_exec_repair_unsafe", "Executable permission repair requires POSIX file permissions.");
@@ -11233,13 +11505,13 @@ async function repairVaultExecutablePermissions(path, expectedSha256) {
11233
11505
  await hash2();
11234
11506
  const mode = before.mode & 511 & ~18;
11235
11507
  const changed = mode !== (before.mode & 511);
11236
- if (await inspectVaultExecutable(path, true) !== resolved || !sameFile(await lstat4(resolved)))
11508
+ if (await inspectVaultExecutable(path, true) !== resolved || !sameFile(await lstat6(resolved)))
11237
11509
  throw unsafe();
11238
11510
  if (!changed) {
11239
11511
  await validateVaultExecutable(path);
11240
11512
  return { changed, mode: mode.toString(8).padStart(4, "0"), sha256: expectedSha256 };
11241
11513
  }
11242
- temporary = join13(dirname8(resolved), `.switcher-repair-${randomUUID5()}`);
11514
+ temporary = join16(dirname8(resolved), `.switcher-repair-${randomUUID5()}`);
11243
11515
  const replacement = await open3(temporary, "wx", 384);
11244
11516
  try {
11245
11517
  await hash2(replacement);
@@ -11248,11 +11520,11 @@ async function repairVaultExecutablePermissions(path, expectedSha256) {
11248
11520
  const ready = await replacement.stat();
11249
11521
  if (!ready.isFile() || ready.nlink !== 1 || ready.uid !== before.uid || ready.size !== before.size)
11250
11522
  throw unsafe();
11251
- if (await inspectVaultExecutable(path, true) !== resolved || !sameFile(await lstat4(resolved)))
11523
+ if (await inspectVaultExecutable(path, true) !== resolved || !sameFile(await lstat6(resolved)))
11252
11524
  throw unsafe();
11253
11525
  await rename2(temporary, resolved);
11254
11526
  temporary = undefined;
11255
- const installed = await lstat4(resolved);
11527
+ const installed = await lstat6(resolved);
11256
11528
  if (installed.dev !== ready.dev || installed.ino !== ready.ino || await validateVaultExecutable(path) !== resolved)
11257
11529
  throw unsafe();
11258
11530
  const directory = await open3(dirname8(resolved), constants5.O_RDONLY | constants5.O_DIRECTORY | constants5.O_NOFOLLOW);
@@ -11634,6 +11906,9 @@ function authenticationProbe(provider) {
11634
11906
  return { url, method: provider.credentialCheck.method ?? "GET", authStyle: provider.authStyle ?? "bearer" };
11635
11907
  }
11636
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" };
11637
11912
  if (provider.credentialEnv === "SWITCHER_PROVIDER_OPENROUTER" && base.origin === "https://openrouter.ai" && base.pathname.replace(/\/+$/, "") === "/api/v1")
11638
11913
  return { url: new URL("https://openrouter.ai/api/v1/key"), method: "GET", authStyle: provider.authStyle ?? "bearer" };
11639
11914
  return;
@@ -12307,18 +12582,18 @@ function oriLaunchWarnings(target) {
12307
12582
 
12308
12583
  // src/chatgpt-launch.ts
12309
12584
  import { createHash as createHash12 } from "crypto";
12310
- import { writeFile as writeFile12, rm as rm4 } from "fs/promises";
12311
- import { join as join14 } from "path";
12585
+ import { writeFile as writeFile15, rm as rm4 } from "fs/promises";
12586
+ import { join as join17 } from "path";
12312
12587
 
12313
12588
  // src/desktop-state.ts
12314
12589
  import { Database as Database3 } from "bun:sqlite";
12315
- import { readFile as readFile5, writeFile as writeFile11, rm as rm3, lstat as lstat5, rename as rename3, chmod as chmod2 } from "fs/promises";
12590
+ import { readFile as readFile7, writeFile as writeFile14, rm as rm3, lstat as lstat7, rename as rename3, chmod as chmod2 } from "fs/promises";
12316
12591
  async function safeDesktopRead(path) {
12317
12592
  try {
12318
- const info = await lstat5(path);
12593
+ const info = await lstat7(path);
12319
12594
  if (!info.isFile() || info.isSymbolicLink() || info.uid !== process.getuid?.())
12320
12595
  throw new Fault(422, "desktop_state_permissions", "Desktop settings must be regular files owned by this user.");
12321
- return await readFile5(path, "utf8");
12596
+ return await readFile7(path, "utf8");
12322
12597
  } catch (error) {
12323
12598
  if (error.code === "ENOENT")
12324
12599
  return;
@@ -12328,7 +12603,7 @@ async function safeDesktopRead(path) {
12328
12603
  async function writeDesktopPrivate(path, text) {
12329
12604
  const temporary = path + "." + crypto.randomUUID() + ".tmp";
12330
12605
  try {
12331
- await writeFile11(temporary, text, { mode: 384, flag: "wx" });
12606
+ await writeFile14(temporary, text, { mode: 384, flag: "wx" });
12332
12607
  await rename3(temporary, path);
12333
12608
  } finally {
12334
12609
  await rm3(temporary, { force: true });
@@ -12336,7 +12611,7 @@ async function writeDesktopPrivate(path, text) {
12336
12611
  }
12337
12612
  async function desktopLease(path) {
12338
12613
  try {
12339
- const info = await lstat5(path);
12614
+ const info = await lstat7(path);
12340
12615
  if (!info.isFile() || info.isSymbolicLink() || info.uid !== process.getuid?.())
12341
12616
  throw new Fault(422, "desktop_state_permissions", "Desktop lease must be a regular file owned by this user.");
12342
12617
  } catch (error) {
@@ -12372,12 +12647,12 @@ var digest = (value) => createHash12("sha256").update(value).digest("hex");
12372
12647
  var quote2 = (value) => `'${value.replaceAll("'", `'"'"'`)}'`;
12373
12648
  async function prepareChatGPTLaunch(native, app, stateDir, sessionDir) {
12374
12649
  await privateDirectory(sessionDir);
12375
- const home = join14(sessionDir, "codex"), userData = join14(sessionDir, "electron");
12650
+ const home = join17(sessionDir, "codex"), userData = join17(sessionDir, "electron");
12376
12651
  await privateDirectory(home);
12377
12652
  await privateDirectory(userData);
12378
- const release = await desktopLease(join14(sessionDir, "launch.sqlite"));
12653
+ const release = await desktopLease(join17(sessionDir, "launch.sqlite"));
12379
12654
  let released = false, authText;
12380
- const authPath = join14(home, "auth.json"), receiptPath = join14(home, ".switcher-auth.sha256");
12655
+ const authPath = join17(home, "auth.json"), receiptPath = join17(home, ".switcher-auth.sha256");
12381
12656
  const cleanup = async () => {
12382
12657
  if (released)
12383
12658
  return;
@@ -12403,7 +12678,7 @@ async function prepareChatGPTLaunch(native, app, stateDir, sessionDir) {
12403
12678
  settings2.push('approval_policy="on-request"');
12404
12679
  if (!settings2.some((setting) => setting.startsWith("sandbox_mode=")))
12405
12680
  settings2.push('sandbox_mode="workspace-write"');
12406
- const configPath = join14(home, "config.toml");
12681
+ const configPath = join17(home, "config.toml");
12407
12682
  const previousAuth = await safeDesktopRead(authPath), previousReceipt = await safeDesktopRead(receiptPath);
12408
12683
  if (previousAuth !== undefined && previousReceipt !== digest(previousAuth))
12409
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.");
@@ -12424,9 +12699,9 @@ async function prepareChatGPTLaunch(native, app, stateDir, sessionDir) {
12424
12699
  `;
12425
12700
  await writeDesktopPrivate(receiptPath, digest(authText));
12426
12701
  await writeDesktopPrivate(authPath, authText);
12427
- const wrapper = join14(stateDir, "chatgpt-codex");
12702
+ const wrapper = join17(stateDir, "chatgpt-codex");
12428
12703
  const overrides = settings2.flatMap((setting) => ["-c", setting]);
12429
- await writeFile12(wrapper, `#!/bin/sh
12704
+ await writeFile15(wrapper, `#!/bin/sh
12430
12705
  set -eu
12431
12706
  unset OPENAI_API_KEY CODEX_API_KEY CODEX_ACCESS_TOKEN OPENAI_BASE_URL OPENAI_ORG_ID OPENAI_ORGANIZATION OPENAI_PROJECT_ID
12432
12707
  export CODEX_HOME=${quote2(home)}
@@ -12459,15 +12734,15 @@ exec ${quote2(app.codexExecutable)} "$@" ${overrides.map(quote2).join(" ")}
12459
12734
  // src/claude-desktop-launch.ts
12460
12735
  import { createHash as createHash13 } from "crypto";
12461
12736
  import { execFile as execFile5 } from "child_process";
12462
- import { access as access5, rm as rm5, writeFile as writeFile13 } from "fs/promises";
12463
- import { homedir as homedir8, userInfo as userInfo2 } from "os";
12464
- import { join as join15 } from "path";
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";
12465
12740
  import { promisify as promisify5 } from "util";
12466
12741
  var execute4 = promisify5(execFile5);
12467
12742
  var hash2 = (text) => createHash13("sha256").update(text).digest("hex");
12468
- var claudeDesktopDataDirectory = () => join15(homedir8(), "Library/Application Support/Claude-3p");
12743
+ var claudeDesktopDataDirectory = () => join18(homedir9(), "Library/Application Support/Claude-3p");
12469
12744
  async function assertAvailable(userData) {
12470
- for (const path of [join15("/Library/Managed Preferences", userInfo2().username, "com.anthropic.claudefordesktop.plist"), "/Library/Managed Preferences/com.anthropic.claudefordesktop.plist"])
12745
+ for (const path of [join18("/Library/Managed Preferences", userInfo2().username, "com.anthropic.claudefordesktop.plist"), "/Library/Managed Preferences/com.anthropic.claudefordesktop.plist"])
12471
12746
  if (await access5(path).then(() => true, () => false))
12472
12747
  throw new Fault(409, "desktop_managed", "Claude has managed preferences. Configure its gateway through the administrator's policy; Switcher will not override it.");
12473
12748
  let openFiles;
@@ -12501,15 +12776,15 @@ async function prepareClaudeDesktopLaunch(input, app, sessionDir, system) {
12501
12776
  const check2 = system?.assertAvailable ?? (() => assertAvailable(userData));
12502
12777
  await check2();
12503
12778
  await privateDirectory(userData);
12504
- const library = join15(userData, "configLibrary");
12779
+ const library = join18(userData, "configLibrary");
12505
12780
  await privateDirectory(library);
12506
- const release = await desktopLease(join15(library, ".switcher-lease.sqlite"));
12507
- const metaPath = join15(library, "_meta.json"), receiptPath = join15(library, ".switcher-selection.json");
12781
+ const release = await desktopLease(join18(library, ".switcher-lease.sqlite"));
12782
+ const metaPath = join18(library, "_meta.json"), receiptPath = join18(library, ".switcher-selection.json");
12508
12783
  let receipt, gateway, closed = false;
12509
12784
  const restore = async (record3) => {
12510
12785
  if (!/^[a-f0-9-]{36}$/.test(record3.id) || typeof record3.configHash !== "string" || typeof record3.appliedMeta !== "string" || record3.previousMeta !== null && typeof record3.previousMeta !== "string")
12511
12786
  throw new Fault(422, "desktop_config_invalid", "Claude's Switcher recovery record is invalid.");
12512
- const configPath = join15(library, record3.id + ".json"), current = await safeDesktopRead(configPath);
12787
+ const configPath = join18(library, record3.id + ".json"), current = await safeDesktopRead(configPath);
12513
12788
  if (current !== undefined && hash2(current) !== record3.configHash)
12514
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.");
12515
12790
  const currentMeta = await safeDesktopRead(metaPath);
@@ -12538,7 +12813,7 @@ async function prepareClaudeDesktopLaunch(input, app, sessionDir, system) {
12538
12813
  const recovery = await safeDesktopRead(receiptPath);
12539
12814
  if (recovery)
12540
12815
  await restore(JSON.parse(recovery));
12541
- const localConfig = await safeDesktopRead(join15(userData, "claude_desktop_config.json"));
12816
+ const localConfig = await safeDesktopRead(join18(userData, "claude_desktop_config.json"));
12542
12817
  if (localConfig && JSON.parse(localConfig).deploymentMode === "1p")
12543
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.");
12544
12819
  await privateDirectory(sessionDir);
@@ -12549,10 +12824,10 @@ async function prepareClaudeDesktopLaunch(input, app, sessionDir, system) {
12549
12824
  if (input.modelPolicy?.aliases?.[alias] && input.modelPolicy.aliases[alias] !== target)
12550
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.");
12551
12826
  const compiledPolicy = compileModelPolicy(input.model, input.models, { ...input.modelPolicy, version: 1, aliases: { ...input.modelPolicy?.aliases, ...aliases } });
12552
- const catalogPath = join15(input.stateDir, "claude-desktop-policy.json");
12553
- await writeFile13(catalogPath, JSON.stringify({ policy: compiledPolicy, models: input.models }), { mode: 384, flag: "wx" });
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" });
12554
12829
  gateway = createInferenceGateway({ ...input, compiledPolicy, catalogPath });
12555
- const id2 = crypto.randomUUID(), configPath = join15(library, id2 + ".json");
12830
+ const id2 = crypto.randomUUID(), configPath = join18(library, id2 + ".json");
12556
12831
  const config = JSON.stringify({
12557
12832
  inferenceProvider: "gateway",
12558
12833
  inferenceGatewayBaseUrl: gateway.baseUrl.replace(/\/v1$/, ""),
@@ -12588,13 +12863,15 @@ async function prepareClaudeDesktopLaunch(input, app, sessionDir, system) {
12588
12863
  // src/launcher.ts
12589
12864
  var LATE_RUN_FINALIZATION_TIMEOUT_MS = 5000;
12590
12865
  async function writeOriCodexCatalog(stateDir, models) {
12591
- const path = join16(stateDir, "ori-codex-models.json");
12866
+ const path = join19(stateDir, "ori-codex-models.json");
12592
12867
  const nativeModels2 = models.filter(codingEligible).map((model3, index) => codexModel(model3, index));
12593
- await writeFile14(path, JSON.stringify({ models: nativeModels2 }, null, 2) + `
12868
+ await writeFile17(path, JSON.stringify({ models: nativeModels2 }, null, 2) + `
12594
12869
  `, { mode: 384, flag: "wx" });
12595
12870
  return path;
12596
12871
  }
12597
12872
  function oriTarget(harness) {
12873
+ if (harness === "antigravity" || harness === "junie")
12874
+ throw new Error("This CLI is supported through the direct Switcher backend only.");
12598
12875
  if (harness === "kilo")
12599
12876
  throw new Error("Ori does not launch Kilo; use the direct backend.");
12600
12877
  if (harness === "opencode")
@@ -12679,9 +12956,9 @@ async function prepareOriForPlan(plan, options) {
12679
12956
  });
12680
12957
  try {
12681
12958
  const shim = prepareOriModelPolicy(request.target, native);
12682
- const dir = join16(options.stateDir, "ori-bin"), path = join16(dir, shim.name);
12959
+ const dir = join19(options.stateDir, "ori-bin"), path = join19(dir, shim.name);
12683
12960
  await mkdir11(dir, { mode: 448 });
12684
- await writeFile14(path, shim.script, { mode: 448, flag: "wx" });
12961
+ await writeFile17(path, shim.script, { mode: 448, flag: "wx" });
12685
12962
  return { contract, prepared: {
12686
12963
  ...ori,
12687
12964
  env: { ...ori.env, ...shim.env, PATH: `${dir}:${ori.env.PATH ?? process.env.PATH ?? ""}` },
@@ -12701,7 +12978,7 @@ async function launch(client, profileId, options = {}) {
12701
12978
  if ((options.reasoning || options.dangerouslyBypassApprovalsAndSandbox) && (profile.harness !== "codex" || (options.backend ?? "direct") !== "direct"))
12702
12979
  throw new Error("Reasoning and full-access launch options require direct Codex or ChatGPT.");
12703
12980
  assertHarnessArguments(profile.harness, options.args ?? []);
12704
- if (profile.harness === "gemini")
12981
+ if (profile.harness === "gemini" || profile.harness === "antigravity")
12705
12982
  validateHarnessProvider(profile.harness, await client.getProvider(profile.providerId));
12706
12983
  await validateHarnessConfiguration(profile.harness, resolve9(options.cwd ?? process.cwd()), options.args);
12707
12984
  if (profile.harness === "grok" && !["", "0", "false", "no", "off"].includes((process.env.GROK_DISABLE_API_KEY_AUTH ?? "").trim().toLowerCase()))
@@ -12734,9 +13011,9 @@ async function launch(client, profileId, options = {}) {
12734
13011
  validateHarnessVersion("gemini", detection?.version);
12735
13012
  if (backend === "direct" && plan.profile.harness === "aider")
12736
13013
  validateHarnessVersion(plan.profile.harness, detection?.version);
12737
- const root = resolve9(options.stateDir ?? join16(switcherHome(), "state"));
13014
+ const root = resolve9(options.stateDir ?? join19(switcherHome(), "state"));
12738
13015
  await privateDirectory(root);
12739
- const stateDir = await mkdtemp(join16(root, "launch-"));
13016
+ const stateDir = await mkdtemp(join19(root, "launch-"));
12740
13017
  let credential;
12741
13018
  if (backend === "direct") {
12742
13019
  try {
@@ -12794,7 +13071,7 @@ async function launch(client, profileId, options = {}) {
12794
13071
  stateDir,
12795
13072
  cwd: resolve9(options.cwd ?? process.cwd())
12796
13073
  };
12797
- let prepared = options.claudeDesktop ? await prepareClaudeDesktopLaunch(input, options.claudeDesktop, join16(root, "desktop-claude", profileId)) : backend === "ori" ? (await prepareOriForPlan(plan, { ...options, stateDir, onRoutingEvent })).prepared : await prepareHarnessLaunch({
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({
12798
13075
  harness: plan.profile.harness,
12799
13076
  baseUrl: plan.provider.baseUrl,
12800
13077
  protocol: plan.provider.protocol,
@@ -12812,11 +13089,11 @@ async function launch(client, profileId, options = {}) {
12812
13089
  stateDir,
12813
13090
  cwd: resolve9(options.cwd ?? process.cwd()),
12814
13091
  version: detection?.version,
12815
- ...["pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "opencode", "kilo"].includes(plan.profile.harness) ? { sessionDir: join16(root, "sessions", plan.profile.harness, profileId) } : {}
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) } : {}
12816
13093
  });
12817
13094
  cleanup = prepared.cleanup;
12818
13095
  if (options.desktop) {
12819
- prepared = await prepareChatGPTLaunch(prepared, options.desktop, stateDir, join16(root, "desktop", profileId));
13096
+ prepared = await prepareChatGPTLaunch(prepared, options.desktop, stateDir, join19(root, "desktop", profileId));
12820
13097
  cleanup = prepared.cleanup;
12821
13098
  }
12822
13099
  for (const warning of [...plan.warnings, ...prepared.warnings])
@@ -13008,7 +13285,8 @@ async function selectModel(models, query = "", harness) {
13008
13285
  }
13009
13286
  }
13010
13287
  async function ensureLaunchProfile(client, provider, harness, model3, modelPolicy) {
13011
- const normalizedPolicy = modelPolicy === undefined ? undefined : parse2(modelPolicySchema, modelPolicy);
13288
+ const policy = modelPolicy ?? (harness === "codex" ? { version: 1, selection: "catalog" } : undefined);
13289
+ const normalizedPolicy = policy === undefined ? undefined : parse2(modelPolicySchema, policy);
13012
13290
  const identity = normalizedPolicy === undefined ? [provider.id, harness, model3] : [provider.id, harness, model3, normalizedPolicy];
13013
13291
  const hash3 = createHash14("sha256").update(canonicalPolicyJSON(identity)).digest("hex").slice(0, 24);
13014
13292
  const desired = parse2(profileInputSchema, { id: `launch-${harness}-${hash3}`, name: `${harness}: ${model3}`.slice(0, 200), providerId: provider.id, harness, model: model3, ...normalizedPolicy ? { modelPolicy: normalizedPolicy } : {} });
@@ -13071,7 +13349,7 @@ var HELP = `switcher \u2014 launch coding harnesses and desktop apps with your p
13071
13349
  switcher credentials repair-executable --vault-cli PATH --sha256 EXPECTED
13072
13350
  switcher doctor
13073
13351
 
13074
- 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
13075
13353
  chatgpt launches the installed macOS desktop app in an isolated provider profile.
13076
13354
  Its local Codex conversations use the selected Responses-compatible provider.
13077
13355
  claude-desktop launches Claude in its separate Claude-3p gateway profile with a
@@ -13360,7 +13638,7 @@ async function main(args = process.argv.slice(2)) {
13360
13638
  modelsPath: values2["models-path"]
13361
13639
  });
13362
13640
  if (command === "doctor") {
13363
- 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)));
13364
13642
  let api;
13365
13643
  try {
13366
13644
  api = { mode: runtime.mode, reachable: true, health: await client.health(), ready: await client.ready() };
@@ -13417,7 +13695,7 @@ async function main(args = process.argv.slice(2)) {
13417
13695
  assertHarnessArguments(profile.harness, nativeArgs);
13418
13696
  await validateHarnessConfiguration(profile.harness, values2.cwd ?? process.cwd(), nativeArgs);
13419
13697
  const provider = await client.getProvider(profile.providerId);
13420
- if (profile.harness === "gemini")
13698
+ if (profile.harness === "gemini" || profile.harness === "antigravity")
13421
13699
  validateHarnessProvider(profile.harness, provider);
13422
13700
  let prepared;
13423
13701
  if (!values2["dry-run"]) {