talentos 1.4.15 → 1.4.16
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/agent/adapters.js +37 -65
- package/dist/agent/codex-policy.js +2 -0
- package/dist/agent/gemini-probe.js +33 -122
- package/dist/agent/gemini-room.js +92 -0
- package/dist/agent/hermes-login.js +166 -0
- package/dist/agent/hermes-policy.js +179 -0
- package/dist/agent/hermes-probe.js +255 -0
- package/dist/agent/hermes-room.js +99 -0
- package/dist/agent/native/config.js +27 -13
- package/dist/agent/native/gate.js +7 -4
- package/dist/agent/native/projects.js +38 -1
- package/dist/agent/packet-order.js +26 -0
- package/dist/agent/provider-login.js +4 -3
- package/dist/agent/room-probe.js +129 -0
- package/dist/agent/room-profile.js +21 -45
- package/dist/agent/room-provider.js +7 -0
- package/dist/agent/room-providers.js +11 -0
- package/dist/agent-config.js +2 -1
- package/dist/agent-http.js +8 -6
- package/dist/agent-link.js +3 -2
- package/dist/commands/agent-serve.js +6 -6
- package/dist/provider-binary.js +8 -1
- package/package.json +1 -1
package/dist/agent/adapters.js
CHANGED
|
@@ -12,14 +12,14 @@ import { providerPathEnv, resolveProviderBinary } from "../provider-binary.js";
|
|
|
12
12
|
import { codexImagesProven, probeCodexImages } from "./codex-image-probe.js";
|
|
13
13
|
import { codexRoomArgs, ROOM_DIRECT_TOOLS, ROOM_PROXY_ONLY_TOOLS, } from "./codex-policy.js";
|
|
14
14
|
import { binaryIdentity, CodexBoundaryError, CodexProbeInterrupted, codexWebProven, probeCodexBoundary, } from "./codex-probe.js";
|
|
15
|
-
import { geminiRoomArgs } from "./gemini-policy.js";
|
|
16
|
-
import { GeminiBoundaryError, probeGeminiBoundary } from "./gemini-probe.js";
|
|
17
15
|
import { prepareCodexOwnerLaunch } from "./native/codex-launch.js";
|
|
18
16
|
import { prepareOwnerLaunch } from "./native/launch.js";
|
|
19
17
|
import { readReceipts } from "./native/receipts.js";
|
|
18
|
+
import { orderPacketForPrompt } from "./packet-order.js";
|
|
20
19
|
import { classifyProviderFailure, matchFailureText, ProviderFailureError, } from "./provider-failure.js";
|
|
21
20
|
import { READ_PAGE_TOOL, ROOM_WEB_MCP_ENTRY, ROOM_WEB_SERVER, } from "./room-page.js";
|
|
22
21
|
import { prepareRoomProfile, ROOM_CATALOG_FILE, ROOM_MCP_FILE, } from "./room-profile.js";
|
|
22
|
+
import { roomProvider } from "./room-providers.js";
|
|
23
23
|
const CHILD_ENV = [
|
|
24
24
|
"HOME",
|
|
25
25
|
"PATH",
|
|
@@ -38,17 +38,6 @@ const CHILD_ENV = [
|
|
|
38
38
|
];
|
|
39
39
|
const CLAUDE_VERSION = /^\d+\.\d+\.\d+/u;
|
|
40
40
|
const CODEX_VERSION = /\b\d+\.\d+\.\d+\b/u;
|
|
41
|
-
const GEMINI_VERSION = /\b\d+\.\d+\.\d+\b/u;
|
|
42
|
-
// What the room launch needs from this Gemini CLI: its own policy files, the
|
|
43
|
-
// workspace-trust skip, headless streaming events, an approval mode and an MCP
|
|
44
|
-
// server allowlist. A Gemini without them cannot hold the room boundary.
|
|
45
|
-
const GEMINI_ROOM_FLAGS = [
|
|
46
|
-
"--policy",
|
|
47
|
-
"--skip-trust",
|
|
48
|
-
"--output-format",
|
|
49
|
-
"--approval-mode",
|
|
50
|
-
"--allowed-mcp-server-names",
|
|
51
|
-
];
|
|
52
41
|
const DONT_ASK = /\bdontAsk\b/u;
|
|
53
42
|
// What the room line says while a job uses web. Neither names a page or a
|
|
54
43
|
// query, and neither is a private tool, so an owner job shows them too.
|
|
@@ -192,13 +181,13 @@ export async function verifyCodex(configured, signal) {
|
|
|
192
181
|
throw new Error(`Update Codex (${version}) to a version supporting isolated room turns, exec/resume flags and a local model catalog.`);
|
|
193
182
|
}
|
|
194
183
|
/**
|
|
195
|
-
*
|
|
196
|
-
* real binary keeps a job inside its room tools (the loopback
|
|
197
|
-
* needs no sign-in). A signed-out
|
|
198
|
-
* failure with its own plain reason.
|
|
184
|
+
* A room-only provider can run a room job when it has the flags the launch
|
|
185
|
+
* uses and the real binary keeps a job inside its room tools (the loopback
|
|
186
|
+
* probe, which needs no sign-in). A signed-out CLI still passes: sign-in is a
|
|
187
|
+
* job-time failure with its own plain reason.
|
|
199
188
|
*/
|
|
200
|
-
export async function
|
|
201
|
-
const binary = resolveProviderBinary(
|
|
189
|
+
export async function verifyRoomProvider(profile, configured, signal) {
|
|
190
|
+
const binary = resolveProviderBinary(profile.provider, configured);
|
|
202
191
|
const execute = promisify(execFile);
|
|
203
192
|
const options = {
|
|
204
193
|
env: childEnvironment(process.env, binary),
|
|
@@ -208,12 +197,19 @@ export async function verifyGemini(configured, signal) {
|
|
|
208
197
|
};
|
|
209
198
|
let version = "unknown";
|
|
210
199
|
try {
|
|
211
|
-
const detected = await execute(binary, ["--version"], options)
|
|
212
|
-
|
|
213
|
-
|
|
200
|
+
const detected = await execute(binary, ["--version"], options).catch((error) => {
|
|
201
|
+
// Hermes prints its version, then looks for updates over the network;
|
|
202
|
+
// an offline computer can stall there, so what was printed counts.
|
|
203
|
+
if (profile.versionMayStall && error.killed && error.stdout) {
|
|
204
|
+
return { stdout: error.stdout };
|
|
205
|
+
}
|
|
206
|
+
throw error;
|
|
207
|
+
});
|
|
208
|
+
version = profile.versionPattern.exec(detected.stdout)?.[0] ?? "unknown";
|
|
209
|
+
const help = await execute(binary, profile.helpArgs, options);
|
|
214
210
|
if (version !== "unknown" &&
|
|
215
|
-
|
|
216
|
-
await
|
|
211
|
+
profile.requiredFlags.every((flag) => help.stdout.includes(flag))) {
|
|
212
|
+
await profile.probe({
|
|
217
213
|
binary,
|
|
218
214
|
env: childEnvironment(process.env, binary),
|
|
219
215
|
signal,
|
|
@@ -223,12 +219,12 @@ export async function verifyGemini(configured, signal) {
|
|
|
223
219
|
}
|
|
224
220
|
}
|
|
225
221
|
catch (error) {
|
|
226
|
-
if (error
|
|
222
|
+
if (profile.isBoundaryError(error)) {
|
|
227
223
|
throw error;
|
|
228
224
|
}
|
|
229
225
|
// Provider diagnostics can contain login details.
|
|
230
226
|
}
|
|
231
|
-
throw new Error(`Update
|
|
227
|
+
throw new Error(`Update ${profile.label} (${version}) to a version that supports ${profile.requiredFlags.join(", ")}.`);
|
|
232
228
|
}
|
|
233
229
|
/**
|
|
234
230
|
* Proves this Codex's tool surface with live web search on, after the room
|
|
@@ -367,6 +363,7 @@ export function readProviderEvent(provider, value) {
|
|
|
367
363
|
return {};
|
|
368
364
|
}
|
|
369
365
|
const event = value;
|
|
366
|
+
const room = roomProvider(provider);
|
|
370
367
|
if (provider === "claude_code") {
|
|
371
368
|
if (event.type === "result") {
|
|
372
369
|
if (event.is_error) {
|
|
@@ -400,26 +397,8 @@ export function readProviderEvent(provider, value) {
|
|
|
400
397
|
};
|
|
401
398
|
}
|
|
402
399
|
}
|
|
403
|
-
else if (
|
|
404
|
-
|
|
405
|
-
// tool_result, error (a warning) and result (status and stats).
|
|
406
|
-
if (event.type === "message" && event.role === "assistant") {
|
|
407
|
-
return typeof event.content === "string"
|
|
408
|
-
? { textDelta: event.content }
|
|
409
|
-
: {};
|
|
410
|
-
}
|
|
411
|
-
if (event.type === "tool_use") {
|
|
412
|
-
return { status: "Using room tools…", textReset: true };
|
|
413
|
-
}
|
|
414
|
-
if (event.type === "result" && event.status === "error") {
|
|
415
|
-
const error = event.error;
|
|
416
|
-
return {
|
|
417
|
-
failed: true,
|
|
418
|
-
failure: typeof error?.message === "string"
|
|
419
|
-
? matchFailureText(error.message)
|
|
420
|
-
: undefined,
|
|
421
|
-
};
|
|
422
|
-
}
|
|
400
|
+
else if (room) {
|
|
401
|
+
return room.readEvent(event);
|
|
423
402
|
}
|
|
424
403
|
else {
|
|
425
404
|
if (event.type === "thread.started" &&
|
|
@@ -452,11 +431,12 @@ export function readProviderEvent(provider, value) {
|
|
|
452
431
|
export async function runProvider(input) {
|
|
453
432
|
const { config, job, workDir, sessionId, signal } = input;
|
|
454
433
|
const { instructions, ...context } = job.packet;
|
|
455
|
-
const prompt = JSON.stringify(config.provider === "codex" ? job.packet : context), mcpPath = join(dirname(workDir), ROOM_MCP_FILE);
|
|
434
|
+
const prompt = JSON.stringify(orderPacketForPrompt(config.provider === "codex" ? job.packet : context)), mcpPath = join(dirname(workDir), ROOM_MCP_FILE);
|
|
456
435
|
const catalogPath = join(dirname(workDir), ROOM_CATALOG_FILE);
|
|
457
436
|
const binary = resolveProviderBinary(config.provider, config.providerPath);
|
|
437
|
+
const room = roomProvider(config.provider);
|
|
458
438
|
let command, args;
|
|
459
|
-
//
|
|
439
|
+
// A room-only profile reads the packet from stdin; the others take it as an argument.
|
|
460
440
|
let stdinText;
|
|
461
441
|
let ownerLaunch;
|
|
462
442
|
let stopWatching;
|
|
@@ -484,34 +464,26 @@ export async function runProvider(input) {
|
|
|
484
464
|
command = binary;
|
|
485
465
|
args = ownerLaunch.args;
|
|
486
466
|
}
|
|
487
|
-
else if (
|
|
488
|
-
//
|
|
489
|
-
// either); a job that arrives as one runs nowhere.
|
|
467
|
+
else if (room) {
|
|
468
|
+
// A room-only provider never runs the owner's setup (the server never
|
|
469
|
+
// grants it either); a job that arrives as one runs nowhere.
|
|
490
470
|
if (input.owner) {
|
|
491
|
-
throw new Error(
|
|
471
|
+
throw new Error(`A ${room.label} job is always room-only.`);
|
|
492
472
|
}
|
|
493
473
|
command = binary;
|
|
494
474
|
roomProfile = await prepareRoomProfile({
|
|
495
|
-
|
|
496
|
-
env: process.env,
|
|
497
|
-
gemini: {
|
|
475
|
+
agent: {
|
|
498
476
|
apiKey: config.apiKey,
|
|
499
477
|
mcpUrl: new URL("/mcp", config.apiUrl).href,
|
|
500
478
|
},
|
|
479
|
+
directory: dirname(workDir),
|
|
480
|
+
env: process.env,
|
|
481
|
+
instructions,
|
|
501
482
|
jobId: job.jobId,
|
|
502
483
|
provider: config.provider,
|
|
503
484
|
});
|
|
504
|
-
|
|
505
|
-
// The room playbook is the job's own GEMINI.md: its directory is empty and
|
|
506
|
-
// nothing above it is read.
|
|
507
|
-
await writePrivateFile(join(roomProfile.cwd, "GEMINI.md"), instructions);
|
|
508
|
-
}
|
|
509
|
-
catch (error) {
|
|
510
|
-
await roomProfile.cleanup();
|
|
511
|
-
throw error;
|
|
512
|
-
}
|
|
485
|
+
args = roomProfile.launch?.args ?? [];
|
|
513
486
|
stdinText = prompt;
|
|
514
|
-
args = geminiRoomArgs({ policyPath: roomProfile.geminiPolicyPath ?? "" });
|
|
515
487
|
}
|
|
516
488
|
else if (input.owner && config.provider === "codex" && input.owner.codex) {
|
|
517
489
|
const watching = await input.owner.watch?.();
|
|
@@ -44,9 +44,11 @@ export const ROOM_TOOLS = [
|
|
|
44
44
|
"post_message",
|
|
45
45
|
"ask_owner",
|
|
46
46
|
"edit_own_message",
|
|
47
|
+
"react_to_message",
|
|
47
48
|
"post_to_thread",
|
|
48
49
|
"reply_to_comment",
|
|
49
50
|
"start_thread",
|
|
51
|
+
"rename_thread",
|
|
50
52
|
"share_link",
|
|
51
53
|
"room_default_set",
|
|
52
54
|
"room_default_remove",
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
1
|
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
2
|
import { createServer } from "node:http";
|
|
4
3
|
import { tmpdir } from "node:os";
|
|
5
4
|
import { join } from "node:path";
|
|
6
|
-
import { createInterface } from "node:readline";
|
|
7
5
|
import { writePrivateFile } from "../agent-config.js";
|
|
8
6
|
import { ProviderBinaryError } from "../provider-binary.js";
|
|
9
7
|
import { geminiRoomArgs, geminiRoomPolicy, geminiRoomSettings, geminiToolName, } from "./gemini-policy.js";
|
|
8
|
+
import { cachedProof, closeServer, fakeRoom, listen, ROOM_TOOL, readBody, runProbeChild, SECRET, } from "./room-probe.js";
|
|
10
9
|
// Proves, against the real binary and with no login, that this Gemini CLI keeps
|
|
11
10
|
// a room job inside its room tools. It runs the exact launch a job uses (same
|
|
12
11
|
// policy, settings and flags) in a throwaway home, pointed at a loopback stand-in
|
|
@@ -17,10 +16,6 @@ import { geminiRoomArgs, geminiRoomPolicy, geminiRoomSettings, geminiToolName, }
|
|
|
17
16
|
// only the offer), and an @file reference in its input is not expanded into the
|
|
18
17
|
// request. A Gemini that fails it serves no room job. The result is
|
|
19
18
|
// cached for the binary and its version.
|
|
20
|
-
const PROBE_MS = 45_000;
|
|
21
|
-
const MAX_BYTES = 2_000_000;
|
|
22
|
-
const SECRET = "probe-secret-must-never-reach-the-model";
|
|
23
|
-
const ROOM_TOOL = "whoami";
|
|
24
19
|
export class GeminiBoundaryError extends ProviderBinaryError {
|
|
25
20
|
constructor(version) {
|
|
26
21
|
super(`Gemini CLI ${version} cannot safely run room jobs. Update Gemini CLI, then run talentos agent repair. If this persists, report this version to TalentOS support.`);
|
|
@@ -37,18 +32,6 @@ function toolNames(body) {
|
|
|
37
32
|
.filter((name) => typeof name === "string")
|
|
38
33
|
: []);
|
|
39
34
|
}
|
|
40
|
-
async function readBody(request) {
|
|
41
|
-
let size = 0;
|
|
42
|
-
const chunks = [];
|
|
43
|
-
for await (const chunk of request) {
|
|
44
|
-
size += chunk.length;
|
|
45
|
-
if (size > MAX_BYTES) {
|
|
46
|
-
throw new Error("Probe request exceeded its limit.");
|
|
47
|
-
}
|
|
48
|
-
chunks.push(chunk);
|
|
49
|
-
}
|
|
50
|
-
return Buffer.concat(chunks).toString("utf8");
|
|
51
|
-
}
|
|
52
35
|
/**
|
|
53
36
|
* The Gemini API stand-in: first answers with a call to the room tool and one
|
|
54
37
|
* to a file tool, then text.
|
|
@@ -141,64 +124,13 @@ function fakeApi(seen, secretPath) {
|
|
|
141
124
|
}
|
|
142
125
|
});
|
|
143
126
|
}
|
|
144
|
-
/** The room endpoint stand-in: one room tool and one tool that is not a room tool. */
|
|
145
|
-
function fakeRoom(seen) {
|
|
146
|
-
return createServer(async (request, response) => {
|
|
147
|
-
const body = await readBody(request).catch(() => "");
|
|
148
|
-
let message = {};
|
|
149
|
-
try {
|
|
150
|
-
message = JSON.parse(body);
|
|
151
|
-
}
|
|
152
|
-
catch {
|
|
153
|
-
// A GET or an empty body: nothing to answer.
|
|
154
|
-
}
|
|
155
|
-
const reply = (result) => {
|
|
156
|
-
response.setHeader("content-type", "application/json");
|
|
157
|
-
response.end(JSON.stringify({ id: message.id, jsonrpc: "2.0", result }));
|
|
158
|
-
};
|
|
159
|
-
const empty = { properties: {}, type: "object" };
|
|
160
|
-
if (message.method === "initialize") {
|
|
161
|
-
reply({
|
|
162
|
-
capabilities: { tools: {} },
|
|
163
|
-
protocolVersion: "2025-03-26",
|
|
164
|
-
serverInfo: { name: "probe", version: "1" },
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
else if (message.method === "tools/list") {
|
|
168
|
-
reply({
|
|
169
|
-
tools: [
|
|
170
|
-
{ description: "who", inputSchema: empty, name: ROOM_TOOL },
|
|
171
|
-
{ description: "no", inputSchema: empty, name: "not_a_room_tool" },
|
|
172
|
-
],
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
else if (message.method === "tools/call") {
|
|
176
|
-
seen.roomCalls.push(String(message.params?.name));
|
|
177
|
-
reply({ content: [{ text: "ok", type: "text" }] });
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
response.statusCode = 202;
|
|
181
|
-
response.end();
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
function listen(server) {
|
|
186
|
-
return new Promise((resolve, reject) => {
|
|
187
|
-
server.once("error", reject);
|
|
188
|
-
server.listen(0, "127.0.0.1", () => resolve(server.address().port));
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
const closeServer = (server) => new Promise((resolve) => {
|
|
192
|
-
server.closeAllConnections?.();
|
|
193
|
-
server.close(() => resolve());
|
|
194
|
-
});
|
|
195
127
|
/** Runs the probe and returns what it saw; `probeGeminiBoundary` judges it. */
|
|
196
128
|
export async function runGeminiProbe(input) {
|
|
197
129
|
const dir = await mkdtemp(join(tmpdir(), "talentos-gemini-probe-"));
|
|
198
130
|
const seen = { requests: [], roomCalls: [] };
|
|
199
131
|
const secretPath = join(dir, "secret.txt");
|
|
200
132
|
const api = fakeApi(seen, secretPath);
|
|
201
|
-
const room = fakeRoom(seen);
|
|
133
|
+
const room = fakeRoom(seen.roomCalls);
|
|
202
134
|
try {
|
|
203
135
|
await writeFile(secretPath, SECRET, { mode: 0o600 });
|
|
204
136
|
const [apiPort, roomPort] = await Promise.all([listen(api), listen(room)]);
|
|
@@ -214,7 +146,10 @@ export async function runGeminiProbe(input) {
|
|
|
214
146
|
authType: "gemini-api-key",
|
|
215
147
|
mcpUrl: `http://127.0.0.1:${roomPort}/mcp`,
|
|
216
148
|
}));
|
|
217
|
-
|
|
149
|
+
let readRefused = false;
|
|
150
|
+
await runProbeChild({
|
|
151
|
+
args: geminiRoomArgs({ policyPath }),
|
|
152
|
+
binary: input.binary,
|
|
218
153
|
cwd: work,
|
|
219
154
|
env: {
|
|
220
155
|
...input.env,
|
|
@@ -222,44 +157,26 @@ export async function runGeminiProbe(input) {
|
|
|
222
157
|
GEMINI_CLI_HOME: home,
|
|
223
158
|
GOOGLE_GEMINI_BASE_URL: `http://127.0.0.1:${apiPort}`,
|
|
224
159
|
},
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const timer = setTimeout(() => child.kill("SIGKILL"), PROBE_MS);
|
|
235
|
-
input.signal?.addEventListener("abort", () => child.kill("SIGKILL"), {
|
|
236
|
-
once: true,
|
|
237
|
-
});
|
|
238
|
-
let readRefused = false;
|
|
239
|
-
const lines = createInterface({ input: child.stdout });
|
|
240
|
-
for await (const line of lines) {
|
|
241
|
-
try {
|
|
242
|
-
const event = JSON.parse(line);
|
|
243
|
-
if (event.type === "tool_result" &&
|
|
244
|
-
String(event.tool_id).startsWith("read_file") &&
|
|
245
|
-
event.status === "error" &&
|
|
246
|
-
event.error?.type === "tool_not_registered") {
|
|
247
|
-
readRefused = true;
|
|
160
|
+
onLine: (line) => {
|
|
161
|
+
try {
|
|
162
|
+
const event = JSON.parse(line);
|
|
163
|
+
if (event.type === "tool_result" &&
|
|
164
|
+
String(event.tool_id).startsWith("read_file") &&
|
|
165
|
+
event.status === "error" &&
|
|
166
|
+
event.error?.type === "tool_not_registered") {
|
|
167
|
+
readRefused = true;
|
|
168
|
+
}
|
|
248
169
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
else {
|
|
259
|
-
resolve();
|
|
260
|
-
}
|
|
170
|
+
catch {
|
|
171
|
+
// Not an event line.
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
signal: input.signal,
|
|
175
|
+
// Headless Gemini expands @file references in what it is given; the
|
|
176
|
+
// packet holds room text anyone can write, so a reference to a file
|
|
177
|
+
// outside the job's directory must read nothing (`secretLeaked` judges it).
|
|
178
|
+
stdin: JSON.stringify({ probe: true, text: `look at @${secretPath}` }),
|
|
261
179
|
});
|
|
262
|
-
clearTimeout(timer);
|
|
263
180
|
return {
|
|
264
181
|
advertised: [...new Set(seen.requests.flatMap((r) => r.tools))],
|
|
265
182
|
readRefused,
|
|
@@ -285,24 +202,18 @@ export function geminiBoundaryHolds(result) {
|
|
|
285
202
|
result.readRefused &&
|
|
286
203
|
!result.secretLeaked);
|
|
287
204
|
}
|
|
288
|
-
const proofs = new Map();
|
|
289
205
|
/**
|
|
290
206
|
* Throws GeminiBoundaryError unless this binary offered the model only the room
|
|
291
|
-
* tool on every request, ran it, and refused the file tool it was asked to run.
|
|
292
|
-
* version; a failure is cached too, so a bad Gemini is not
|
|
207
|
+
* tool on every request, ran it, and refused the file tool it was asked to run.
|
|
208
|
+
* Cached per binary and version; a failure is cached too, so a bad Gemini is not
|
|
209
|
+
* retried on every job.
|
|
293
210
|
*/
|
|
294
211
|
export function probeGeminiBoundary(input) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
if (!proof) {
|
|
298
|
-
proof = runGeminiProbe(input).then((result) => {
|
|
299
|
-
if (!geminiBoundaryHolds(result)) {
|
|
300
|
-
throw new GeminiBoundaryError(input.version);
|
|
301
|
-
}
|
|
302
|
-
}, () => {
|
|
212
|
+
return cachedProof(`gemini:${input.binary}@${input.version}`, () => runGeminiProbe(input).then((result) => {
|
|
213
|
+
if (!geminiBoundaryHolds(result)) {
|
|
303
214
|
throw new GeminiBoundaryError(input.version);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
215
|
+
}
|
|
216
|
+
}, () => {
|
|
217
|
+
throw new GeminiBoundaryError(input.version);
|
|
218
|
+
}));
|
|
308
219
|
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { mkdir, symlink } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { writePrivateFile } from "../agent-config.js";
|
|
4
|
+
import { GEMINI_CREDENTIAL_FILES, geminiSignedIn, readGeminiLogin, } from "./gemini-login.js";
|
|
5
|
+
import { geminiRoomArgs, geminiRoomPolicy, geminiRoomSettings, } from "./gemini-policy.js";
|
|
6
|
+
import { GeminiBoundaryError, probeGeminiBoundary } from "./gemini-probe.js";
|
|
7
|
+
import { matchFailureText } from "./provider-failure.js";
|
|
8
|
+
import { RoomIsolationError, } from "./room-provider.js";
|
|
9
|
+
// What the room launch needs from this Gemini CLI: its own policy files, the
|
|
10
|
+
// workspace-trust skip, headless streaming events, an approval mode and an MCP
|
|
11
|
+
// server allowlist. A Gemini without them cannot hold the room boundary.
|
|
12
|
+
const GEMINI_ROOM_FLAGS = [
|
|
13
|
+
"--policy",
|
|
14
|
+
"--skip-trust",
|
|
15
|
+
"--output-format",
|
|
16
|
+
"--approval-mode",
|
|
17
|
+
"--allowed-mcp-server-names",
|
|
18
|
+
];
|
|
19
|
+
// stream-json: init, message (user and assistant chunks), tool_use,
|
|
20
|
+
// tool_result, error (a warning) and result (status and stats).
|
|
21
|
+
function readGeminiEvent(event) {
|
|
22
|
+
if (event.type === "message" && event.role === "assistant") {
|
|
23
|
+
return typeof event.content === "string"
|
|
24
|
+
? { textDelta: event.content }
|
|
25
|
+
: {};
|
|
26
|
+
}
|
|
27
|
+
if (event.type === "tool_use") {
|
|
28
|
+
return { status: "Using room tools…", textReset: true };
|
|
29
|
+
}
|
|
30
|
+
if (event.type === "result" && event.status === "error") {
|
|
31
|
+
const error = event.error;
|
|
32
|
+
return {
|
|
33
|
+
failed: true,
|
|
34
|
+
failure: typeof error?.message === "string"
|
|
35
|
+
? matchFailureText(error.message)
|
|
36
|
+
: undefined,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
export const geminiRoomProfile = {
|
|
42
|
+
helpArgs: ["--help"],
|
|
43
|
+
isBoundaryError: (error) => error instanceof GeminiBoundaryError,
|
|
44
|
+
label: "Gemini CLI",
|
|
45
|
+
async prepare(input) {
|
|
46
|
+
const login = readGeminiLogin(input.env);
|
|
47
|
+
// Gemini CLI reads context files from the working directory upward to its
|
|
48
|
+
// home, so its directory sits inside the job's own home: nothing above it is
|
|
49
|
+
// ever read.
|
|
50
|
+
const home = join(input.jobDir, "home");
|
|
51
|
+
const cwd = join(home, "work");
|
|
52
|
+
await mkdir(cwd, { mode: 0o700, recursive: true });
|
|
53
|
+
const dotGemini = join(home, ".gemini");
|
|
54
|
+
await mkdir(dotGemini, { mode: 0o700, recursive: true });
|
|
55
|
+
const policyPath = join(dotGemini, "room-policy.toml");
|
|
56
|
+
await writePrivateFile(policyPath, geminiRoomPolicy());
|
|
57
|
+
await writePrivateFile(join(dotGemini, "settings.json"), geminiRoomSettings({
|
|
58
|
+
apiKey: input.agent.apiKey,
|
|
59
|
+
// An OAuth sign-in with no method named in settings is still OAuth.
|
|
60
|
+
authType: login.authType ??
|
|
61
|
+
(login.files.includes("oauth_creds.json")
|
|
62
|
+
? "oauth-personal"
|
|
63
|
+
: undefined),
|
|
64
|
+
mcpUrl: input.agent.mcpUrl,
|
|
65
|
+
}));
|
|
66
|
+
// Links, never copies: Gemini refreshes the token in place.
|
|
67
|
+
for (const name of GEMINI_CREDENTIAL_FILES) {
|
|
68
|
+
if (login.files.includes(name)) {
|
|
69
|
+
await symlink(join(login.dir, name), join(dotGemini, name)).catch(() => {
|
|
70
|
+
throw new RoomIsolationError("Gemini CLI");
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// The room playbook is the job's own GEMINI.md: its directory is empty and
|
|
75
|
+
// nothing above it is read.
|
|
76
|
+
await writePrivateFile(join(cwd, "GEMINI.md"), input.instructions);
|
|
77
|
+
return {
|
|
78
|
+
args: geminiRoomArgs({ policyPath }),
|
|
79
|
+
cwd,
|
|
80
|
+
env: { ...login.env, GEMINI_CLI_HOME: home },
|
|
81
|
+
home,
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
probe: probeGeminiBoundary,
|
|
85
|
+
provider: "gemini_cli",
|
|
86
|
+
readEvent: readGeminiEvent,
|
|
87
|
+
requiredFlags: GEMINI_ROOM_FLAGS,
|
|
88
|
+
signInProblem: (env) => geminiSignedIn(readGeminiLogin(env))
|
|
89
|
+
? undefined
|
|
90
|
+
: "Sign in through the official gemini CLI before linking: start gemini once and choose how to sign in.",
|
|
91
|
+
versionPattern: /\b\d+\.\d+\.\d+\b/u,
|
|
92
|
+
};
|