@moondeck/station 1.0.13 → 1.0.15
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/images/standard/Dockerfile +32 -0
- package/images/standard/README.md +7 -7
- package/lib/agent-cli-issues.ts +42 -13
- package/lib/agent-cli.ts +63 -42
- package/lib/agents/agy-pin.ts +36 -0
- package/lib/agents/agy-scrub.ts +11 -0
- package/lib/agents/claude.ts +5 -2
- package/lib/agents/codex.ts +5 -0
- package/lib/agents/factory.ts +1 -0
- package/lib/agents/gemini-credentials.ts +61 -0
- package/lib/agents/gemini-stream.fixture.json +439 -0
- package/lib/agents/gemini.ts +836 -0
- package/lib/agents/transport.ts +5 -2
- package/lib/browser-testing.ts +4 -2
- package/lib/credential-cleanup-inventory.ts +19 -1
- package/lib/credential-consumers/engines.ts +70 -9
- package/lib/credential-consumers/task-files.ts +19 -0
- package/lib/engine-accounts.ts +3 -0
- package/lib/engine-login.ts +162 -7
- package/lib/engine-spawn-env.ts +63 -0
- package/lib/gemini-mcp-config.ts +120 -0
- package/lib/mcp-gateway.ts +40 -8
- package/lib/orchestrator.ts +182 -26
- package/lib/standard-image-pin.ts +2 -1
- package/lib/standard-image.ts +9 -1
- package/lib/task-credential-cleanup.ts +3 -1
- package/package.json +1 -1
- package/scripts/agent/task-up.sh +36 -0
- package/scripts/agent/uai-env-exec.sh +89 -1
- package/src/cloud-credentials.ts +6 -0
- package/src/engine-account-paths.ts +2 -0
- package/src/engine-usage.ts +1 -0
- package/src/index.ts +4 -1
- package/src/main.ts +7 -1
- package/src/protocol.ts +7 -4
- package/src/task-env-names.ts +70 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ADR-178: MCP servers for Gemini (agy) agents.
|
|
3
|
+
*
|
|
4
|
+
* agy reads its MCP servers from `<gemini dir>/config/mcp_config.json`, and
|
|
5
|
+
* every Gemini agent runs with a gemini dir of its own (`agy --gemini_dir`):
|
|
6
|
+
* a subscription agent's `/home/node/.gemini-acct-<account>-agent-<agent>`,
|
|
7
|
+
* an API-key agent's `/home/node/.gemini-uai-key-agent-<agent>`. So unlike
|
|
8
|
+
* Codex or Grok there is no shared home to reconcile and no user entry to
|
|
9
|
+
* keep: Uai owns each of these files whole and writes the complete list.
|
|
10
|
+
*
|
|
11
|
+
* The format is agy's own, as `agy mcp add` writes it (agy 1.5.16, read from
|
|
12
|
+
* the file the binary wrote, not guessed):
|
|
13
|
+
*
|
|
14
|
+
* { "mcpServers": {
|
|
15
|
+
* "<stdio>": { "args": [...], "command": "...", "disabled": false,
|
|
16
|
+
* "env": { "K": "V" } }, // env optional
|
|
17
|
+
* "<http>": { "disabled": false, "headers": { "K": "V" }, // optional
|
|
18
|
+
* "serverUrl": "http://…" } } }
|
|
19
|
+
*
|
|
20
|
+
* The list is the same one every other engine gets: the watchable browser
|
|
21
|
+
* (stdio, the ADR-053 launcher) while the task has browser testing on, and
|
|
22
|
+
* each MCP connection the host gateway serves the task, at the same gateway
|
|
23
|
+
* URL Codex and Grok get (`taskGatewayServerUrls`). The URL's path token is
|
|
24
|
+
* the gateway's auth, so the content only ever travels over the writer's
|
|
25
|
+
* stdin and is never logged; a failure is a fixed message.
|
|
26
|
+
*
|
|
27
|
+
* Written with the no-follow task-file writer (task-files.ts), mode 0600, as
|
|
28
|
+
* node, only into the dir derived from the agent's own id. The dir is
|
|
29
|
+
* already inventoried as a whole for cleanup (a subscription home by
|
|
30
|
+
* writeEngineHome, an API-key dir by the orchestrator), so the file goes with
|
|
31
|
+
* it.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import { createHash } from "node:crypto";
|
|
35
|
+
import { SERVER_DEF } from "./browser-testing";
|
|
36
|
+
import { geminiKeyHome } from "./credential-consumers/engines";
|
|
37
|
+
import {
|
|
38
|
+
assertTaskRuntime,
|
|
39
|
+
runInTask,
|
|
40
|
+
TASK_HOME,
|
|
41
|
+
writeExistingTaskDirFileArgv,
|
|
42
|
+
writeTaskFileArgv,
|
|
43
|
+
type TaskWriteEnvironment,
|
|
44
|
+
} from "./credential-consumers/task-files";
|
|
45
|
+
|
|
46
|
+
/** Where agy keeps its MCP list, relative to its gemini dir. */
|
|
47
|
+
export const GEMINI_MCP_CONFIG_FILE = "config/mcp_config.json";
|
|
48
|
+
|
|
49
|
+
/** The slug the browser server takes in every engine's config. A gateway
|
|
50
|
+
* connection of the same name is left out, as Claude's merge keeps the
|
|
51
|
+
* browser entry over it. */
|
|
52
|
+
export const GEMINI_BROWSER_SERVER = "browser";
|
|
53
|
+
|
|
54
|
+
export interface GeminiMcpServers {
|
|
55
|
+
/** List the watchable browser (the task has browser testing on). */
|
|
56
|
+
browser: boolean;
|
|
57
|
+
/** Gateway URL by connection slug. */
|
|
58
|
+
gateway: Readonly<Record<string, string>>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The whole mcp_config.json for one agent, in agy's format. An empty list is
|
|
62
|
+
* still a valid file (`{"mcpServers": {}}`), never a 0-byte one. */
|
|
63
|
+
export function geminiMcpConfigJson(servers: GeminiMcpServers): string {
|
|
64
|
+
const mcpServers: Record<string, unknown> = {};
|
|
65
|
+
if (servers.browser) {
|
|
66
|
+
mcpServers[GEMINI_BROWSER_SERVER] = {
|
|
67
|
+
args: [...SERVER_DEF.args],
|
|
68
|
+
command: SERVER_DEF.command,
|
|
69
|
+
disabled: false,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
for (const slug of Object.keys(servers.gateway).sort()) {
|
|
73
|
+
if (Object.hasOwn(mcpServers, slug)) continue;
|
|
74
|
+
mcpServers[slug] = { disabled: false, serverUrl: servers.gateway[slug] };
|
|
75
|
+
}
|
|
76
|
+
return `${JSON.stringify({ mcpServers }, null, 2)}\n`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** A content fingerprint to skip rewriting an unchanged file (kept in
|
|
80
|
+
* memory only; never logged). */
|
|
81
|
+
export function geminiMcpConfigHash(content: string): string {
|
|
82
|
+
return createHash("sha256").update(content).digest("hex");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const SUBSCRIPTION_PREFIX = `${TASK_HOME}/.gemini-acct-`;
|
|
86
|
+
|
|
87
|
+
/** True only for `agentId`'s own gemini dir: its API-key dir, or a
|
|
88
|
+
* subscription account's home derived for it (`<home>-agent-<agent>`). */
|
|
89
|
+
export function isGeminiAgentDir(agentId: string, dir: string): boolean {
|
|
90
|
+
if (dir === geminiKeyHome(agentId)) return true;
|
|
91
|
+
const suffix = `-agent-${agentId.replace(/[^A-Za-z0-9_-]/g, "_")}`;
|
|
92
|
+
if (!dir.startsWith(SUBSCRIPTION_PREFIX) || !dir.endsWith(suffix)) return false;
|
|
93
|
+
const account = dir.slice(SUBSCRIPTION_PREFIX.length, dir.length - suffix.length);
|
|
94
|
+
return /^[A-Za-z0-9_-]+$/.test(account);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Write `content` as `<dir>/config/mcp_config.json`, 0600, through the
|
|
99
|
+
* no-follow writer. `create` is for the spawn that is about to run agy in
|
|
100
|
+
* `dir` (already inventoried): missing directories are created owner-only.
|
|
101
|
+
* A rewrite passes `create: false`, so the dir must still exist: a home a
|
|
102
|
+
* cleanup removed is never recreated by a later MCP change.
|
|
103
|
+
*/
|
|
104
|
+
export async function writeGeminiMcpConfig(
|
|
105
|
+
environment: TaskWriteEnvironment,
|
|
106
|
+
taskId: string,
|
|
107
|
+
agentId: string,
|
|
108
|
+
dir: string,
|
|
109
|
+
content: string,
|
|
110
|
+
options: { create: boolean; admit: () => void },
|
|
111
|
+
): Promise<void> {
|
|
112
|
+
assertTaskRuntime(environment, taskId);
|
|
113
|
+
if (!isGeminiAgentDir(agentId, dir)) {
|
|
114
|
+
throw new Error("not this Gemini agent's own agy dir");
|
|
115
|
+
}
|
|
116
|
+
const argv = options.create
|
|
117
|
+
? writeTaskFileArgv(`${dir}/${GEMINI_MCP_CONFIG_FILE}`, "600")
|
|
118
|
+
: writeExistingTaskDirFileArgv(dir, GEMINI_MCP_CONFIG_FILE, "600");
|
|
119
|
+
await runInTask(environment, argv, content, "writing the Gemini agent's MCP config", options.admit);
|
|
120
|
+
}
|
package/lib/mcp-gateway.ts
CHANGED
|
@@ -2330,6 +2330,41 @@ function shellQuote(value: string): string {
|
|
|
2330
2330
|
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
2331
2331
|
}
|
|
2332
2332
|
|
|
2333
|
+
/** ADR-121: a machine dials the gateway through its ssh REVERSE tunnel — the
|
|
2334
|
+
* host's loopback appears at the machine's own 127.0.0.1:PORT
|
|
2335
|
+
* (machine-gateway-tunnel.ts). host.docker.internal / vmnet addresses are
|
|
2336
|
+
* container topology a machine can never route. */
|
|
2337
|
+
async function gatewayHostFor(
|
|
2338
|
+
environment?: Partial<Pick<TaskEnvironmentHandle, "descriptor">>,
|
|
2339
|
+
): Promise<string> {
|
|
2340
|
+
return isEnvironmentTransportProvider(environment?.descriptor?.locator.provider)
|
|
2341
|
+
? "127.0.0.1"
|
|
2342
|
+
: await taskGatewayHost();
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
/**
|
|
2346
|
+
* The gateway URL of each slug under the task's EXISTING ACL token, the same
|
|
2347
|
+
* URL `setupMcpTaskConfig` writes for every other engine (which must have
|
|
2348
|
+
* succeeded for these connections first: it writes the ACL). Null when the
|
|
2349
|
+
* task has no ACL yet. For engines that keep their MCP list in a file of
|
|
2350
|
+
* their own, written by a separate writer (Gemini: gemini-mcp-config.ts).
|
|
2351
|
+
* Never log the result: the path token is the gateway's auth.
|
|
2352
|
+
*/
|
|
2353
|
+
export async function taskGatewayServerUrls(
|
|
2354
|
+
taskId: string,
|
|
2355
|
+
slugs: readonly string[],
|
|
2356
|
+
environment?: Partial<Pick<TaskEnvironmentHandle, "descriptor">>,
|
|
2357
|
+
): Promise<Record<string, string> | null> {
|
|
2358
|
+
const acl = readAcl(taskId);
|
|
2359
|
+
if (!acl || typeof acl.token !== "string" || acl.token.length === 0) return null;
|
|
2360
|
+
const host = await gatewayHostFor(environment);
|
|
2361
|
+
const urls: Record<string, string> = {};
|
|
2362
|
+
for (const slug of slugs) {
|
|
2363
|
+
urls[slug] = `http://${host}:${MCP_GATEWAY_PORT}/t/${acl.token}/${slug}`;
|
|
2364
|
+
}
|
|
2365
|
+
return urls;
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2333
2368
|
/** Config homes are independent, but every Uai/browser writer must remain
|
|
2334
2369
|
* behind one flock. Run a bounded batch at a time so the supported account ×
|
|
2335
2370
|
* agent count cannot turn the outer timeout into a deterministic failure. */
|
|
@@ -2385,6 +2420,9 @@ const MCP_CONFIG_GROK_BATCH_BUDGET_S = 2 + Math.ceil(MAX_MANIFEST_MCP / 4);
|
|
|
2385
2420
|
* - OpenCode — ~/.config/opencode/opencode.json `mcp` block (type:"remote",
|
|
2386
2421
|
* oauth:false so it treats the gateway URL as a plain server; the path
|
|
2387
2422
|
* token is the auth).
|
|
2423
|
+
* - Gemini — NOT here: each agent's own agy dir gets a whole-file
|
|
2424
|
+
* mcp_config.json from gemini-mcp-config.ts (the orchestrator writes it
|
|
2425
|
+
* after this succeeds, with `taskGatewayServerUrls`).
|
|
2388
2426
|
* Safe to re-run every ensure. `engineKinds` is the roster's agent kinds.
|
|
2389
2427
|
*/
|
|
2390
2428
|
export async function setupMcpTaskConfig(
|
|
@@ -2417,14 +2455,8 @@ export async function setupMcpTaskConfig(
|
|
|
2417
2455
|
throw new Error("invalid Codex MCP connection slug");
|
|
2418
2456
|
}
|
|
2419
2457
|
const acl = ensureTaskGatewayAcl(taskId, connections);
|
|
2420
|
-
// ADR-121: a machine dials
|
|
2421
|
-
|
|
2422
|
-
// (machine-gateway-tunnel.ts). host.docker.internal / vmnet addresses
|
|
2423
|
-
// are container topology a machine can never route.
|
|
2424
|
-
const gatewayHost =
|
|
2425
|
-
isEnvironmentTransportProvider(environment?.descriptor?.locator.provider)
|
|
2426
|
-
? "127.0.0.1"
|
|
2427
|
-
: await taskGatewayHost();
|
|
2458
|
+
// ADR-121: a machine dials through its reverse tunnel (gatewayHostFor).
|
|
2459
|
+
const gatewayHost = await gatewayHostFor(environment);
|
|
2428
2460
|
const urlFor = (slug: string): string =>
|
|
2429
2461
|
`http://${gatewayHost}:${MCP_GATEWAY_PORT}/t/${acl.token}/${slug}`;
|
|
2430
2462
|
|
package/lib/orchestrator.ts
CHANGED
|
@@ -70,6 +70,7 @@ import {
|
|
|
70
70
|
import { ACTIVE_STATUSES, isActive, isOnDashboard } from "./task-status";
|
|
71
71
|
import { isSafeHostTaskId } from "./task-identity";
|
|
72
72
|
import { projectEnvForTask } from "./host-env";
|
|
73
|
+
import { CODEX_UNSET_ONLY_NAMES, SPAWN_RESTORED_ENV_NAMES } from "./engine-spawn-env";
|
|
73
74
|
import { CLASSIFIER_MODEL, shadowRoute } from "./routing/shadow";
|
|
74
75
|
import {
|
|
75
76
|
closeCurrentTaskRunAssignmentForStoppedRuntime,
|
|
@@ -195,6 +196,7 @@ import { buildEngineUsageFrame } from "../src/engine-usage";
|
|
|
195
196
|
import {
|
|
196
197
|
ENGINE_ACCOUNT_HOMES,
|
|
197
198
|
EngineCredentialWriteRefused,
|
|
199
|
+
geminiKeyHome,
|
|
198
200
|
engineSpawnEnv,
|
|
199
201
|
engineVersionHeldBack,
|
|
200
202
|
ensureEngineHome,
|
|
@@ -240,7 +242,9 @@ import {
|
|
|
240
242
|
LEASED_ENGINE_KINDS,
|
|
241
243
|
MANAGED_ENGINE_KIND,
|
|
242
244
|
} from "../src/cloud-credentials";
|
|
243
|
-
import { clearTaskGatewayAcl, setupMcpTaskConfig } from "./mcp-gateway";
|
|
245
|
+
import { clearTaskGatewayAcl, setupMcpTaskConfig, taskGatewayServerUrls } from "./mcp-gateway";
|
|
246
|
+
import { GEMINI_DIR_ENV } from "./agents/gemini";
|
|
247
|
+
import { geminiMcpConfigHash, geminiMcpConfigJson, writeGeminiMcpConfig } from "./gemini-mcp-config";
|
|
244
248
|
import {
|
|
245
249
|
reactivateTaskGatewayTask,
|
|
246
250
|
removeTaskGatewayTask,
|
|
@@ -456,6 +460,17 @@ interface Channel {
|
|
|
456
460
|
/** Serialize gateway config writes so two ensures cannot publish stale
|
|
457
461
|
* content and then memoize the newer fingerprint over it. */
|
|
458
462
|
mcpConfigWrite: Promise<void> | null;
|
|
463
|
+
/** The connection set the last successful gateway publication wrote (and
|
|
464
|
+
* the gateway ACL holds): what Gemini agents' own configs list. */
|
|
465
|
+
mcpServedConnections: Array<{ slug: string }> | null;
|
|
466
|
+
/** ADR-178: each Gemini agent's own agy dir (from its spawn), whose
|
|
467
|
+
* mcp_config.json Uai keeps current. */
|
|
468
|
+
geminiMcpDirs: Map<string, string>;
|
|
469
|
+
/** What was last written in each of those dirs (a content hash). */
|
|
470
|
+
geminiMcpWritten: Map<string, string>;
|
|
471
|
+
/** Serializes Gemini config writes: each computes its content when it
|
|
472
|
+
* runs, so the last write carries the latest state. */
|
|
473
|
+
geminiMcpWrite: Promise<unknown> | null;
|
|
459
474
|
/** Account provisioning can overwrite per-engine config without changing
|
|
460
475
|
* the desired gateway fingerprint. A monotonic epoch prevents an older
|
|
461
476
|
* in-flight writer from clearing a newer provisioning mutation. */
|
|
@@ -639,6 +654,7 @@ const ENGINE_USAGE_KINDS = new Set<EngineUsageFrame["engine"]>([
|
|
|
639
654
|
"grok",
|
|
640
655
|
"cursor",
|
|
641
656
|
"opencode",
|
|
657
|
+
"gemini",
|
|
642
658
|
]);
|
|
643
659
|
|
|
644
660
|
function isEngineUsageKind(kind: string): kind is EngineUsageFrame["engine"] {
|
|
@@ -1508,6 +1524,10 @@ export class Orchestrator {
|
|
|
1508
1524
|
mcpConnections: spec.mcpConnections ?? [],
|
|
1509
1525
|
mcpLeaseConnections: null,
|
|
1510
1526
|
mcpConfigWrite: null,
|
|
1527
|
+
mcpServedConnections: null,
|
|
1528
|
+
geminiMcpDirs: new Map(),
|
|
1529
|
+
geminiMcpWritten: new Map(),
|
|
1530
|
+
geminiMcpWrite: null,
|
|
1511
1531
|
mcpConfigDirtyEpoch: 1,
|
|
1512
1532
|
mcpConfigAppliedEpoch: 0,
|
|
1513
1533
|
mcpProvisionAffectedKinds: new Set(),
|
|
@@ -2147,6 +2167,12 @@ export class Orchestrator {
|
|
|
2147
2167
|
}
|
|
2148
2168
|
|
|
2149
2169
|
if (!this.isActiveChannel(channel)) return unavailable;
|
|
2170
|
+
// ADR-178: Gemini agents' own configs list the browser while it's on;
|
|
2171
|
+
// rewritten before the sessions below are marked to recycle.
|
|
2172
|
+
if (channel.geminiMcpDirs.size > 0 && setup.configured) {
|
|
2173
|
+
await this.ensureGeminiMcpConfig(channel);
|
|
2174
|
+
if (!this.isActiveChannel(channel)) return unavailable;
|
|
2175
|
+
}
|
|
2150
2176
|
|
|
2151
2177
|
channel.browserReady = setup.ready && setup.configured;
|
|
2152
2178
|
if (setup.changed) {
|
|
@@ -2377,6 +2403,14 @@ export class Orchestrator {
|
|
|
2377
2403
|
grokHomes,
|
|
2378
2404
|
);
|
|
2379
2405
|
if (!configured || !this.isActiveChannel(channel)) return;
|
|
2406
|
+
channel.mcpServedConnections = connections.map(({ slug }) => ({ slug }));
|
|
2407
|
+
// ADR-178: every Gemini agent's own agy dir lists the same servers,
|
|
2408
|
+
// rewritten before any session is marked to recycle below. No await
|
|
2409
|
+
// without a Gemini agent: other engines' timing stays as it was.
|
|
2410
|
+
if (channel.geminiMcpDirs.size > 0) {
|
|
2411
|
+
await this.ensureGeminiMcpConfig(channel, providerEnvironment);
|
|
2412
|
+
if (!this.isActiveChannel(channel)) return;
|
|
2413
|
+
}
|
|
2380
2414
|
channel.configGeneration += 1;
|
|
2381
2415
|
channel.mcpConfigFingerprint = fingerprint;
|
|
2382
2416
|
// Only acknowledge the epoch this write observed. If provisioning dirtied
|
|
@@ -2437,6 +2471,83 @@ export class Orchestrator {
|
|
|
2437
2471
|
}
|
|
2438
2472
|
}
|
|
2439
2473
|
|
|
2474
|
+
/**
|
|
2475
|
+
* ADR-178: keep each Gemini agent's `<gemini dir>/config/mcp_config.json`
|
|
2476
|
+
* listing what every other engine gets: the browser while the task has it
|
|
2477
|
+
* on, and the gateway's served connections at the same URLs. `spawn` names
|
|
2478
|
+
* the agent about to start agy in `dir`: it is registered and always
|
|
2479
|
+
* written (its dirs may be missing). Otherwise every registered dir whose
|
|
2480
|
+
* content changed is rewritten, never recreated. Serialized per channel;
|
|
2481
|
+
* a failure is logged with a fixed message and the agent still starts (as
|
|
2482
|
+
* every other engine's config write). Resolves to the agents written.
|
|
2483
|
+
*/
|
|
2484
|
+
private ensureGeminiMcpConfig(
|
|
2485
|
+
channel: Channel,
|
|
2486
|
+
environment?: TaskEnvironmentHandle<unknown>,
|
|
2487
|
+
spawn?: { agentId: string; dir: string },
|
|
2488
|
+
): Promise<string[]> {
|
|
2489
|
+
const run = (channel.geminiMcpWrite ?? Promise.resolve())
|
|
2490
|
+
.catch(() => undefined)
|
|
2491
|
+
.then(() => this.writeGeminiMcpPass(channel, environment, spawn));
|
|
2492
|
+
channel.geminiMcpWrite = run;
|
|
2493
|
+
return run.finally(() => {
|
|
2494
|
+
if (channel.geminiMcpWrite === run) channel.geminiMcpWrite = null;
|
|
2495
|
+
});
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
private async writeGeminiMcpPass(
|
|
2499
|
+
channel: Channel,
|
|
2500
|
+
environment: TaskEnvironmentHandle<unknown> | undefined,
|
|
2501
|
+
spawn: { agentId: string; dir: string } | undefined,
|
|
2502
|
+
): Promise<string[]> {
|
|
2503
|
+
if (!this.isActiveChannel(channel)) return [];
|
|
2504
|
+
if (spawn) channel.geminiMcpDirs.set(spawn.agentId, spawn.dir);
|
|
2505
|
+
for (const agentId of [...channel.geminiMcpDirs.keys()]) {
|
|
2506
|
+
if (!channel.roster.some((agent) => agent.id === agentId && agent.kind === "gemini")) {
|
|
2507
|
+
channel.geminiMcpWritten.delete(channel.geminiMcpDirs.get(agentId)!);
|
|
2508
|
+
channel.geminiMcpDirs.delete(agentId);
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
const targets: Array<[string, string]> = spawn
|
|
2512
|
+
? channel.geminiMcpDirs.get(spawn.agentId) === spawn.dir ? [[spawn.agentId, spawn.dir]] : []
|
|
2513
|
+
: [...channel.geminiMcpDirs];
|
|
2514
|
+
const target = environment ?? channel.agentHandle ?? undefined;
|
|
2515
|
+
if (targets.length === 0 || !target) return [];
|
|
2516
|
+
const slugs = (channel.mcpServedConnections ?? []).map(({ slug }) => slug);
|
|
2517
|
+
const gateway = slugs.length > 0
|
|
2518
|
+
? await taskGatewayServerUrls(channel.taskId, slugs, target)
|
|
2519
|
+
: {};
|
|
2520
|
+
// No ACL although connections were published: the task is being torn
|
|
2521
|
+
// down; write nothing rather than a list without its servers.
|
|
2522
|
+
if (gateway === null || !this.isActiveChannel(channel)) return [];
|
|
2523
|
+
const content = geminiMcpConfigJson({ browser: channel.browserTesting, gateway });
|
|
2524
|
+
const hash = geminiMcpConfigHash(content);
|
|
2525
|
+
const written: string[] = [];
|
|
2526
|
+
for (const [agentId, dir] of targets) {
|
|
2527
|
+
if (!spawn && channel.geminiMcpWritten.get(dir) === hash) continue;
|
|
2528
|
+
try {
|
|
2529
|
+
await writeGeminiMcpConfig(target, channel.taskId, agentId, dir, content, {
|
|
2530
|
+
create: spawn !== undefined,
|
|
2531
|
+
admit: () => {
|
|
2532
|
+
if (!this.isActiveChannel(channel) || channel.geminiMcpDirs.get(agentId) !== dir) {
|
|
2533
|
+
throw new Error("the Gemini agent moved");
|
|
2534
|
+
}
|
|
2535
|
+
},
|
|
2536
|
+
});
|
|
2537
|
+
channel.geminiMcpWritten.set(dir, hash);
|
|
2538
|
+
written.push(agentId);
|
|
2539
|
+
} catch (err) {
|
|
2540
|
+
channel.geminiMcpWritten.delete(dir);
|
|
2541
|
+
console.warn(
|
|
2542
|
+
`[orchestrator] ${channel.taskId}/${agentId}: writing its Gemini MCP config failed: ${
|
|
2543
|
+
err instanceof Error ? err.message : String(err)
|
|
2544
|
+
}`,
|
|
2545
|
+
);
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
return written;
|
|
2549
|
+
}
|
|
2550
|
+
|
|
2440
2551
|
/** Close stale sessions that are idle, without recursively reconciling. */
|
|
2441
2552
|
private async closeIdleStaleSessions(channel: Channel): Promise<number> {
|
|
2442
2553
|
let recycled = 0;
|
|
@@ -2906,7 +3017,12 @@ export class Orchestrator {
|
|
|
2906
3017
|
) {
|
|
2907
3018
|
return {};
|
|
2908
3019
|
}
|
|
2909
|
-
|
|
3020
|
+
// These values ride the agent's own env here, under the spawn blanks that
|
|
3021
|
+
// keep an app-shared name (OPENAI_BASE_URL, …) from routing an agent's
|
|
3022
|
+
// CLI: drop them, or the project's value would win over its blank.
|
|
3023
|
+
const env = projectEnvForTask(hostTaskProjectIds(task));
|
|
3024
|
+
for (const name of [...SPAWN_RESTORED_ENV_NAMES, ...CODEX_UNSET_ONLY_NAMES]) delete env[name];
|
|
3025
|
+
return env;
|
|
2910
3026
|
}
|
|
2911
3027
|
|
|
2912
3028
|
|
|
@@ -3104,7 +3220,8 @@ export class Orchestrator {
|
|
|
3104
3220
|
if (lease?.open) {
|
|
3105
3221
|
const account = this.leasedAccountFor(channel, agentId, kind, lease);
|
|
3106
3222
|
if (account?.authKind === "env") {
|
|
3107
|
-
return this.withLeasedAccount(channel, agentId, args, account, lease.assignment.runEpoch
|
|
3223
|
+
return this.withLeasedAccount(channel, agentId, args, account, lease.assignment.runEpoch,
|
|
3224
|
+
this.geminiKeyHomeFor(channel, agentId, account, lease.assignment.runEpoch, environment));
|
|
3108
3225
|
}
|
|
3109
3226
|
}
|
|
3110
3227
|
return (async () => {
|
|
@@ -3127,7 +3244,8 @@ export class Orchestrator {
|
|
|
3127
3244
|
break;
|
|
3128
3245
|
}
|
|
3129
3246
|
if (account.authKind === "env") {
|
|
3130
|
-
return this.withLeasedAccount(channel, agentId, args, account, open.assignment.runEpoch
|
|
3247
|
+
return this.withLeasedAccount(channel, agentId, args, account, open.assignment.runEpoch,
|
|
3248
|
+
this.geminiKeyHomeFor(channel, agentId, account, open.assignment.runEpoch, environment));
|
|
3131
3249
|
}
|
|
3132
3250
|
if (account.authKind === "custom-connection") {
|
|
3133
3251
|
try {
|
|
@@ -3223,7 +3341,12 @@ export class Orchestrator {
|
|
|
3223
3341
|
if (!this.isActiveChannel(channel)) return null;
|
|
3224
3342
|
// Codex runs in a home of its own (two agents on one account never
|
|
3225
3343
|
// share its state runtime); the config writers above reached it.
|
|
3226
|
-
|
|
3344
|
+
// Gemini too (ADR-178): each agent's agy keeps and renews its own
|
|
3345
|
+
// token file and conversations.
|
|
3346
|
+
const home =
|
|
3347
|
+
kind === "codex" || kind === "gemini"
|
|
3348
|
+
? codexPerAgentHome(account.home!, agentId)
|
|
3349
|
+
: account.home!;
|
|
3227
3350
|
try {
|
|
3228
3351
|
await ensureEngineHome(environment, open.assignment, account.credentialId, home);
|
|
3229
3352
|
} catch (error) {
|
|
@@ -3250,6 +3373,26 @@ export class Orchestrator {
|
|
|
3250
3373
|
})();
|
|
3251
3374
|
}
|
|
3252
3375
|
|
|
3376
|
+
/** ADR-178: an API-key Gemini agent runs agy in a dir of its own (never a
|
|
3377
|
+
* subscription's), inventoried under this run so a cleanup removes it with
|
|
3378
|
+
* the agent's agy state. Undefined for every other account. */
|
|
3379
|
+
private geminiKeyHomeFor(
|
|
3380
|
+
channel: Channel,
|
|
3381
|
+
agentId: string,
|
|
3382
|
+
account: LeasedEngineAccount,
|
|
3383
|
+
runEpoch: number,
|
|
3384
|
+
environment: TaskEnvironmentHandle<unknown>,
|
|
3385
|
+
): string | undefined {
|
|
3386
|
+
if (account.engineKind !== "gemini" || account.authKind !== "env") return undefined;
|
|
3387
|
+
const home = geminiKeyHome(agentId);
|
|
3388
|
+
rememberCredentialCleanupPath({
|
|
3389
|
+
taskId: channel.taskId, runEpoch,
|
|
3390
|
+
runtime: environment.descriptor.locator, lane: "engine-auth",
|
|
3391
|
+
path: home, credentialId: account.credentialId,
|
|
3392
|
+
});
|
|
3393
|
+
return home;
|
|
3394
|
+
}
|
|
3395
|
+
|
|
3253
3396
|
/** The task's open engine lease, waited for while time remains, a newer
|
|
3254
3397
|
* run's when the task moves on to one; null when none opens in time. */
|
|
3255
3398
|
private async leasedGateOpen(channel: Channel, deadline: number): Promise<TaskEngineLease | null> {
|
|
@@ -4211,6 +4354,17 @@ export class Orchestrator {
|
|
|
4211
4354
|
} else if (kind === "codex") {
|
|
4212
4355
|
boundArgs = await this.isolateCodexHome(environment, agentId, args);
|
|
4213
4356
|
}
|
|
4357
|
+
// ADR-178: agy reads its MCP servers from its own gemini dir, so that
|
|
4358
|
+
// dir gets the task's list before agy can start in it. The API-key path
|
|
4359
|
+
// binds without the gateway write the subscription path awaits, so
|
|
4360
|
+
// publish (a no-op when current) first.
|
|
4361
|
+
const geminiDir = kind === "gemini" ? boundArgs.agentEnv?.[GEMINI_DIR_ENV] : undefined;
|
|
4362
|
+
if (geminiDir) {
|
|
4363
|
+
await this.ensureMcpConfig(channel);
|
|
4364
|
+
if (!this.isActiveChannel(channel)) return null;
|
|
4365
|
+
await this.ensureGeminiMcpConfig(channel, environment, { agentId, dir: geminiDir });
|
|
4366
|
+
if (!this.isActiveChannel(channel)) return null;
|
|
4367
|
+
}
|
|
4214
4368
|
while (this.isActiveChannel(channel)) {
|
|
4215
4369
|
if (recovery && !this.recoveryIsCurrent(channel, agentId, recovery)) {
|
|
4216
4370
|
channel.reconcileAgain = true;
|
|
@@ -4427,7 +4581,9 @@ export class Orchestrator {
|
|
|
4427
4581
|
): Promise<{ exitCode: number | null; stdout: string } | null> {
|
|
4428
4582
|
if (channel.roster.find(a => a.id === agentId)?.accountBinding === "required") return null;
|
|
4429
4583
|
const request = (env: Record<string, string>, admit: () => void) => ({
|
|
4430
|
-
|
|
4584
|
+
// Codex refuses an empty workload-identity name: on a baked container a
|
|
4585
|
+
// project's value is removed, unless this env sets it (agentCliArgv).
|
|
4586
|
+
argv: agentCliArgv(handle, argv, kind === "codex" ? CODEX_UNSET_ONLY_NAMES.filter((name) => !Object.hasOwn(env, name)) : []),
|
|
4431
4587
|
projectEnvProfile: "task" as const,
|
|
4432
4588
|
cwd: scratchDir,
|
|
4433
4589
|
user: "node",
|
|
@@ -5197,7 +5353,7 @@ export class Orchestrator {
|
|
|
5197
5353
|
}
|
|
5198
5354
|
|
|
5199
5355
|
const channel = await this.getOrCreateChannel(taskId);
|
|
5200
|
-
if (!channel) return { ok: false, error: "task or
|
|
5356
|
+
if (!channel) return { ok: false, error: "task or repository not found" };
|
|
5201
5357
|
|
|
5202
5358
|
const ready = await this.ensureSessions(channel);
|
|
5203
5359
|
if (!ready) {
|
|
@@ -7841,7 +7997,7 @@ export function buildSystemPreamble(
|
|
|
7841
7997
|
"## Workspace layout",
|
|
7842
7998
|
"",
|
|
7843
7999
|
`Your shell starts in \`${workspacePath}\`. It contains one`,
|
|
7844
|
-
"
|
|
8000
|
+
"Git worktree per repository:",
|
|
7845
8001
|
"",
|
|
7846
8002
|
...projectLines,
|
|
7847
8003
|
"",
|
|
@@ -7855,7 +8011,7 @@ export function buildSystemPreamble(
|
|
|
7855
8011
|
]),
|
|
7856
8012
|
"",
|
|
7857
8013
|
"The `.moondeck/` directory is Moondeck scaffolding. Read the two transcript files",
|
|
7858
|
-
"there as described above; do not treat the rest as
|
|
8014
|
+
"there as described above; do not treat the rest as repository content.",
|
|
7859
8015
|
"",
|
|
7860
8016
|
]
|
|
7861
8017
|
: [
|
|
@@ -7863,16 +8019,16 @@ export function buildSystemPreamble(
|
|
|
7863
8019
|
"",
|
|
7864
8020
|
`Your shell starts in \`${workspacePath}\` (the task workspace).`,
|
|
7865
8021
|
"That directory is **not** itself a git repo — it holds one git",
|
|
7866
|
-
"worktree per
|
|
8022
|
+
"worktree per repository this task spans. Every repository below is on the",
|
|
7867
8023
|
"same task branch. To run git commands, **`cd` into one of the",
|
|
7868
|
-
"
|
|
8024
|
+
"repository directories first**:",
|
|
7869
8025
|
"",
|
|
7870
8026
|
...projectLines,
|
|
7871
8027
|
"",
|
|
7872
8028
|
`The task branch is \`${taskBranch}\`. Push with \`git push -u origin`,
|
|
7873
|
-
`${taskBranch}\` from inside the
|
|
7874
|
-
"create` (the container has gh authenticated). For multi-
|
|
7875
|
-
"tasks, each
|
|
8029
|
+
`${taskBranch}\` from inside the repository, then open a PR with \`gh pr`,
|
|
8030
|
+
"create` (the container has gh authenticated). For multi-repository",
|
|
8031
|
+
"tasks, each repository's PR is independent — open one per repository whose",
|
|
7876
8032
|
"worktree you actually changed. For a separate branch, create it in",
|
|
7877
8033
|
"this task's namespace — `git switch -c \"$(moondeck branch name fix-foo)\"`",
|
|
7878
8034
|
"makes `uai/<taskId>/fix-foo`. Only task-branch and namespace PRs link to",
|
|
@@ -7880,7 +8036,7 @@ export function buildSystemPreamble(
|
|
|
7880
8036
|
"",
|
|
7881
8037
|
"The `.moondeck/` directory under each task is Moondeck's own scaffolding",
|
|
7882
8038
|
"(rendered Dockerfile, compose file, container scripts) — it is NOT",
|
|
7883
|
-
"part of the
|
|
8039
|
+
"part of the repository. Never review, edit, stage, commit, or flag it;",
|
|
7884
8040
|
"treat it as ignored, even though git may show it as untracked.",
|
|
7885
8041
|
"",
|
|
7886
8042
|
];
|
|
@@ -8125,7 +8281,7 @@ export function buildSystemPreamble(
|
|
|
8125
8281
|
"",
|
|
8126
8282
|
`You can query and plan through Moondeck by running \`node ${CONTAINER_CLI_PATH}`,
|
|
8127
8283
|
"<command>` in the shell. Your permissions:",
|
|
8128
|
-
`\`${(agent.permissions ?? []).join(", ")}\`. Commands: \`
|
|
8284
|
+
`\`${(agent.permissions ?? []).join(", ")}\`. Commands: \`repos list\`,`,
|
|
8129
8285
|
"`people list`, `task list`" +
|
|
8130
8286
|
(agent.permissions?.includes("issues.read")
|
|
8131
8287
|
? ", `issue list`, `issue show KEY-N`, `issue current` (Issue reads; add --json for structured output)"
|
|
@@ -8134,7 +8290,7 @@ export function buildSystemPreamble(
|
|
|
8134
8290
|
? ", `issue create --title T`, `issue update KEY-N`, `issue link KEY-N`, `issue unlink KEY-N` (Issue writes; see the guide for flags)"
|
|
8135
8291
|
: "") +
|
|
8136
8292
|
(agent.permissions?.includes("tasks.create")
|
|
8137
|
-
? ", `task create --name <n> --prompt <p> [--
|
|
8293
|
+
? ", `task create --name <n> --prompt <p> [--repos id,id] [--agents handle,handle] [--astronaut engine/model/effort] [--start --request-id <logical-run-id>]`"
|
|
8138
8294
|
: "") +
|
|
8139
8295
|
(agent.permissions?.includes("tasks.read")
|
|
8140
8296
|
? ", `task watch <childId> [--after <cursor>]`, `task usage <childId>`"
|
|
@@ -8158,7 +8314,7 @@ export function buildSystemPreamble(
|
|
|
8158
8314
|
? ", `preview add|enable|public <name>`"
|
|
8159
8315
|
: "") +
|
|
8160
8316
|
(agent.permissions?.includes("projects.write")
|
|
8161
|
-
? ", `
|
|
8317
|
+
? ", `repo create --name --repo`"
|
|
8162
8318
|
: "") +
|
|
8163
8319
|
(agent.permissions?.includes("tasks.history")
|
|
8164
8320
|
? ", `task search <query>` / `task read <id>`"
|
|
@@ -8183,7 +8339,7 @@ export function buildSystemPreamble(
|
|
|
8183
8339
|
"Closing the parent leaves running children alive. Child permissions never exceed your live creation ceiling.",
|
|
8184
8340
|
"Send/answer are visibly delegated agent inputs, never human approval.",
|
|
8185
8341
|
"Discover options first with",
|
|
8186
|
-
"`
|
|
8342
|
+
"`repos list` / `people list`.",
|
|
8187
8343
|
]
|
|
8188
8344
|
: []),
|
|
8189
8345
|
...(agent.permissions?.includes("tasks.close")
|
|
@@ -9312,15 +9468,15 @@ function validateRecoveryProjects(
|
|
|
9312
9468
|
try {
|
|
9313
9469
|
parsed = JSON.parse(task.projectSlugs);
|
|
9314
9470
|
} catch {
|
|
9315
|
-
return { error: "the persisted
|
|
9471
|
+
return { error: "the persisted repository slug list is invalid JSON" };
|
|
9316
9472
|
}
|
|
9317
9473
|
if (!Array.isArray(parsed) || !parsed.every(safeRecoveryProjectSlug)) {
|
|
9318
|
-
return { error: "the persisted
|
|
9474
|
+
return { error: "the persisted repository slug list contains an unsafe entry" };
|
|
9319
9475
|
}
|
|
9320
9476
|
const slugs = parsed as string[];
|
|
9321
9477
|
const expected = new Set(slugs);
|
|
9322
9478
|
if (expected.size !== slugs.length) {
|
|
9323
|
-
return { error: "the persisted
|
|
9479
|
+
return { error: "the persisted repository slug list contains duplicates" };
|
|
9324
9480
|
}
|
|
9325
9481
|
|
|
9326
9482
|
for (const slug of expected) {
|
|
@@ -9331,7 +9487,7 @@ function validateRecoveryProjects(
|
|
|
9331
9487
|
projectStat = lstatSync(project);
|
|
9332
9488
|
markerStat = lstatSync(join(project, ".git"));
|
|
9333
9489
|
} catch {
|
|
9334
|
-
return { error: `expected
|
|
9490
|
+
return { error: `expected repository ${slug} or its .git marker is missing` };
|
|
9335
9491
|
}
|
|
9336
9492
|
if (
|
|
9337
9493
|
projectStat.isSymbolicLink() ||
|
|
@@ -9339,7 +9495,7 @@ function validateRecoveryProjects(
|
|
|
9339
9495
|
markerStat.isSymbolicLink() ||
|
|
9340
9496
|
(!markerStat.isFile() && !markerStat.isDirectory())
|
|
9341
9497
|
) {
|
|
9342
|
-
return { error: `expected
|
|
9498
|
+
return { error: `expected repository ${slug} is not a safe Git worktree` };
|
|
9343
9499
|
}
|
|
9344
9500
|
}
|
|
9345
9501
|
return { slugs };
|
|
@@ -9384,7 +9540,7 @@ function recoveryRuntimeProjectAllowlist(
|
|
|
9384
9540
|
return { error: "the task runtime-project allowlist is not a regular file" };
|
|
9385
9541
|
}
|
|
9386
9542
|
if (readFileSync(target, "utf8") !== expected) {
|
|
9387
|
-
return { error: "the task runtime-project allowlist does not match persisted
|
|
9543
|
+
return { error: "the task runtime-project allowlist does not match persisted repositories" };
|
|
9388
9544
|
}
|
|
9389
9545
|
return { path: target };
|
|
9390
9546
|
} catch (err) {
|
|
@@ -9393,7 +9549,7 @@ function recoveryRuntimeProjectAllowlist(
|
|
|
9393
9549
|
|
|
9394
9550
|
if (slugs.length === 0) {
|
|
9395
9551
|
return {
|
|
9396
|
-
error: "zero-
|
|
9552
|
+
error: "zero-repository recovery lacks an existing authoritative empty runtime-project allowlist",
|
|
9397
9553
|
};
|
|
9398
9554
|
}
|
|
9399
9555
|
|
|
@@ -39,13 +39,14 @@ export const STANDARD_IMAGE_PIN_BASENAME = "standard-image.pin.json";
|
|
|
39
39
|
* host — and toggling an engine on stops forcing a host-side rebuild.
|
|
40
40
|
*/
|
|
41
41
|
export const STANDARD_IMAGE_SUPERSET_EXTRA =
|
|
42
|
-
"kimi=1;grok=1;cursor=1;opencode=1";
|
|
42
|
+
"kimi=1;grok=1;cursor=1;opencode=1;gemini=1";
|
|
43
43
|
|
|
44
44
|
export const STANDARD_IMAGE_SUPERSET_BUILD_ARGS: readonly string[] = [
|
|
45
45
|
"INSTALL_KIMI=1",
|
|
46
46
|
"INSTALL_GROK=1",
|
|
47
47
|
"INSTALL_CURSOR=1",
|
|
48
48
|
"INSTALL_OPENCODE=1",
|
|
49
|
+
"INSTALL_GEMINI=1",
|
|
49
50
|
];
|
|
50
51
|
|
|
51
52
|
export interface StandardImagePin {
|
package/lib/standard-image.ts
CHANGED
|
@@ -52,6 +52,7 @@ import {
|
|
|
52
52
|
standardImagePullCommands,
|
|
53
53
|
standardImagePullDigest,
|
|
54
54
|
} from "./standard-image-pin";
|
|
55
|
+
import { geminiCredentialSource } from "./agents/gemini-credentials";
|
|
55
56
|
import { sidecarMode } from "./sidecar";
|
|
56
57
|
import { StandardImageCleanup, StandardImageBuildBackoff } from "./standard-image-cleanup";
|
|
57
58
|
|
|
@@ -125,6 +126,7 @@ export function configuredOptionalEngines(): {
|
|
|
125
126
|
grok: boolean;
|
|
126
127
|
cursor: boolean;
|
|
127
128
|
opencode: boolean;
|
|
129
|
+
gemini: boolean;
|
|
128
130
|
} {
|
|
129
131
|
// A stored account (a workspace's, on a shared host; a labeled extra on an
|
|
130
132
|
// owned one) needs the CLI in the image just like the host's own sign-in
|
|
@@ -137,6 +139,10 @@ export function configuredOptionalEngines(): {
|
|
|
137
139
|
grok: on("grok"),
|
|
138
140
|
cursor: on("cursor"),
|
|
139
141
|
opencode: on("opencode"),
|
|
142
|
+
// Antigravity CLI: gated on the sign-in seam (gemini-credentials.ts), not
|
|
143
|
+
// engines.ts. How the credential reaches a task waits on the ADR-154
|
|
144
|
+
// decision; the binary only needs to be present.
|
|
145
|
+
gemini: geminiCredentialSource().hostSignedIn(),
|
|
140
146
|
};
|
|
141
147
|
}
|
|
142
148
|
|
|
@@ -1372,9 +1378,11 @@ async function ensureStandardImageInner(
|
|
|
1372
1378
|
`INSTALL_CURSOR=${engines.cursor ? 1 : 0}`,
|
|
1373
1379
|
"--build-arg",
|
|
1374
1380
|
`INSTALL_OPENCODE=${engines.opencode ? 1 : 0}`,
|
|
1381
|
+
"--build-arg",
|
|
1382
|
+
`INSTALL_GEMINI=${engines.gemini ? 1 : 0}`,
|
|
1375
1383
|
];
|
|
1376
1384
|
const contextHash = await hashBuildContext(
|
|
1377
|
-
`kimi=${engines.kimi ? 1 : 0};grok=${engines.grok ? 1 : 0};cursor=${engines.cursor ? 1 : 0};opencode=${engines.opencode ? 1 : 0}`,
|
|
1385
|
+
`kimi=${engines.kimi ? 1 : 0};grok=${engines.grok ? 1 : 0};cursor=${engines.cursor ? 1 : 0};opencode=${engines.opencode ? 1 : 0};gemini=${engines.gemini ? 1 : 0}`,
|
|
1378
1386
|
);
|
|
1379
1387
|
let inspect: RunResult;
|
|
1380
1388
|
let labeledHash: string | null = null;
|