talentos 1.4.15 → 1.4.17

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.
@@ -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.
@@ -82,6 +71,10 @@ const CLAUDE_DISALLOWED = [
82
71
  // open through read_page instead (room-page.ts: resolve once, connect to that
83
72
  // address, every redirect hop checked).
84
73
  const CLAUDE_WEB_TOOLS = "WebSearch";
74
+ // A job never updates its own provider. Claude Code's updater swaps the binary
75
+ // the owner-native safety check proved, so the next owner job ran room-only
76
+ // until the check ran again.
77
+ const NO_SELF_UPDATE = { claude_code: { DISABLE_AUTOUPDATER: "1" } };
85
78
  export function childEnvironment(source = process.env, binary) {
86
79
  return {
87
80
  ...Object.fromEntries(CHILD_ENV.filter((key) => source[key] !== undefined).map((key) => [
@@ -192,13 +185,13 @@ export async function verifyCodex(configured, signal) {
192
185
  throw new Error(`Update Codex (${version}) to a version supporting isolated room turns, exec/resume flags and a local model catalog.`);
193
186
  }
194
187
  /**
195
- * Gemini CLI can run a room job when it has the flags the launch uses and the
196
- * real binary keeps a job inside its room tools (the loopback probe, which
197
- * needs no sign-in). A signed-out Gemini still passes: sign-in is a job-time
198
- * failure with its own plain reason.
188
+ * A room-only provider can run a room job when it has the flags the launch
189
+ * uses and the real binary keeps a job inside its room tools (the loopback
190
+ * probe, which needs no sign-in). A signed-out CLI still passes: sign-in is a
191
+ * job-time failure with its own plain reason.
199
192
  */
200
- export async function verifyGemini(configured, signal) {
201
- const binary = resolveProviderBinary("gemini_cli", configured);
193
+ export async function verifyRoomProvider(profile, configured, signal) {
194
+ const binary = resolveProviderBinary(profile.provider, configured);
202
195
  const execute = promisify(execFile);
203
196
  const options = {
204
197
  env: childEnvironment(process.env, binary),
@@ -208,12 +201,19 @@ export async function verifyGemini(configured, signal) {
208
201
  };
209
202
  let version = "unknown";
210
203
  try {
211
- const detected = await execute(binary, ["--version"], options);
212
- version = GEMINI_VERSION.exec(detected.stdout)?.[0] ?? "unknown";
213
- const help = await execute(binary, ["--help"], options);
204
+ const detected = await execute(binary, ["--version"], options).catch((error) => {
205
+ // Hermes prints its version, then looks for updates over the network;
206
+ // an offline computer can stall there, so what was printed counts.
207
+ if (profile.versionMayStall && error.killed && error.stdout) {
208
+ return { stdout: error.stdout };
209
+ }
210
+ throw error;
211
+ });
212
+ version = profile.versionPattern.exec(detected.stdout)?.[0] ?? "unknown";
213
+ const help = await execute(binary, profile.helpArgs, options);
214
214
  if (version !== "unknown" &&
215
- GEMINI_ROOM_FLAGS.every((flag) => help.stdout.includes(flag))) {
216
- await probeGeminiBoundary({
215
+ profile.requiredFlags.every((flag) => help.stdout.includes(flag))) {
216
+ await profile.probe({
217
217
  binary,
218
218
  env: childEnvironment(process.env, binary),
219
219
  signal,
@@ -223,12 +223,12 @@ export async function verifyGemini(configured, signal) {
223
223
  }
224
224
  }
225
225
  catch (error) {
226
- if (error instanceof GeminiBoundaryError) {
226
+ if (profile.isBoundaryError(error)) {
227
227
  throw error;
228
228
  }
229
229
  // Provider diagnostics can contain login details.
230
230
  }
231
- throw new Error(`Update Gemini CLI (${version}) to a version that supports ${GEMINI_ROOM_FLAGS.join(", ")}.`);
231
+ throw new Error(`Update ${profile.label} (${version}) to a version that supports ${profile.requiredFlags.join(", ")}.`);
232
232
  }
233
233
  /**
234
234
  * Proves this Codex's tool surface with live web search on, after the room
@@ -367,6 +367,7 @@ export function readProviderEvent(provider, value) {
367
367
  return {};
368
368
  }
369
369
  const event = value;
370
+ const room = roomProvider(provider);
370
371
  if (provider === "claude_code") {
371
372
  if (event.type === "result") {
372
373
  if (event.is_error) {
@@ -400,26 +401,8 @@ export function readProviderEvent(provider, value) {
400
401
  };
401
402
  }
402
403
  }
403
- else if (provider === "gemini_cli") {
404
- // stream-json: init, message (user and assistant chunks), tool_use,
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
- }
404
+ else if (room) {
405
+ return room.readEvent(event);
423
406
  }
424
407
  else {
425
408
  if (event.type === "thread.started" &&
@@ -451,12 +434,30 @@ export function readProviderEvent(provider, value) {
451
434
  }
452
435
  export async function runProvider(input) {
453
436
  const { config, job, workDir, sessionId, signal } = input;
454
- const { instructions, ...context } = job.packet;
455
- const prompt = JSON.stringify(config.provider === "codex" ? job.packet : context), mcpPath = join(dirname(workDir), ROOM_MCP_FILE);
437
+ // The server granted the owner's setup and wrote owner instructions, but this
438
+ // computer runs the job room-only: the model reads the room-only ones and
439
+ // why, never instructions for tools it doesn't have (#15424). Codex reads
440
+ // the whole packet, so they replace the packet's own.
441
+ const fallback = input.owner ? undefined : job.native?.roomOnlyInstructions;
442
+ const packet = fallback
443
+ ? {
444
+ ...job.packet,
445
+ instructions: [
446
+ fallback,
447
+ input.fallbackReason &&
448
+ `Why, on this computer: ${input.fallbackReason}`,
449
+ ]
450
+ .filter(Boolean)
451
+ .join("\n"),
452
+ }
453
+ : job.packet;
454
+ const { instructions, ...context } = packet;
455
+ const prompt = JSON.stringify(orderPacketForPrompt(config.provider === "codex" ? packet : context)), mcpPath = join(dirname(workDir), ROOM_MCP_FILE);
456
456
  const catalogPath = join(dirname(workDir), ROOM_CATALOG_FILE);
457
457
  const binary = resolveProviderBinary(config.provider, config.providerPath);
458
+ const room = roomProvider(config.provider);
458
459
  let command, args;
459
- // Gemini CLI reads the packet from stdin; the others take it as an argument.
460
+ // A room-only profile reads the packet from stdin; the others take it as an argument.
460
461
  let stdinText;
461
462
  let ownerLaunch;
462
463
  let stopWatching;
@@ -484,34 +485,26 @@ export async function runProvider(input) {
484
485
  command = binary;
485
486
  args = ownerLaunch.args;
486
487
  }
487
- else if (config.provider === "gemini_cli") {
488
- // Gemini CLI never runs the owner's setup (the server never grants it
489
- // either); a job that arrives as one runs nowhere.
488
+ else if (room) {
489
+ // A room-only provider never runs the owner's setup (the server never
490
+ // grants it either); a job that arrives as one runs nowhere.
490
491
  if (input.owner) {
491
- throw new Error("A Gemini CLI job is always room-only.");
492
+ throw new Error(`A ${room.label} job is always room-only.`);
492
493
  }
493
494
  command = binary;
494
495
  roomProfile = await prepareRoomProfile({
495
- directory: dirname(workDir),
496
- env: process.env,
497
- gemini: {
496
+ agent: {
498
497
  apiKey: config.apiKey,
499
498
  mcpUrl: new URL("/mcp", config.apiUrl).href,
500
499
  },
500
+ directory: dirname(workDir),
501
+ env: process.env,
502
+ instructions,
501
503
  jobId: job.jobId,
502
504
  provider: config.provider,
503
505
  });
504
- try {
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
- }
506
+ args = roomProfile.launch?.args ?? [];
513
507
  stdinText = prompt;
514
- args = geminiRoomArgs({ policyPath: roomProfile.geminiPolicyPath ?? "" });
515
508
  }
516
509
  else if (input.owner && config.provider === "codex" && input.owner.codex) {
517
510
  const watching = await input.owner.watch?.();
@@ -659,11 +652,13 @@ export async function runProvider(input) {
659
652
  PATH: [dirname(binary), input.owner.env.PATH]
660
653
  .filter(Boolean)
661
654
  .join(delimiter),
655
+ ...NO_SELF_UPDATE[config.provider],
662
656
  }
663
657
  : {
664
658
  ...childEnvironment(process.env, binary),
665
659
  // Login variables from the owner's settings; never written to a file.
666
660
  ...roomProfile?.env,
661
+ ...NO_SELF_UPDATE[config.provider],
667
662
  // The owner's memory stays out; the job's own directory is fresh.
668
663
  ...(config.provider === "claude_code"
669
664
  ? { CLAUDE_CODE_DISABLE_AUTO_MEMORY: "1" }
@@ -43,10 +43,13 @@ export const ROOM_TOOLS = [
43
43
  "commit_upload",
44
44
  "post_message",
45
45
  "ask_owner",
46
+ "delete_own_message",
46
47
  "edit_own_message",
48
+ "react_to_message",
47
49
  "post_to_thread",
48
50
  "reply_to_comment",
49
51
  "start_thread",
52
+ "rename_thread",
50
53
  "share_link",
51
54
  "room_default_set",
52
55
  "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
- const child = spawn(input.binary, geminiRoomArgs({ policyPath }), {
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
- stdio: ["pipe", "pipe", "ignore"],
226
- });
227
- // A Gemini that exits before reading stdin must fail the probe, not crash the
228
- // CLI with an unhandled EPIPE.
229
- child.stdin?.on("error", () => undefined);
230
- // Headless Gemini expands @file references in what it is given; the packet
231
- // holds room text anyone can write, so a reference to a file outside the
232
- // job's directory must read nothing (`secretLeaked` judges it).
233
- child.stdin?.end(JSON.stringify({ probe: true, text: `look at @${secretPath}` }));
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
- catch {
251
- // Not an event line.
252
- }
253
- }
254
- await new Promise((resolve) => {
255
- if (child.exitCode === null) {
256
- child.once("close", () => resolve());
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. Cached per binary and
292
- * version; a failure is cached too, so a bad Gemini is not retried on every job.
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
- const key = `${input.binary}@${input.version}`;
296
- let proof = proofs.get(key);
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
- proofs.set(key, proof);
306
- }
307
- return proof;
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
+ };