@moondeck/station 1.0.12 → 1.0.14

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.
@@ -87,6 +87,9 @@ export interface AgentTransportOptions {
87
87
  passEnv?: string[];
88
88
  /** Explicit per-session environment values. */
89
89
  explicitEnv?: Record<string, string>;
90
+ /** Names removed from the CLI's env on a baked Docker/Apple task, where
91
+ * container env can't be cleared by an exec env (agentCliArgv). */
92
+ unsetEnv?: readonly string[];
90
93
  /**
91
94
  * Whether a live runner from a previous host process may be attached to.
92
95
  * True for stateless adapters (claude); false for ones whose host-side
@@ -464,7 +467,7 @@ export function createAgentTransport(opts: AgentTransportOptions): LineTransport
464
467
  debugLabel: opts.debugLabel,
465
468
  launch: async () => {
466
469
  await prepared;
467
- const cliArgv = agentCliArgv(opts.environment, [opts.cli, ...opts.cliArgs]);
470
+ const cliArgv = agentCliArgv(opts.environment, [opts.cli, ...opts.cliArgs], opts.unsetEnv);
468
471
  const result = await opts.environment.launchDetachedSession({
469
472
  argv: [
470
473
  "node",
@@ -682,7 +685,7 @@ function directEnvironmentTransport(opts: AgentTransportOptions): LineTransport
682
685
  return new EnvironmentLineProcess({
683
686
  environment: opts.environment,
684
687
  request: {
685
- argv: agentCliArgv(opts.environment, [opts.cli, ...opts.cliArgs]),
688
+ argv: agentCliArgv(opts.environment, [opts.cli, ...opts.cliArgs], opts.unsetEnv),
686
689
  projectEnvProfile: "task",
687
690
  inheritEnv: opts.passEnv ?? [],
688
691
  env: opts.explicitEnv ?? {},
@@ -149,6 +149,20 @@ export function forgetCredentialCleanupPending(
149
149
  * (`.uai-tmp`) before renaming it into place. */
150
150
  const CONNECTION_AUTH_PATH = /^\/home\/node\/\.uai-connection\/[a-f0-9]{64}(?:\/(?:auth\.json|config\.toml|aws-config|aws-credentials))?$/;
151
151
  const ENGINE_AUTH_PATH = /^\/home\/node\/(?:\.codex(?:-acct-[A-Za-z0-9_-]+)?(?:-agent-[A-Za-z0-9_-]+)?|\.grok(?:-acct-[A-Za-z0-9_-]+)?|\.local\/share\/opencode(?:-acct-[A-Za-z0-9_-]+)?)\/auth\.json(?:\.uai-tmp)?$/;
152
+ /** ADR-178: an agent's agy dir, removed whole (agy keeps conversations and
153
+ * logs beside the token): a subscription account's per-agent dir, or an
154
+ * API-key agent's own dir. */
155
+ const GEMINI_DIR_PATH = /^\/home\/node\/(?:\.gemini-acct-[A-Za-z0-9_-]+(?:-agent-[A-Za-z0-9_-]+)?|\.gemini-uai-key-agent-[A-Za-z0-9_-]+)$/;
156
+ /** ADR-178: a subscription account's token file in its per-agent dir. */
157
+ const GEMINI_TOKEN_PATH = /^\/home\/node\/\.gemini-acct-[A-Za-z0-9_-]+(?:-agent-[A-Za-z0-9_-]+)?\/antigravity-cli\/antigravity-oauth-token(?:\.uai-tmp)?$/;
158
+ const CONNECTION_HOME_PATH = /^\/home\/node\/\.uai-connection\/[a-f0-9]{64}$/;
159
+
160
+ /** Whether a cleanup path is a whole directory the executor removes with a
161
+ * confined rmtree (a connection home, a Gemini agent's agy dir), rather than
162
+ * one file it unlinks. */
163
+ export function isCredentialCleanupDirectory(path: string): boolean {
164
+ return CONNECTION_HOME_PATH.test(path) || GEMINI_DIR_PATH.test(path);
165
+ }
152
166
  /** A file a writer stages (`.uai-tmp`) before renaming it into place. */
153
167
  function andStaged(...paths: string[]): string[] {
154
168
  return paths.flatMap((path) => [path, `${path}.uai-tmp`]);
@@ -190,7 +204,11 @@ export function assertCredentialCleanupPath(
190
204
  throw new Error("credential cleanup path is invalid");
191
205
  }
192
206
  const allowed =
193
- (lane === "engine-auth" && (ENGINE_AUTH_PATH.test(value) || CONNECTION_AUTH_PATH.test(value))) ||
207
+ (lane === "engine-auth" &&
208
+ (ENGINE_AUTH_PATH.test(value) ||
209
+ GEMINI_DIR_PATH.test(value) ||
210
+ GEMINI_TOKEN_PATH.test(value) ||
211
+ CONNECTION_AUTH_PATH.test(value))) ||
194
212
  (lane === "github" && GITHUB_PATHS.has(value)) ||
195
213
  (lane === "ssh" && SSH_PATHS.has(value)) ||
196
214
  (lane === "files-session" && FILES_SESSION_PATHS.has(value));
@@ -66,11 +66,37 @@ import {
66
66
  * Where a config-directory engine's account lives in the task, the variable
67
67
  * that points the engine at it, and whether the engine reads it again at
68
68
  * every turn (a one-shot CLI) or only when it starts (Codex's app-server,
69
- * which must respawn to see a rewritten file).
69
+ * which must respawn to see a rewritten file). `fileDir`, when set, is the
70
+ * subdirectory of the home the account's files go in.
71
+ *
72
+ * Gemini (ADR-178): the home is agy's "gemini dir", passed as
73
+ * `agy --gemini_dir <home>` (agy then reads `<home>/antigravity-cli/
74
+ * antigravity-oauth-token`), and each agent runs in a home derived from its
75
+ * account's (`<home>-agent-<agent>`, as Codex does). So two gemini accounts,
76
+ * or two agents, in one task never share a token file, and each agy renews
77
+ * only its own copy. HOME itself is untouched, so the commands agy runs keep
78
+ * the task's git, gh and ssh setup.
70
79
  */
71
- export const ENGINE_ACCOUNT_HOMES: Readonly<
72
- Record<string, { selectVar: string; prefix: string; readsEachTurn: boolean }>
73
- > = Object.freeze({
80
+ export interface EngineAccountHome {
81
+ selectVar: string;
82
+ prefix: string;
83
+ readsEachTurn: boolean;
84
+ fileDir?: string;
85
+ }
86
+
87
+ /** The non-secret marker telling the gemini adapter which kind of account it
88
+ * runs on: `subscription` (agy's token file) or `api-key` (GEMINI_API_KEY). */
89
+ export const GEMINI_AUTH_ENV = "UAI_GEMINI_AUTH";
90
+
91
+ /** An API-key Gemini agent's own agy dir (ADR-178): never holds a
92
+ * subscription token; the orchestrator inventories it so a cleanup removes
93
+ * it with the agent's agy state. */
94
+ export function geminiKeyHome(agentId: string): string {
95
+ return `${TASK_HOME}/.gemini-uai-key-agent-${agentId.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 128)}`;
96
+ }
97
+ const GEMINI_KEY_HOME = /^\/home\/node\/\.gemini-uai-key-agent-[A-Za-z0-9_-]{1,128}$/;
98
+
99
+ export const ENGINE_ACCOUNT_HOMES: Readonly<Record<string, EngineAccountHome>> = Object.freeze({
74
100
  codex: { selectVar: "CODEX_HOME", prefix: `${TASK_HOME}/.codex-acct-`, readsEachTurn: false },
75
101
  grok: { selectVar: "GROK_HOME", prefix: `${TASK_HOME}/.grok-acct-`, readsEachTurn: true },
76
102
  opencode: {
@@ -78,6 +104,14 @@ export const ENGINE_ACCOUNT_HOMES: Readonly<
78
104
  prefix: `${TASK_HOME}/.local/share/opencode-acct-`,
79
105
  readsEachTurn: true,
80
106
  },
107
+ // ADR-178: the full token file, refresh token included (agy renews it
108
+ // itself; no lane, so the broker never sees or refreshes it).
109
+ gemini: {
110
+ selectVar: "UAI_GEMINI_DIR",
111
+ prefix: `${TASK_HOME}/.gemini-acct-`,
112
+ readsEachTurn: true,
113
+ fileDir: "antigravity-cli",
114
+ },
81
115
  });
82
116
 
83
117
  /** A derived home's suffix: `<home>-agent-<agent>`. */
@@ -197,7 +231,15 @@ let fenceEscalator: EngineLaunchFenceEscalator | null = null;
197
231
  /** The account's home in the task: null for a kind that reads no file. */
198
232
  export function engineAccountHome(engineKind: string, credentialId: string): string | null {
199
233
  const home = ENGINE_ACCOUNT_HOMES[engineKind];
200
- return home ? `${home.prefix}${idPathSegment(credentialId)}` : null;
234
+ if (!home) return null;
235
+ return `${home.prefix}${idPathSegment(credentialId)}`;
236
+ }
237
+
238
+ /** Where one of an account's files goes under `home` (its home or one derived
239
+ * from it). */
240
+ export function engineAccountFile(engineKind: string, home: string, name: string): string {
241
+ const dir = ENGINE_ACCOUNT_HOMES[engineKind]?.fileDir;
242
+ return dir ? `${home}/${dir}/${name}` : `${home}/${name}`;
201
243
  }
202
244
 
203
245
  function accountOf(credential: TaskEngineCredential): ServedEngineAccount {
@@ -561,10 +603,23 @@ function homeOf(account: LeasedEngineAccount, home: string | undefined): string
561
603
  */
562
604
  export function engineSpawnEnv(account: LeasedEngineAccount, home?: string): Record<string, string> {
563
605
  if (account.authKind === "custom-connection") throw new Error("a connection requires its launch builder");
564
- if (account.authKind === "env") return { ...(account.env ?? {}) };
606
+ if (account.authKind === "env") {
607
+ if (account.engineKind === "gemini" && home !== undefined && !GEMINI_KEY_HOME.test(home)) {
608
+ throw new Error("an engine home outside the account's");
609
+ }
610
+ return {
611
+ ...(account.env ?? {}),
612
+ ...(account.engineKind === "gemini"
613
+ ? { [GEMINI_AUTH_ENV]: "api-key", ...(home !== undefined ? { UAI_GEMINI_DIR: home } : {}) }
614
+ : {}),
615
+ };
616
+ }
565
617
  const selector = ENGINE_ACCOUNT_HOMES[account.engineKind];
566
618
  if (!selector) throw new Error("the account's engine reads no file");
567
- return { [selector.selectVar]: homeOf(account, home) };
619
+ return {
620
+ [selector.selectVar]: homeOf(account, home),
621
+ ...(account.engineKind === "gemini" ? { [GEMINI_AUTH_ENV]: "subscription" } : {}),
622
+ };
568
623
  }
569
624
 
570
625
  /** The writer's step was refused: the run, the gate, the revision or the
@@ -639,7 +694,13 @@ export function writeEngineHome(
639
694
  if (live.revision !== revision || live.version !== version) throw new EngineCredentialWriteRefused();
640
695
  };
641
696
  const names = Object.keys(account.files).sort();
642
- for (const path of withStaged(...names.map((name) => `${target}/${name}`))) {
697
+ // Gemini: agy fills its whole home (conversations, logs, caches), so the
698
+ // home itself is inventoried and a cleanup removes it entirely.
699
+ const inventory = [
700
+ ...(account.engineKind === "gemini" ? [target] : []),
701
+ ...withStaged(...names.map((name) => engineAccountFile(account.engineKind, target, name))),
702
+ ];
703
+ for (const path of inventory) {
643
704
  rememberCredentialCleanupPath({
644
705
  taskId: assignment.taskId,
645
706
  runEpoch: assignment.runEpoch,
@@ -655,7 +716,7 @@ export function writeEngineHome(
655
716
  for (const name of names) {
656
717
  await runInTask(
657
718
  environment,
658
- writeTaskFileArgv(`${target}/${name}`, "600"),
719
+ writeTaskFileArgv(engineAccountFile(account.engineKind, target, name), "600"),
659
720
  account.files[name]!,
660
721
  `writing the ${account.engineKind} account`,
661
722
  admit,
@@ -132,10 +132,13 @@ const KINDS: Record<string, KindDescriptor> = {
132
132
  const API_KEY_ENV_VARS: Record<string, string> = {
133
133
  grok: "XAI_API_KEY",
134
134
  cursor: "CURSOR_API_KEY",
135
+ // ADR-178: a Gemini API key runs agy with modelProvider "gemini".
136
+ gemini: "GEMINI_API_KEY",
135
137
  };
136
138
  const API_KEY_ENGINE_LABELS: Record<string, string> = {
137
139
  grok: "Grok",
138
140
  cursor: "Cursor",
141
+ gemini: "Gemini",
139
142
  };
140
143
 
141
144
  /**
@@ -59,6 +59,9 @@ import {
59
59
  writeEnvValuesAtomic,
60
60
  } from "./env-file";
61
61
  import { ASDF_DATA_VOLUME, STANDARD_IMAGE_TAG } from "./standard-image";
62
+ import { agyResolveShell } from "./agents/agy-pin";
63
+ import { scrubAgyDiagnostics } from "./agents/agy-scrub";
64
+ import { AGY_TOKEN_RELATIVE_PATH } from "./agents/gemini-credentials";
62
65
 
63
66
  export const ENGINE_LOGIN_TIMEOUT_MS = 10 * 60_000;
64
67
  /** Delay before the separate submit keystroke — long enough for the TUI to
@@ -87,6 +90,16 @@ const GROK_LOGIN_SHELL =
87
90
  '[ -n "$g" ] || { curl -fsSL https://x.ai/cli/install.sh | bash >/dev/null 2>&1; g="$HOME/.grok/bin/grok"; }; ' +
88
91
  '[ -x "$g" ] || { echo "grok CLI is not available in the login image" >&2; exit 127; }; ' +
89
92
  'exec "$g" login --device-auth';
93
+ /** ADR-178: Antigravity's sign-in. `agy acp --login` prints a Google URL,
94
+ * reads one pasted authorization code from stdin, writes its token file under
95
+ * HOME (forced to the file store) and exits 0. Uai never exchanges the code
96
+ * itself: agy does, with its own client. The image carries agy only when the
97
+ * host had gemini configured at its last build, so the pinned build is
98
+ * fetched into the op's private HOME when it's missing (like grok). */
99
+ export const GEMINI_LOGIN_SHELL =
100
+ `${agyResolveShell()}\n` +
101
+ "export AGY_CLI_FORCE_FILE_TOKEN_STORAGE=1 AGY_CLI_DISABLE_AUTO_UPDATE=true\n" +
102
+ 'exec "$a" acp --login';
90
103
  const MAX_OUTPUT_TAIL_BYTES = 64 * 1_024;
91
104
  /** script(1) transcripts of a login run a few KB; 1MB is a hostile-file cap. */
92
105
  const MAX_TRANSCRIPT_BYTES = 1_024 * 1_024;
@@ -467,6 +480,13 @@ export class EngineLoginManager {
467
480
  status: grokConfigured ? "configured" : "missing",
468
481
  loginSupported: true,
469
482
  },
483
+ // ADR-178: gemini signs in only into the cloud vault, so only the
484
+ // sign-in box offers it (a runner keeps no gemini login of its own).
485
+ // Kept off ordinary runners so their frames stay within an older
486
+ // cloud's three-entry bound.
487
+ ...(this.workspaceOnly
488
+ ? [{ engine: "gemini" as const, status: "missing" as const, loginSupported: true as const }]
489
+ : []),
470
490
  ];
471
491
  }
472
492
 
@@ -492,6 +512,24 @@ export class EngineLoginManager {
492
512
  );
493
513
  return false;
494
514
  }
515
+ // ADR-178: a Gemini sign-in exists only as a cloud capture. Anywhere else
516
+ // (an ordinary runner, or the box without a flow) agy must never start:
517
+ // it would exchange a pasted code for a token nothing may keep.
518
+ if (
519
+ engine === "gemini" &&
520
+ (!this.workspaceOnly || flow === undefined || this.seams.captureEngineAccount === undefined)
521
+ ) {
522
+ safeEmit(
523
+ emit,
524
+ failedEvent(
525
+ opId,
526
+ engine,
527
+ "start_failed",
528
+ "Gemini accounts are connected in Moondeck Cloud (Connections → AI Accounts).",
529
+ ),
530
+ );
531
+ return false;
532
+ }
495
533
  if (scope !== undefined && !isEngineAccountScope(scope)) {
496
534
  safeEmit(
497
535
  emit,
@@ -623,8 +661,8 @@ export class EngineLoginManager {
623
661
  }
624
662
  const rejection = !this.isCurrent(operation)
625
663
  ? "operation belongs to a previous bridge generation"
626
- : operation.engine !== "claude"
627
- ? `engine is ${operation.engine}, not claude`
664
+ : operation.engine !== "claude" && operation.engine !== "gemini"
665
+ ? `engine is ${operation.engine}, not claude or gemini`
628
666
  : operation.stage !== "awaiting_input"
629
667
  ? `stage is ${operation.stage}, not awaiting_input`
630
668
  : operation.inputUsed
@@ -679,6 +717,18 @@ export class EngineLoginManager {
679
717
  private deliverOneTimeCode(operation: LoginOperation, text: string): boolean {
680
718
  const process = operation.process;
681
719
  if (!process) return false;
720
+ if (operation.engine === "gemini") {
721
+ // agy reads one plain line from a pipe (no PTY, no raw-mode TUI), so
722
+ // the code and its newline go in one write.
723
+ try {
724
+ process.writeInput(`${text}\n`);
725
+ console.log(`[engine-login] input written to the login process for ${operation.opId}`);
726
+ return true;
727
+ } catch {
728
+ void this.fail(operation, "invalid_input", "The login process could not accept the one-time code.");
729
+ return false;
730
+ }
731
+ }
682
732
  try {
683
733
  process.writeInput(text);
684
734
  console.log(
@@ -931,6 +981,29 @@ export class EngineLoginManager {
931
981
  );
932
982
  }
933
983
 
984
+ if (operation.engine === "gemini") {
985
+ // The credential is a file agy writes, never output: only the Google
986
+ // authorize URL is read from the stream.
987
+ if (operation.stage === "starting") {
988
+ const authorizeUrl = findGeminiAuthorizeUrl(operation.outputTail);
989
+ if (authorizeUrl) {
990
+ console.log(
991
+ `[engine-login] gemini authorize URL found for ${operation.opId}; awaiting the one-time code`,
992
+ );
993
+ operation.stage = "awaiting_input";
994
+ safeEmit(operation.emit, authorizeEvent(operation, authorizeUrl));
995
+ safeEmit(operation.emit, {
996
+ kind: "engine.login.event",
997
+ opId: operation.opId,
998
+ engine: operation.engine,
999
+ phase: "awaiting_input",
1000
+ message: "Paste the authorization code Google shows after you sign in.",
1001
+ });
1002
+ }
1003
+ }
1004
+ return;
1005
+ }
1006
+
934
1007
  if (operation.engine === "claude") {
935
1008
  if (operation.inputUsed && !operation.postInputOutputSeen) {
936
1009
  operation.postInputOutputSeen = true;
@@ -1056,6 +1129,13 @@ export class EngineLoginManager {
1056
1129
  if (operation.finishPromise) await operation.finishPromise;
1057
1130
  return;
1058
1131
  }
1132
+ if (operation.engine === "gemini" && result.code === 0 && operation.tempDir) {
1133
+ operation.finishing = true;
1134
+ this.clearOperationTimer(operation);
1135
+ operation.finishPromise = this.commitGemini(operation);
1136
+ await operation.finishPromise;
1137
+ return;
1138
+ }
1059
1139
  if (
1060
1140
  operation.engine === "claude" &&
1061
1141
  result.code === 0 &&
@@ -1201,6 +1281,52 @@ export class EngineLoginManager {
1201
1281
  );
1202
1282
  }
1203
1283
 
1284
+ /**
1285
+ * ADR-178: agy wrote its token file under the op's private HOME. It is
1286
+ * captured whole and opaque (never parsed, logged or refreshed here): the
1287
+ * vault keeps it as the lease part, with no broker part, and agy alone
1288
+ * renews it in the task. Only cloud capture flows take it: a runner keeps
1289
+ * no gemini sign-in of its own.
1290
+ */
1291
+ private async commitGemini(operation: LoginOperation): Promise<void> {
1292
+ const tempDir = operation.tempDir;
1293
+ if (!tempDir) return;
1294
+ if (operation.captureFlow === null) {
1295
+ await this.finishCommit(
1296
+ operation,
1297
+ failedEvent(
1298
+ operation.opId,
1299
+ operation.engine,
1300
+ "persist_failed",
1301
+ "Gemini accounts are connected in Moondeck Cloud (Connections → AI Accounts).",
1302
+ ),
1303
+ );
1304
+ return;
1305
+ }
1306
+ let contents: string;
1307
+ try {
1308
+ contents = await readFile(join(tempDir, "home", AGY_TOKEN_RELATIVE_PATH), "utf8");
1309
+ } catch {
1310
+ contents = "";
1311
+ }
1312
+ if (!contents) {
1313
+ await this.finishCommit(
1314
+ operation,
1315
+ failedEvent(
1316
+ operation.opId,
1317
+ operation.engine,
1318
+ "persist_failed",
1319
+ "Gemini authorized, but its credential could not be read.",
1320
+ ),
1321
+ );
1322
+ return;
1323
+ }
1324
+ await this.finishCapture(operation, {
1325
+ authKind: "config-dir",
1326
+ files: { "antigravity-oauth-token": contents },
1327
+ });
1328
+ }
1329
+
1204
1330
  private beginCodexFinish(operation: LoginOperation): void {
1205
1331
  if (
1206
1332
  !this.isCurrent(operation) ||
@@ -1513,11 +1639,19 @@ function lastSignificantOutputLine(tail: string): string | null {
1513
1639
  .replace(/[\u0000-\u0009\u000b-\u001f\u007f]/g, "")
1514
1640
  .split("\n")
1515
1641
  .map((line) => line.trim())
1516
- .filter((line) => line.length > 3);
1642
+ // A one-time code or the OAuth URL around it (agy's codes hold `/`, so
1643
+ // the long-token check below can miss them) never becomes evidence.
1644
+ .filter(
1645
+ (line) =>
1646
+ line.length > 3 &&
1647
+ !/code=|accounts\.google\.com/i.test(line) &&
1648
+ // A bare Google authorization code on a line of its own.
1649
+ !/^\s*4\/[0-9A-Za-z_-]+\s*$/.test(line),
1650
+ );
1517
1651
  const last = lines.at(-1);
1518
1652
  if (!last) return null;
1519
1653
  if (/sk-ant-|Bearer |[A-Za-z0-9_-]{40,}/.test(last)) return null;
1520
- return last.slice(0, 200);
1654
+ return scrubAgyDiagnostics(last).slice(0, 200);
1521
1655
  }
1522
1656
 
1523
1657
  function safeEmit(
@@ -1531,8 +1665,14 @@ function safeEmit(
1531
1665
  }
1532
1666
  }
1533
1667
 
1534
- function engineLabel(engine: EngineLoginKind): "Claude" | "Codex" | "Grok" {
1535
- return engine === "claude" ? "Claude" : engine === "codex" ? "Codex" : "Grok";
1668
+ function engineLabel(engine: EngineLoginKind): "Claude" | "Codex" | "Grok" | "Gemini" {
1669
+ return engine === "claude"
1670
+ ? "Claude"
1671
+ : engine === "codex"
1672
+ ? "Codex"
1673
+ : engine === "gemini"
1674
+ ? "Gemini"
1675
+ : "Grok";
1536
1676
  }
1537
1677
 
1538
1678
  function failedEvent(
@@ -1757,6 +1897,19 @@ function parseSafeHttpsUrl(value: string): URL | null {
1757
1897
  }
1758
1898
 
1759
1899
  /** Exported narrow parsers make secret-boundary regressions easy to fuzz. */
1900
+ /** ADR-178: agy's sign-in banner ("Open this link in a browser to log in with
1901
+ * Google:" + an accounts.google.com OAuth URL). Phrase gate + host check, so
1902
+ * no other URL in the stream can pose as the authorize page. */
1903
+ export function findGeminiAuthorizeUrl(value: string): string | null {
1904
+ const plain = stripTerminalControl(value);
1905
+ if (!/log in with Google|Authentication required/i.test(plain)) return null;
1906
+ for (const candidate of candidateHttpsUrls(plain)) {
1907
+ const parsed = parseSafeHttpsUrl(candidate);
1908
+ if (parsed && parsed.hostname === "accounts.google.com") return parsed.toString();
1909
+ }
1910
+ return null;
1911
+ }
1912
+
1760
1913
  export function findSafeHttpsUrl(value: string): string | null {
1761
1914
  for (const candidate of candidateHttpsUrls(value)) {
1762
1915
  const parsed = parseSafeHttpsUrl(candidate);
@@ -2237,7 +2390,9 @@ export function engineLoginContainerArgs(
2237
2390
  ]
2238
2391
  : request.engine === "grok"
2239
2392
  ? ["sh", "-c", GROK_LOGIN_SHELL]
2240
- : // Device-code flow: no localhost callback, no paste — the CLI prints
2393
+ : request.engine === "gemini"
2394
+ ? ["sh", "-c", GEMINI_LOGIN_SHELL]
2395
+ : // Device-code flow: no localhost callback, no paste — the CLI prints
2241
2396
  // a verification URL + one-time code, the operator confirms on the
2242
2397
  // provider's page, and the CLI polls to completion (ADR-116 v2,
2243
2398
  // 2026-08-24). The callback machinery below stays as the fallback
@@ -0,0 +1,63 @@
1
+ /**
2
+ * App-shared names an engine CLI routes by: a project's own app reads them
3
+ * too, so they are NOT reserved from project env (src/task-env-names.ts);
4
+ * instead an agent's spawn env blanks them, and the loader wrapper
5
+ * (scripts/agent/uai-env-exec.sh) puts the spawn's value back after its sync
6
+ * so a project value never reaches the engine process. Each CLI treats an
7
+ * empty value as unset (checked on the real binaries, 2026-11-25).
8
+ */
9
+ import { CONNECTION_AWS_BLANKS, CONNECTION_NATIVE_BLANKS } from "./custom-connection-launch";
10
+
11
+ /** Claude Code 2.1.332 reads the AWS SDK endpoint overrides for Bedrock. */
12
+ export const CLAUDE_SPAWN_BLANKS: Readonly<Record<string, string>> = Object.freeze({
13
+ AWS_ENDPOINT_URL: "",
14
+ AWS_ENDPOINT_URL_BEDROCK: "",
15
+ AWS_ENDPOINT_URL_BEDROCK_RUNTIME: "",
16
+ });
17
+
18
+ /** codex-cli 0.164.0's OpenAI workload-identity names: unset-only, never
19
+ * blanked. Codex treats an empty value as set and refuses to start
20
+ * ("workload identity variable OPENAI_FEDERATION_RULE_ID is invalid", checked
21
+ * 2026-11-25). uai-env-exec puts back only a non-empty pre-sync value and
22
+ * otherwise unsets them: a loader container pre-seeds every name a project
23
+ * declares as an empty placeholder (task-up.sh), and that empty value must
24
+ * not reach codex. On a baked Docker/Apple task the codex launch removes
25
+ * them with `env -u` (agentCliArgv), unless the agent's own env sets one. */
26
+ export const CODEX_UNSET_ONLY_NAMES: readonly string[] = ["OPENAI_FEDERATION_RULE_ID", "OPENAI_IDENTITY_TOKEN_FILE"];
27
+
28
+ /** Google's ADC, project and GenAI-SDK switches agy 1.5.16 reads. ADC itself
29
+ * needs AGY_ADC_AUTH, a reserved name. */
30
+ export const GEMINI_SPAWN_BLANKS: Readonly<Record<string, string>> = Object.freeze({
31
+ GOOGLE_CLOUD_PROJECT: "",
32
+ GOOGLE_CLOUD_LOCATION: "",
33
+ GOOGLE_CLOUD_QUOTA_PROJECT: "",
34
+ GOOGLE_APPLICATION_CREDENTIALS: "",
35
+ CLOUDSDK_CORE_PROJECT: "",
36
+ GOOGLE_API_KEY: "",
37
+ GOOGLE_GENAI_USE_VERTEXAI: "",
38
+ GOOGLE_GENAI_USE_ENTERPRISE: "",
39
+ });
40
+
41
+ /**
42
+ * Every name an agent spawn blanks (or, on a connection, sets) that a
43
+ * project value must not replace: every spawn's CONNECTION_NATIVE_BLANKS and
44
+ * the per-engine blanks above. uai-env-exec.sh restores these after its sync
45
+ * (uai-env-exec.test.ts holds its lists equal to these), and a legacy baked
46
+ * machine task's project floor drops them (orchestrator.ts machineProjectEnv).
47
+ */
48
+ export const SPAWN_RESTORED_ENV_NAMES: readonly string[] = [...new Set([
49
+ ...Object.keys(CONNECTION_NATIVE_BLANKS),
50
+ ...Object.keys(CLAUDE_SPAWN_BLANKS),
51
+ ...Object.keys(GEMINI_SPAWN_BLANKS),
52
+ ])].sort();
53
+
54
+ /**
55
+ * A connection launch's AWS isolation (custom-connection-launch.ts): only a
56
+ * connection sets these, so uai-env-exec restores them only when the spawn
57
+ * is one (UAI_CUSTOM_CONNECTION=1, a reserved name no project can set). A
58
+ * native spawn keeps a project's AWS_REGION, AWS_PROFILE, … like any app.
59
+ */
60
+ export const CONNECTION_RESTORED_ENV_NAMES: readonly string[] = [...new Set([
61
+ ...Object.keys(CONNECTION_AWS_BLANKS),
62
+ "AWS_EC2_METADATA_DISABLED", "AWS_CONFIG_FILE", "AWS_SHARED_CREDENTIALS_FILE", "AWS_MAX_ATTEMPTS",
63
+ ])].filter((name) => !SPAWN_RESTORED_ENV_NAMES.includes(name)).sort();