talentos 1.4.10 → 1.4.12
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/README.md +3 -3
- package/dist/agent/adapters.js +207 -14
- package/dist/agent/codex-policy.js +22 -0
- package/dist/agent/codex-probe.js +114 -30
- package/dist/agent/gemini-login.js +74 -0
- package/dist/agent/gemini-policy.js +91 -0
- package/dist/agent/gemini-probe.js +308 -0
- package/dist/agent/mcp-entry.js +22 -9
- package/dist/agent/native/approvals.js +15 -11
- package/dist/agent/native/codex-launch.js +3 -0
- package/dist/agent/native/config.js +4 -2
- package/dist/agent/native/gate.js +160 -8
- package/dist/agent/native/hook-entry.js +33 -8
- package/dist/agent/native/launch.js +3 -0
- package/dist/agent/native/native-issue.js +3 -3
- package/dist/agent/native/policy.js +62 -14
- package/dist/agent/native/probe.js +13 -1
- package/dist/agent/native/touch.js +33 -1
- package/dist/agent/node-floor.js +140 -0
- package/dist/agent/provider-failure.js +2 -2
- package/dist/agent/provider-login.js +134 -0
- package/dist/agent/room-profile.js +41 -4
- package/dist/agent/serve.js +75 -9
- package/dist/agent-config.js +6 -1
- package/dist/agent-http.js +57 -0
- package/dist/agent-link.js +4 -2
- package/dist/agent-session.js +137 -0
- package/dist/args.js +1 -0
- package/dist/client.js +11 -2
- package/dist/commands/agent-native.js +0 -3
- package/dist/commands/agent-serve.js +7 -2
- package/dist/commands/agent-session.js +160 -0
- package/dist/commands/agent.js +37 -3
- package/dist/commands/init.js +2 -2
- package/dist/commands/login.js +2 -2
- package/dist/gateway-install.js +50 -11
- package/dist/index.js +13 -4
- package/dist/install.js +39 -14
- package/dist/mcp-proxy.js +30 -2
- package/dist/provider-binary.js +12 -2
- package/package.json +2 -2
|
@@ -35,11 +35,54 @@ const RESOURCE_HELPERS = [
|
|
|
35
35
|
"list_mcp_resource_templates", // Sole tools-only MCP server: no templates.
|
|
36
36
|
"read_mcp_resource", // MCP RPC only; the proxy has no resources/read handler.
|
|
37
37
|
];
|
|
38
|
+
// The newest Codex this proof was proven against (codex-boundary.test.ts). One at
|
|
39
|
+
// or past it that fails is a build TalentOS has not learned yet; updating Codex
|
|
40
|
+
// cannot fix that, and a current Codex may have nothing newer to update to.
|
|
41
|
+
const PROVEN_CODEX = [0, 162, 1];
|
|
42
|
+
const RELEASE = /(\d+)\.(\d+)\.(\d+)/u;
|
|
43
|
+
const WHITESPACE = /\s+/gu;
|
|
44
|
+
function provenOrNewer(version) {
|
|
45
|
+
const parts = RELEASE.exec(version)?.slice(1).map(Number);
|
|
46
|
+
if (!parts) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
for (const [index, proven] of PROVEN_CODEX.entries()) {
|
|
50
|
+
const part = parts[index] ?? 0;
|
|
51
|
+
if (part !== proven) {
|
|
52
|
+
return part > proven;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
38
57
|
export class CodexBoundaryError extends ProviderBinaryError {
|
|
39
|
-
|
|
40
|
-
|
|
58
|
+
/** The check that failed, for the gateway log; no login or owner data. */
|
|
59
|
+
check;
|
|
60
|
+
constructor(version, check) {
|
|
61
|
+
const why = check ? ` (check failed: ${check})` : "";
|
|
62
|
+
super(provenOrNewer(version)
|
|
63
|
+
? `Codex ${version} cannot safely run room jobs${why}. TalentOS doesn't support this Codex version yet, so it stays off until it does; there is nothing to update on this computer. Please report this version to TalentOS support.`
|
|
64
|
+
: `Codex ${version} cannot safely run room jobs${why}. Update Codex, then run talentos agent repair. If this persists, report this version to TalentOS support.`);
|
|
65
|
+
this.check = check;
|
|
41
66
|
}
|
|
42
67
|
}
|
|
68
|
+
/** One line of a failure, bounded: it goes to a log and carries no owner data. */
|
|
69
|
+
const oneLine = (text, max = 300) => text.replace(WHITESPACE, " ").trim().slice(0, max);
|
|
70
|
+
/**
|
|
71
|
+
* The check ran out of road (a timeout, a shutdown, a full disk, a child that
|
|
72
|
+
* died, the file replaced mid-check), so it says nothing about this Codex. The
|
|
73
|
+
* CLI exits plainly, not with the refusal's 78, and the service manager starts
|
|
74
|
+
* it again (a minute apart), which checks again.
|
|
75
|
+
*/
|
|
76
|
+
export class CodexProbeInterrupted extends Error {
|
|
77
|
+
check;
|
|
78
|
+
constructor(version, check) {
|
|
79
|
+
super(`Codex ${version} could not be checked just now (${check}). TalentOS checks again by itself.`);
|
|
80
|
+
this.check = check;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** What Codex did or offered differed from the room boundary: a verdict, not a mishap. */
|
|
84
|
+
class BoundaryMismatch extends Error {
|
|
85
|
+
}
|
|
43
86
|
function record(value) {
|
|
44
87
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
45
88
|
throw new Error("Invalid tool envelope");
|
|
@@ -65,7 +108,7 @@ export function codexAdvertisedTools(value) {
|
|
|
65
108
|
tool.function !== undefined ||
|
|
66
109
|
tool.namespace !== undefined ||
|
|
67
110
|
!["functions", "mcp__talentos"].includes(String(tool.name))) {
|
|
68
|
-
throw new Error(
|
|
111
|
+
throw new Error(`unexpected tool namespace "${oneLine(String(tool.name), 60)}"`);
|
|
69
112
|
}
|
|
70
113
|
inspect(tool.tools, String(tool.name));
|
|
71
114
|
}
|
|
@@ -76,7 +119,7 @@ export function codexAdvertisedTools(value) {
|
|
|
76
119
|
(namespace &&
|
|
77
120
|
tool.namespace !== undefined &&
|
|
78
121
|
tool.namespace !== namespace)) {
|
|
79
|
-
throw new Error(
|
|
122
|
+
throw new Error(`conflicting tool envelope for "${oneLine(String(tool.name), 60)}"`);
|
|
80
123
|
}
|
|
81
124
|
const ns = namespace ||
|
|
82
125
|
(typeof tool.namespace === "string" ? tool.namespace : "");
|
|
@@ -87,12 +130,12 @@ export function codexAdvertisedTools(value) {
|
|
|
87
130
|
if (!(allowed && tool.parameters) ||
|
|
88
131
|
typeof tool.parameters !== "object" ||
|
|
89
132
|
Array.isArray(tool.parameters)) {
|
|
90
|
-
throw new Error(
|
|
133
|
+
throw new Error(`unexpected tool "${oneLine(`${ns}.${name}`, 80)}"`);
|
|
91
134
|
}
|
|
92
135
|
names.push(`${ns}.${name}`);
|
|
93
136
|
}
|
|
94
137
|
else {
|
|
95
|
-
throw new Error(
|
|
138
|
+
throw new Error(`unknown tool schema "${oneLine(String(tool.type), 40)}"`);
|
|
96
139
|
}
|
|
97
140
|
}
|
|
98
141
|
}
|
|
@@ -105,14 +148,14 @@ export function codexAdvertisedTools(value) {
|
|
|
105
148
|
for (const item of request.input) {
|
|
106
149
|
const input = record(item);
|
|
107
150
|
if (typeof input.type !== "string" || !INPUT_TYPES.has(input.type)) {
|
|
108
|
-
throw new Error(
|
|
151
|
+
throw new Error(`unknown input item "${oneLine(String(input.type), 40)}"`);
|
|
109
152
|
}
|
|
110
153
|
if (input.type === "additional_tools" ||
|
|
111
154
|
input.type === "tool_search_output") {
|
|
112
155
|
inspect(input.tools);
|
|
113
156
|
}
|
|
114
157
|
else if (input.tools !== undefined || input.functions !== undefined) {
|
|
115
|
-
throw new Error("
|
|
158
|
+
throw new Error(`tools on an "${input.type}" input item`);
|
|
116
159
|
}
|
|
117
160
|
}
|
|
118
161
|
return names;
|
|
@@ -145,7 +188,13 @@ async function execute(binary, args, cwd, env, signal) {
|
|
|
145
188
|
cwd,
|
|
146
189
|
env,
|
|
147
190
|
detached: process.platform !== "win32",
|
|
148
|
-
stdio: ["ignore", "pipe", "
|
|
191
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
192
|
+
});
|
|
193
|
+
// The probe's environment holds no login or owner data, so the child's last
|
|
194
|
+
// words are safe to log; they say why a computer fails a proof.
|
|
195
|
+
let stderrTail = "";
|
|
196
|
+
child.stderr.on("data", (chunk) => {
|
|
197
|
+
stderrTail = (stderrTail + chunk.toString()).slice(-600);
|
|
149
198
|
});
|
|
150
199
|
const kill = () => {
|
|
151
200
|
try {
|
|
@@ -168,13 +217,15 @@ async function execute(binary, args, cwd, env, signal) {
|
|
|
168
217
|
output += chunk.toString();
|
|
169
218
|
if (Buffer.byteLength(output) > MAX_BYTES) {
|
|
170
219
|
kill();
|
|
171
|
-
reject(new
|
|
220
|
+
reject(new BoundaryMismatch("Codex printed more than the probe allows"));
|
|
172
221
|
}
|
|
173
222
|
});
|
|
174
223
|
child.once("error", reject);
|
|
175
|
-
child.once("close", (code) => code === 0 && !signal.aborted
|
|
224
|
+
child.once("close", (code, exitSignal) => code === 0 && !signal.aborted
|
|
176
225
|
? resolve(output)
|
|
177
|
-
: reject(new Error(
|
|
226
|
+
: reject(new Error(signal.aborted
|
|
227
|
+
? `Codex was stopped after ${PROBE_MS / 1000} s or by shutdown: ${oneLine(stderrTail)}`
|
|
228
|
+
: `Codex exited with code ${code ?? exitSignal}: ${oneLine(stderrTail)}`)));
|
|
178
229
|
});
|
|
179
230
|
}
|
|
180
231
|
finally {
|
|
@@ -185,7 +236,11 @@ async function execute(binary, args, cwd, env, signal) {
|
|
|
185
236
|
function digest(value) {
|
|
186
237
|
return createHash("sha256").update(value).digest("hex");
|
|
187
238
|
}
|
|
188
|
-
|
|
239
|
+
/**
|
|
240
|
+
* What makes a Codex binary the same file: its path, real target, inode, size
|
|
241
|
+
* and times. An update in place changes at least the size or the times.
|
|
242
|
+
*/
|
|
243
|
+
export async function binaryIdentity(binary) {
|
|
189
244
|
const target = await realpath(binary);
|
|
190
245
|
const info = await stat(target);
|
|
191
246
|
return JSON.stringify([
|
|
@@ -208,8 +263,11 @@ export async function probeCodexBoundary(binary, version, catalog, stop, { web =
|
|
|
208
263
|
try {
|
|
209
264
|
await proveCodexBoundary(binary, version, catalog, stop, web);
|
|
210
265
|
}
|
|
211
|
-
catch {
|
|
212
|
-
|
|
266
|
+
catch (error) {
|
|
267
|
+
const check = oneLine(error instanceof Error ? error.message : "unknown");
|
|
268
|
+
throw error instanceof BoundaryMismatch
|
|
269
|
+
? new CodexBoundaryError(version, check)
|
|
270
|
+
: new CodexProbeInterrupted(version, check);
|
|
213
271
|
}
|
|
214
272
|
}
|
|
215
273
|
// The web proof's cache key leaves the version out: a job has the binary and
|
|
@@ -234,7 +292,7 @@ const proofCache = (key) => join(homeDir(), ".talentos", "codex-boundary", `${ke
|
|
|
234
292
|
/** Whether this Codex binary passed the proof with live web search on. */
|
|
235
293
|
export async function codexWebProven(binary, catalog) {
|
|
236
294
|
try {
|
|
237
|
-
const key = webProofKey(await
|
|
295
|
+
const key = webProofKey(await binaryIdentity(binary), catalog);
|
|
238
296
|
return ((await readFile(proofCache(key), "utf8")) ===
|
|
239
297
|
JSON.stringify({ key, safe: true }));
|
|
240
298
|
}
|
|
@@ -243,7 +301,7 @@ export async function codexWebProven(binary, catalog) {
|
|
|
243
301
|
}
|
|
244
302
|
}
|
|
245
303
|
async function proveCodexBoundary(binary, version, catalog, stop, web = false) {
|
|
246
|
-
const before = await
|
|
304
|
+
const before = await binaryIdentity(binary);
|
|
247
305
|
const key = web
|
|
248
306
|
? webProofKey(before, catalog)
|
|
249
307
|
: digest(JSON.stringify([
|
|
@@ -297,7 +355,7 @@ async function proveCodexBoundary(binary, version, catalog, stop, web = false) {
|
|
|
297
355
|
import {StdioServerTransport} from ${JSON.stringify(import.meta.resolve("@modelcontextprotocol/sdk/server/stdio.js"))};
|
|
298
356
|
import {ListToolsRequestSchema,CallToolRequestSchema} from ${JSON.stringify(import.meta.resolve("@modelcontextprotocol/sdk/types.js"))};
|
|
299
357
|
const server=new Server({name:'talentos',version:'probe'},{capabilities:{tools:{}}});
|
|
300
|
-
server.setRequestHandler(ListToolsRequestSchema,async()=>{await new Promise(r=>setTimeout(r,Number(process.argv[2])));return {tools:${JSON.stringify([...ROOM_TOOLS, "
|
|
358
|
+
server.setRequestHandler(ListToolsRequestSchema,async()=>{await new Promise(r=>setTimeout(r,Number(process.argv[2])));return {tools:${JSON.stringify([...ROOM_TOOLS, "share_skill"].map((name) => ({ name, description: name, inputSchema: { type: "object", properties: {} }, annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false } })))}};});
|
|
301
359
|
server.setRequestHandler(CallToolRequestSchema,async r=>({content:[{type:'text',text:r.params.name==='read_room'?${JSON.stringify(marker)}:'private-tool-refused'}]}));
|
|
302
360
|
await server.connect(new StdioServerTransport());`, { mode: 0o600 });
|
|
303
361
|
server.on("request", async (request, response) => {
|
|
@@ -305,7 +363,7 @@ await server.connect(new StdioServerTransport());`, { mode: 0o600 });
|
|
|
305
363
|
if (request.method !== "POST" ||
|
|
306
364
|
request.url !== "/v1/responses" ||
|
|
307
365
|
++requests > 20) {
|
|
308
|
-
throw new Error(
|
|
366
|
+
throw new Error(`unexpected request ${request.method} ${oneLine(String(request.url).split("?")[0] ?? "", 80)}`);
|
|
309
367
|
}
|
|
310
368
|
let raw = "";
|
|
311
369
|
for await (const chunk of request) {
|
|
@@ -397,7 +455,10 @@ await server.connect(new StdioServerTransport());`, { mode: 0o600 });
|
|
|
397
455
|
});
|
|
398
456
|
}
|
|
399
457
|
catch (error) {
|
|
400
|
-
|
|
458
|
+
// A request cut off by the timeout or a shutdown is not Codex's doing.
|
|
459
|
+
if (!(failure || signal.aborted)) {
|
|
460
|
+
failure = error;
|
|
461
|
+
}
|
|
401
462
|
response.writeHead(400).end();
|
|
402
463
|
controller.abort();
|
|
403
464
|
}
|
|
@@ -432,27 +493,50 @@ await server.connect(new StdioServerTransport());`, { mode: 0o600 });
|
|
|
432
493
|
web,
|
|
433
494
|
});
|
|
434
495
|
args.unshift("-c", 'model_provider="talentos_probe"', "-c", 'model_providers.talentos_probe.name="Loopback"', "-c", `model_providers.talentos_probe.base_url="http://127.0.0.1:${address.port}/v1"`, "-c", 'model_providers.talentos_probe.wire_api="responses"', "-c", 'model_providers.talentos_probe.env_key="TALENTOS_PROBE_KEY"');
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
496
|
+
// The stand-in aborts the child when it sees a bad request, so its own
|
|
497
|
+
// word on what was wrong beats the child's "stopped".
|
|
498
|
+
const output = await execute(binary, args, directory, env, signal).catch((error) => {
|
|
499
|
+
throw failure
|
|
500
|
+
? new BoundaryMismatch(`${turn === 0 ? "fresh" : "resumed"} turn: ${failure?.message ?? failure}`)
|
|
501
|
+
: error;
|
|
502
|
+
});
|
|
503
|
+
const missing = ROOM_TOOLS.filter((name) => !observations[turn]?.has(`mcp__talentos.${name}`));
|
|
504
|
+
const incomplete = failure
|
|
505
|
+
? String(failure?.message ?? failure)
|
|
506
|
+
: (!finished[turn] && "Codex stopped before its final answer") ||
|
|
507
|
+
(calls[turn]?.length !== turnSteps[turn]?.length &&
|
|
508
|
+
`${calls[turn]?.length ?? 0} of ${turnSteps[turn]?.length ?? 0} expected tool calls ran`) ||
|
|
509
|
+
(missing.length > 0 &&
|
|
510
|
+
`room tools not offered to the model: ${missing.slice(0, 3).join(", ")}`);
|
|
511
|
+
if (incomplete) {
|
|
512
|
+
throw new BoundaryMismatch(`${turn === 0 ? "fresh" : "resumed"} turn: ${incomplete}`);
|
|
441
513
|
}
|
|
514
|
+
// Only the JSON events count; a line Codex prints for people (a notice, a
|
|
515
|
+
// warning) is neither an event nor a reason to refuse a safe tool list.
|
|
442
516
|
const events = output
|
|
443
517
|
.trim()
|
|
444
518
|
.split("\n")
|
|
445
|
-
.
|
|
519
|
+
.flatMap((line) => {
|
|
520
|
+
try {
|
|
521
|
+
const event = JSON.parse(line);
|
|
522
|
+
return event && typeof event === "object" && !Array.isArray(event)
|
|
523
|
+
? [event]
|
|
524
|
+
: [];
|
|
525
|
+
}
|
|
526
|
+
catch {
|
|
527
|
+
return [];
|
|
528
|
+
}
|
|
529
|
+
});
|
|
446
530
|
const thread = events.find((event) => event.type === "thread.started")?.thread_id;
|
|
447
531
|
if (typeof thread !== "string" ||
|
|
448
532
|
(session && session !== thread) ||
|
|
449
533
|
!events.some((event) => event.type === "turn.completed")) {
|
|
450
|
-
throw new
|
|
534
|
+
throw new BoundaryMismatch(`${turn === 0 ? "fresh" : "resumed"} turn: no thread, or it did not complete`);
|
|
451
535
|
}
|
|
452
536
|
session = thread;
|
|
453
537
|
}
|
|
454
|
-
if ((await
|
|
455
|
-
throw new Error("Codex changed
|
|
538
|
+
if ((await binaryIdentity(binary)) !== before) {
|
|
539
|
+
throw new Error("the Codex file changed while it was checked");
|
|
456
540
|
}
|
|
457
541
|
signal.throwIfAborted();
|
|
458
542
|
// Failure to persist an optimization does not invalidate a completed proof.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { homeDir } from "../install.js";
|
|
4
|
+
// Where a Gemini CLI login lives (docs: geminicli.com authentication, and the
|
|
5
|
+
// binary's own start-up message): an OAuth sign-in leaves oauth_creds.json and
|
|
6
|
+
// google_accounts.json under ~/.gemini, an API key or a Vertex project lives in
|
|
7
|
+
// the environment or in ~/.gemini/.env, and settings.json names the method the
|
|
8
|
+
// owner picked. A room job gets a fresh home, so exactly these carry across:
|
|
9
|
+
// the login, never the owner's memory, extensions, skills or other settings.
|
|
10
|
+
/** The variables that carry a login or its routing. Never written to a file. */
|
|
11
|
+
export const GEMINI_LOGIN_ENV = /^(?:GEMINI_API_KEY|GOOGLE_API_KEY|GOOGLE_GENAI_USE_VERTEXAI|GOOGLE_GENAI_USE_GCA|GOOGLE_CLOUD_PROJECT|GOOGLE_CLOUD_PROJECT_ID|GOOGLE_CLOUD_LOCATION|GOOGLE_APPLICATION_CREDENTIALS|(?:HTTPS?|NO)_PROXY|NODE_EXTRA_CA_CERTS)$/iu;
|
|
12
|
+
/** The OAuth files, linked (never copied): Gemini refreshes the token in place. */
|
|
13
|
+
export const GEMINI_CREDENTIAL_FILES = [
|
|
14
|
+
"oauth_creds.json",
|
|
15
|
+
"google_accounts.json",
|
|
16
|
+
];
|
|
17
|
+
const ENV_LINE = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$/u;
|
|
18
|
+
const QUOTED = /^(["'])(.*)\1$/u;
|
|
19
|
+
export function geminiDir(env) {
|
|
20
|
+
return join(env.GEMINI_CLI_HOME || homeDir(env), ".gemini");
|
|
21
|
+
}
|
|
22
|
+
function parseDotenv(text) {
|
|
23
|
+
const values = {};
|
|
24
|
+
for (const line of text.split("\n")) {
|
|
25
|
+
if (line.trimStart().startsWith("#")) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const match = ENV_LINE.exec(line);
|
|
29
|
+
if (match?.[1] && GEMINI_LOGIN_ENV.test(match[1])) {
|
|
30
|
+
const raw = match[2] ?? "";
|
|
31
|
+
values[match[1]] = QUOTED.exec(raw)?.[2] ?? raw;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return values;
|
|
35
|
+
}
|
|
36
|
+
function readText(path) {
|
|
37
|
+
try {
|
|
38
|
+
return readFileSync(path, "utf8");
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Missing or unreadable carries no login; never echo what failed.
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Synchronous on purpose: two small files, read once per job or once at link.
|
|
46
|
+
export function readGeminiLogin(env) {
|
|
47
|
+
const dir = geminiDir(env);
|
|
48
|
+
const settingsText = readText(join(dir, "settings.json"));
|
|
49
|
+
const dotenvText = readText(join(dir, ".env"));
|
|
50
|
+
let authType;
|
|
51
|
+
try {
|
|
52
|
+
const type = JSON.parse(settingsText ?? "null")?.security?.auth?.selectedType;
|
|
53
|
+
authType = typeof type === "string" && type.length <= 64 ? type : undefined;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
authType = undefined;
|
|
57
|
+
}
|
|
58
|
+
const fromProcess = Object.fromEntries(Object.entries(env).filter((entry) => GEMINI_LOGIN_ENV.test(entry[0]) && typeof entry[1] === "string"));
|
|
59
|
+
return {
|
|
60
|
+
...(authType ? { authType } : {}),
|
|
61
|
+
dir,
|
|
62
|
+
env: { ...parseDotenv(dotenvText ?? ""), ...fromProcess },
|
|
63
|
+
files: GEMINI_CREDENTIAL_FILES.filter((name) => existsSync(join(dir, name))),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** Does this computer have any way for Gemini CLI to sign in? */
|
|
67
|
+
export function geminiSignedIn(login) {
|
|
68
|
+
return (login.files.includes("oauth_creds.json") ||
|
|
69
|
+
Boolean(login.env.GEMINI_API_KEY ||
|
|
70
|
+
login.env.GOOGLE_API_KEY ||
|
|
71
|
+
login.env.GOOGLE_GENAI_USE_VERTEXAI ||
|
|
72
|
+
login.env.GOOGLE_GENAI_USE_GCA) ||
|
|
73
|
+
login.authType === "compute-default-credentials");
|
|
74
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ROOM_TOOLS } from "./codex-policy.js";
|
|
2
|
+
// A Gemini CLI room job's boundary, written as the CLI's own policy engine and
|
|
3
|
+
// user settings (verified against @google/gemini-cli 0.65.0 with its own
|
|
4
|
+
// binary: see docs/features/agent-access/README.md, "Gemini CLI"). Three layers:
|
|
5
|
+
//
|
|
6
|
+
// 1. The policy denies every built-in tool (`toolName = "*"`). A rule with no
|
|
7
|
+
// argument pattern removes its tool from the model's view, so the model is
|
|
8
|
+
// never offered a file, shell, search or sub-agent tool, and a call to one it
|
|
9
|
+
// names anyway is refused as an unregistered tool. The probe fails without it.
|
|
10
|
+
// 2. The MCP fence is `includeTools` on the one `talentos` server plus
|
|
11
|
+
// `--allowed-mcp-server-names`: only the room tools are ever registered. The
|
|
12
|
+
// MCP deny and allow rules below are defence in depth; on 0.65.0 the probe
|
|
13
|
+
// passes without them, so it cannot see them regress (a unit test pins their
|
|
14
|
+
// text).
|
|
15
|
+
// 3. Headless runs treat any confirmation as a refusal, so a tool the policy
|
|
16
|
+
// missed (one a later Gemini adds) still cannot run.
|
|
17
|
+
export const GEMINI_SERVER = "talentos";
|
|
18
|
+
/** Gemini names an MCP tool `mcp_<server>_<tool>` in what the model sees. */
|
|
19
|
+
export const geminiToolName = (tool) => `mcp_${GEMINI_SERVER}_${tool}`;
|
|
20
|
+
export function geminiRoomPolicy() {
|
|
21
|
+
return `# TalentOS room job: room tools only. Written fresh for each job.
|
|
22
|
+
[[rule]]
|
|
23
|
+
toolName = "*"
|
|
24
|
+
decision = "deny"
|
|
25
|
+
priority = 1
|
|
26
|
+
denyMessage = "A room job can only use its room tools."
|
|
27
|
+
|
|
28
|
+
[[rule]]
|
|
29
|
+
mcpName = "*"
|
|
30
|
+
toolName = "*"
|
|
31
|
+
decision = "deny"
|
|
32
|
+
priority = 1
|
|
33
|
+
denyMessage = "A room job can only use its room tools."
|
|
34
|
+
|
|
35
|
+
[[rule]]
|
|
36
|
+
mcpName = "${GEMINI_SERVER}"
|
|
37
|
+
toolName = ${JSON.stringify([...ROOM_TOOLS])}
|
|
38
|
+
decision = "allow"
|
|
39
|
+
priority = 100
|
|
40
|
+
`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The user settings of the job's own home: the sign-in method the owner chose,
|
|
44
|
+
* the one MCP server (the hosted room endpoint, with the agent's key; never
|
|
45
|
+
* `trust: true`, which would let every tool the server lists past the policy,
|
|
46
|
+
* as the probe found), and no telemetry, updates or usage statistics. Everything else the owner has set
|
|
47
|
+
* stays in their own home.
|
|
48
|
+
*/
|
|
49
|
+
export function geminiRoomSettings(input) {
|
|
50
|
+
return JSON.stringify({
|
|
51
|
+
...(input.authType
|
|
52
|
+
? { security: { auth: { selectedType: input.authType } } }
|
|
53
|
+
: {}),
|
|
54
|
+
general: { enableAutoUpdate: false },
|
|
55
|
+
mcpServers: {
|
|
56
|
+
[GEMINI_SERVER]: {
|
|
57
|
+
headers: { Authorization: `Bearer ${input.apiKey}` },
|
|
58
|
+
httpUrl: input.mcpUrl,
|
|
59
|
+
// The server lists more than a room job may use: only these are ever
|
|
60
|
+
// registered with the model.
|
|
61
|
+
includeTools: [...ROOM_TOOLS],
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
privacy: { usageStatisticsEnabled: false },
|
|
65
|
+
telemetry: { enabled: false },
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The launch: headless, the job's own policy, one MCP server, no workspace
|
|
70
|
+
* prompt. The job packet comes on stdin and `--prompt` is appended to it; the
|
|
71
|
+
* room playbook is the job's GEMINI.md, the only file in the job's directory:
|
|
72
|
+
* headless Gemini expands `@file` references in a prompt, so nothing secret may
|
|
73
|
+
* ever be staged there. Approval stays at `default`: with the
|
|
74
|
+
* policy above, nothing needs a confirmation, and a headless run refuses one.
|
|
75
|
+
*/
|
|
76
|
+
export const GEMINI_PROMPT = "This is a TalentOS room job. The JSON above is its packet. Read it, act only through your talentos room tools, and end with the answer for the room.";
|
|
77
|
+
export function geminiRoomArgs(input) {
|
|
78
|
+
return [
|
|
79
|
+
"--skip-trust",
|
|
80
|
+
"--approval-mode",
|
|
81
|
+
"default",
|
|
82
|
+
"--policy",
|
|
83
|
+
input.policyPath,
|
|
84
|
+
"--allowed-mcp-server-names",
|
|
85
|
+
GEMINI_SERVER,
|
|
86
|
+
"--output-format",
|
|
87
|
+
"stream-json",
|
|
88
|
+
"--prompt",
|
|
89
|
+
GEMINI_PROMPT,
|
|
90
|
+
];
|
|
91
|
+
}
|