talentos 1.4.11 → 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/dist/agent/adapters.js +134 -5
- package/dist/agent/codex-policy.js +11 -0
- package/dist/agent/codex-probe.js +106 -26
- 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/native/codex-launch.js +2 -0
- package/dist/agent/native/config.js +4 -2
- package/dist/agent/native/gate.js +125 -7
- package/dist/agent/native/hook-entry.js +2 -0
- package/dist/agent/native/launch.js +2 -0
- package/dist/agent/native/native-issue.js +3 -3
- package/dist/agent/native/touch.js +19 -1
- 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 +22 -2
- package/dist/agent-config.js +6 -1
- package/dist/agent-http.js +9 -0
- package/dist/agent-link.js +4 -2
- package/dist/commands/agent-native.js +0 -3
- package/dist/commands/agent-serve.js +7 -2
- package/dist/commands/agent.js +8 -0
- package/dist/provider-binary.js +12 -2
- package/package.json +1 -1
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { createServer } from "node:http";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { createInterface } from "node:readline";
|
|
7
|
+
import { writePrivateFile } from "../agent-config.js";
|
|
8
|
+
import { ProviderBinaryError } from "../provider-binary.js";
|
|
9
|
+
import { geminiRoomArgs, geminiRoomPolicy, geminiRoomSettings, geminiToolName, } from "./gemini-policy.js";
|
|
10
|
+
// Proves, against the real binary and with no login, that this Gemini CLI keeps
|
|
11
|
+
// a room job inside its room tools. It runs the exact launch a job uses (same
|
|
12
|
+
// policy, settings and flags) in a throwaway home, pointed at a loopback stand-in
|
|
13
|
+
// for the Gemini API and a loopback stand-in for the room endpoint, and checks
|
|
14
|
+
// four things: every request offers the model the room tool alone, a call to a
|
|
15
|
+
// file tool the model names anyway is refused and reads nothing, and a call to
|
|
16
|
+
// the room tool does reach the room endpoint (so the allow rule is live, not
|
|
17
|
+
// only the offer), and an @file reference in its input is not expanded into the
|
|
18
|
+
// request. A Gemini that fails it serves no room job. The result is
|
|
19
|
+
// 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
|
+
export class GeminiBoundaryError extends ProviderBinaryError {
|
|
25
|
+
constructor(version) {
|
|
26
|
+
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.`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function toolNames(body) {
|
|
30
|
+
const tools = body?.tools;
|
|
31
|
+
if (!Array.isArray(tools)) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
return tools.flatMap((tool) => Array.isArray(tool.functionDeclarations)
|
|
35
|
+
? tool.functionDeclarations
|
|
36
|
+
.map((declaration) => declaration.name)
|
|
37
|
+
.filter((name) => typeof name === "string")
|
|
38
|
+
: []);
|
|
39
|
+
}
|
|
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
|
+
/**
|
|
53
|
+
* The Gemini API stand-in: first answers with a call to the room tool and one
|
|
54
|
+
* to a file tool, then text.
|
|
55
|
+
*/
|
|
56
|
+
function fakeApi(seen, secretPath) {
|
|
57
|
+
return createServer(async (request, response) => {
|
|
58
|
+
try {
|
|
59
|
+
const body = await readBody(request);
|
|
60
|
+
let parsed;
|
|
61
|
+
try {
|
|
62
|
+
parsed = JSON.parse(body);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
parsed = null;
|
|
66
|
+
}
|
|
67
|
+
if (request.url?.includes("countTokens")) {
|
|
68
|
+
response.setHeader("content-type", "application/json");
|
|
69
|
+
response.end(JSON.stringify({ totalTokens: 1 }));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// The CLI asks the model first to route the turn (a non-streaming call
|
|
73
|
+
// that wants JSON); any routing answer will do, and it offers no tools.
|
|
74
|
+
if (!request.url?.includes("stream")) {
|
|
75
|
+
response.setHeader("content-type", "application/json");
|
|
76
|
+
response.end(JSON.stringify({
|
|
77
|
+
candidates: [
|
|
78
|
+
{
|
|
79
|
+
content: {
|
|
80
|
+
parts: [
|
|
81
|
+
{
|
|
82
|
+
text: JSON.stringify({
|
|
83
|
+
complexity_reasoning: "probe",
|
|
84
|
+
complexity_score: 10,
|
|
85
|
+
model_choice: "flash",
|
|
86
|
+
reasoning: "probe",
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
role: "model",
|
|
91
|
+
},
|
|
92
|
+
finishReason: "STOP",
|
|
93
|
+
index: 0,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
}));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
seen.requests.push({ body, tools: toolNames(parsed) });
|
|
100
|
+
// Answered once the last thing in the conversation is a tool result.
|
|
101
|
+
const contents = parsed?.contents;
|
|
102
|
+
const last = Array.isArray(contents) ? contents.at(-1) : undefined;
|
|
103
|
+
const answered = JSON.stringify(last ?? "").includes("functionResponse");
|
|
104
|
+
const parts = answered
|
|
105
|
+
? [{ text: "probe done" }]
|
|
106
|
+
: [
|
|
107
|
+
{ functionCall: { args: {}, name: geminiToolName(ROOM_TOOL) } },
|
|
108
|
+
{
|
|
109
|
+
functionCall: {
|
|
110
|
+
args: { file_path: secretPath },
|
|
111
|
+
name: "read_file",
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
];
|
|
115
|
+
const payload = {
|
|
116
|
+
candidates: [
|
|
117
|
+
{
|
|
118
|
+
content: { parts, role: "model" },
|
|
119
|
+
finishReason: "STOP",
|
|
120
|
+
index: 0,
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
usageMetadata: {
|
|
124
|
+
candidatesTokenCount: 1,
|
|
125
|
+
promptTokenCount: 1,
|
|
126
|
+
totalTokenCount: 2,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
if (request.url?.includes("stream")) {
|
|
130
|
+
response.setHeader("content-type", "text/event-stream");
|
|
131
|
+
response.end(`data: ${JSON.stringify(payload)}\n\n`);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
response.setHeader("content-type", "application/json");
|
|
135
|
+
response.end(JSON.stringify(payload));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
response.statusCode = 500;
|
|
140
|
+
response.end();
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
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
|
+
/** Runs the probe and returns what it saw; `probeGeminiBoundary` judges it. */
|
|
196
|
+
export async function runGeminiProbe(input) {
|
|
197
|
+
const dir = await mkdtemp(join(tmpdir(), "talentos-gemini-probe-"));
|
|
198
|
+
const seen = { requests: [], roomCalls: [] };
|
|
199
|
+
const secretPath = join(dir, "secret.txt");
|
|
200
|
+
const api = fakeApi(seen, secretPath);
|
|
201
|
+
const room = fakeRoom(seen);
|
|
202
|
+
try {
|
|
203
|
+
await writeFile(secretPath, SECRET, { mode: 0o600 });
|
|
204
|
+
const [apiPort, roomPort] = await Promise.all([listen(api), listen(room)]);
|
|
205
|
+
const home = join(dir, "home");
|
|
206
|
+
const dotGemini = join(home, ".gemini");
|
|
207
|
+
const work = join(home, "work");
|
|
208
|
+
await mkdir(dotGemini, { recursive: true, mode: 0o700 });
|
|
209
|
+
await mkdir(work, { recursive: true, mode: 0o700 });
|
|
210
|
+
const policyPath = join(dotGemini, "room-policy.toml");
|
|
211
|
+
await writePrivateFile(policyPath, geminiRoomPolicy());
|
|
212
|
+
await writePrivateFile(join(dotGemini, "settings.json"), geminiRoomSettings({
|
|
213
|
+
apiKey: "tos_probe",
|
|
214
|
+
authType: "gemini-api-key",
|
|
215
|
+
mcpUrl: `http://127.0.0.1:${roomPort}/mcp`,
|
|
216
|
+
}));
|
|
217
|
+
const child = spawn(input.binary, geminiRoomArgs({ policyPath }), {
|
|
218
|
+
cwd: work,
|
|
219
|
+
env: {
|
|
220
|
+
...input.env,
|
|
221
|
+
GEMINI_API_KEY: "probe",
|
|
222
|
+
GEMINI_CLI_HOME: home,
|
|
223
|
+
GOOGLE_GEMINI_BASE_URL: `http://127.0.0.1:${apiPort}`,
|
|
224
|
+
},
|
|
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;
|
|
248
|
+
}
|
|
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
|
+
}
|
|
261
|
+
});
|
|
262
|
+
clearTimeout(timer);
|
|
263
|
+
return {
|
|
264
|
+
advertised: [...new Set(seen.requests.flatMap((r) => r.tools))],
|
|
265
|
+
readRefused,
|
|
266
|
+
roomCalls: seen.roomCalls,
|
|
267
|
+
secretLeaked: seen.requests.some((request) => request.body.includes(SECRET)),
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
finally {
|
|
271
|
+
await Promise.all([closeServer(api), closeServer(room)]);
|
|
272
|
+
await rm(dir, { force: true, recursive: true });
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Whether what the probe saw is a Gemini that keeps a room job in its room tool:
|
|
277
|
+
* only that tool offered on every request, it ran and nothing else did, the file
|
|
278
|
+
* tool was refused and its secret never reached the model.
|
|
279
|
+
*/
|
|
280
|
+
export function geminiBoundaryHolds(result) {
|
|
281
|
+
return (result.advertised.length === 1 &&
|
|
282
|
+
result.advertised[0] === geminiToolName(ROOM_TOOL) &&
|
|
283
|
+
result.roomCalls.length === 1 &&
|
|
284
|
+
result.roomCalls[0] === ROOM_TOOL &&
|
|
285
|
+
result.readRefused &&
|
|
286
|
+
!result.secretLeaked);
|
|
287
|
+
}
|
|
288
|
+
const proofs = new Map();
|
|
289
|
+
/**
|
|
290
|
+
* 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.
|
|
293
|
+
*/
|
|
294
|
+
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
|
+
}, () => {
|
|
303
|
+
throw new GeminiBoundaryError(input.version);
|
|
304
|
+
});
|
|
305
|
+
proofs.set(key, proof);
|
|
306
|
+
}
|
|
307
|
+
return proof;
|
|
308
|
+
}
|
|
@@ -21,6 +21,8 @@ export async function prepareCodexOwnerLaunch(input) {
|
|
|
21
21
|
...(input.askSocket ? { askSocket: input.askSocket } : {}),
|
|
22
22
|
home: input.home,
|
|
23
23
|
...(input.roomId ? { roomId: input.roomId } : {}),
|
|
24
|
+
...(input.roomFileIds ? { roomFileIds: input.roomFileIds } : {}),
|
|
25
|
+
...(input.triggerId ? { triggerId: input.triggerId } : {}),
|
|
24
26
|
writeRoots: input.workspace.writeRoots,
|
|
25
27
|
}));
|
|
26
28
|
const catalogPath = join(jobDir, "catalog.json");
|
|
@@ -7,6 +7,7 @@ import { isMissing, writePrivateFile } from "../../agent-config.js";
|
|
|
7
7
|
import { isInside, protectedPaths, reachesProtected } from "./paths.js";
|
|
8
8
|
const exec = promisify(execFile);
|
|
9
9
|
export const NATIVE_FILE = "native.json";
|
|
10
|
+
export const NATIVE_OFF_FILE = "native-off.json";
|
|
10
11
|
export async function readNativeConfig(directory) {
|
|
11
12
|
try {
|
|
12
13
|
const value = JSON.parse(await readFile(join(directory, NATIVE_FILE), "utf8"));
|
|
@@ -42,6 +43,7 @@ export async function readNativeFallback(directory) {
|
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
export async function disableNative(directory) {
|
|
46
|
+
await writePrivateFile(join(directory, NATIVE_OFF_FILE), JSON.stringify(Date.now()));
|
|
45
47
|
await rm(join(directory, NATIVE_FILE), { force: true });
|
|
46
48
|
}
|
|
47
49
|
/** [a-z0-9-] only: a display name never forms a path. */
|
|
@@ -111,8 +113,8 @@ export function rootProblem(config, home) {
|
|
|
111
113
|
* runs in, otherwise ~/TalentOS/<name>-<id>/ (created here, empty).
|
|
112
114
|
*/
|
|
113
115
|
export async function enableNative(input) {
|
|
114
|
-
let root = await repoRoot(input.cwd);
|
|
115
|
-
let kind = "repo";
|
|
116
|
+
let root = input.root ?? (input.cwd ? await repoRoot(input.cwd) : undefined);
|
|
117
|
+
let kind = input.root ? (input.kind ?? "repo") : "repo";
|
|
116
118
|
if (root) {
|
|
117
119
|
root = realpathSync.native(root);
|
|
118
120
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
-
import { rm } from "node:fs/promises";
|
|
3
|
+
import { readFile, rm } from "node:fs/promises";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
6
|
import { writePrivateFile, } from "../../agent-config.js";
|
|
@@ -8,12 +8,12 @@ import { providerPathEnv, resolveProviderBinary, } from "../../provider-binary.j
|
|
|
8
8
|
import { codexFenceEligible, codexFenceVersion, codexUnsupportedMessage, } from "./codex-fence.js";
|
|
9
9
|
import { codexFenceProbeCached, ensureCodexFenceProbe, } from "./codex-fence-probe.js";
|
|
10
10
|
import { codexDisqualifier, codexOwnerContextPresent } from "./codex-owner.js";
|
|
11
|
-
import { NATIVE_FALLBACK_FILE, NATIVE_FILE, readNativeConfig, } from "./config.js";
|
|
11
|
+
import { enableNative, NATIVE_FALLBACK_FILE, NATIVE_FILE, NATIVE_OFF_FILE, readNativeConfig, repoRoot, rootProblem, } from "./config.js";
|
|
12
12
|
import { ownerContextPresent } from "./context.js";
|
|
13
13
|
import { claudeDisqualifier } from "./disqualify.js";
|
|
14
14
|
import { loginShellEnv } from "./env.js";
|
|
15
15
|
import { ensureOwnerNativeProbe, ownerNativeProbeCached } from "./probe.js";
|
|
16
|
-
import { readProjects } from "./projects.js";
|
|
16
|
+
import { readProjects, registerRoot } from "./projects.js";
|
|
17
17
|
import { prepareWorkspace } from "./workspace.js";
|
|
18
18
|
const WHITESPACE = /\s+/u;
|
|
19
19
|
const exec = promisify(execFile);
|
|
@@ -21,10 +21,10 @@ const ENV_TTL_MS = 10 * 60_000;
|
|
|
21
21
|
const ENV_MAX_STALE_MS = 60 * 60_000;
|
|
22
22
|
const RETRY_MS = 10 * 60_000;
|
|
23
23
|
export const UNKNOWN_PROJECT = "That project isn't set up on this computer, so I'm working room-only.";
|
|
24
|
-
export const NO_PROJECT = "No project is
|
|
24
|
+
export const NO_PROJECT = "No project folder is chosen on this computer yet, so I'm working room-only. The owner can choose one in the agent settings.";
|
|
25
25
|
export const MISSING_PROJECT = "That project's folder isn't available on this computer, so I'm working room-only.";
|
|
26
|
-
export const NATIVE_OFF = "
|
|
27
|
-
export const NOT_READY = "The safety check for
|
|
26
|
+
export const NATIVE_OFF = "Computer access is off. Its owner can allow it in the agent settings.";
|
|
27
|
+
export const NOT_READY = "The safety check for this computer has not passed yet. Its owner can check the agent settings.";
|
|
28
28
|
export const CLAUDE_CHANGED = "Claude Code changed on this computer since its safety check, so I'm working room-only until it passes again.";
|
|
29
29
|
export const PREPARE_FAILED = "Something went wrong preparing your setup on this computer.";
|
|
30
30
|
export const LOCAL_BASE = "Couldn't get the latest code, so I started from your local copy.";
|
|
@@ -42,6 +42,7 @@ export class NativeGate {
|
|
|
42
42
|
// last heartbeat. Until it arrives, a Codex is never probed or reported ready.
|
|
43
43
|
codexTested;
|
|
44
44
|
retryAt = 0;
|
|
45
|
+
syncing;
|
|
45
46
|
env;
|
|
46
47
|
agent;
|
|
47
48
|
directory;
|
|
@@ -53,6 +54,119 @@ export class NativeGate {
|
|
|
53
54
|
this.directory = input.directory;
|
|
54
55
|
this.home = input.home;
|
|
55
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The owner's own choice in the app (a level above No access) authorizes the
|
|
59
|
+
* setup `talentos agent native enable` used to need a local yes for: the same
|
|
60
|
+
* folder rules and readiness checks, with no command. `null` is No access
|
|
61
|
+
* (instant), `undefined` an older server. A local `native off` holds until a
|
|
62
|
+
* later app choice (`enabledAt` newer than it).
|
|
63
|
+
*/
|
|
64
|
+
syncComputerSetup(choice) {
|
|
65
|
+
// A project request's heartbeat can overlap the regular one: one setup at a time.
|
|
66
|
+
this.syncing = (this.syncing ?? Promise.resolve())
|
|
67
|
+
.then(() => this.applyComputerSetup(choice))
|
|
68
|
+
.catch(() => undefined);
|
|
69
|
+
return this.syncing;
|
|
70
|
+
}
|
|
71
|
+
async applyComputerSetup(choice) {
|
|
72
|
+
if (choice === undefined) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (choice === null) {
|
|
76
|
+
await rm(join(this.directory, NATIVE_FILE), { force: true });
|
|
77
|
+
this.codexIssue = undefined;
|
|
78
|
+
this.probe = "none";
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (choice.enabledAt <= (await this.localOffAt())) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const stored = await readNativeConfig(this.directory);
|
|
86
|
+
let config = stored && !rootProblem(stored, this.home) ? stored : undefined;
|
|
87
|
+
if (stored && !config) {
|
|
88
|
+
// The folder went missing or was replaced: another project the owner
|
|
89
|
+
// added takes over; with none, the card asks for a folder.
|
|
90
|
+
config = await this.otherProject(stored.root);
|
|
91
|
+
}
|
|
92
|
+
else if (!config) {
|
|
93
|
+
config = await this.chooseWorkspace();
|
|
94
|
+
await registerRoot(this.directory, config);
|
|
95
|
+
}
|
|
96
|
+
if (!config) {
|
|
97
|
+
throw new Error("workspace");
|
|
98
|
+
}
|
|
99
|
+
if (config !== stored) {
|
|
100
|
+
this.probe = "none";
|
|
101
|
+
}
|
|
102
|
+
this.codexIssue =
|
|
103
|
+
this.codexIssue?.code === "workspace" ? undefined : this.codexIssue;
|
|
104
|
+
this.refresh();
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
this.codexIssue = { code: "workspace" };
|
|
108
|
+
this.probe = "failed";
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async localOffAt() {
|
|
112
|
+
try {
|
|
113
|
+
const at = JSON.parse(await readFile(join(this.directory, NATIVE_OFF_FILE), "utf8"));
|
|
114
|
+
return typeof at === "number" ? at : Number.POSITIVE_INFINITY;
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async otherProject(broken) {
|
|
121
|
+
for (const project of await readProjects(this.directory)) {
|
|
122
|
+
if (project.root === broken || rootProblem(project, this.home)) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
return await enableNative({
|
|
127
|
+
agentId: this.agent.agentId,
|
|
128
|
+
directory: this.directory,
|
|
129
|
+
home: this.home,
|
|
130
|
+
kind: project.kind,
|
|
131
|
+
name: this.agent.name,
|
|
132
|
+
root: project.root,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
// The next project.
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Where it works: the repo it was connected from, else its existing first
|
|
143
|
+
* project, else ~/TalentOS/<name>-<id>. A refused folder (home, credentials)
|
|
144
|
+
* falls through to the managed folder rather than leaving it unset.
|
|
145
|
+
*/
|
|
146
|
+
async chooseWorkspace() {
|
|
147
|
+
const connected = this.agent.connectCwd
|
|
148
|
+
? await repoRoot(this.agent.connectCwd)
|
|
149
|
+
: undefined;
|
|
150
|
+
const existing = (await readProjects(this.directory))[0];
|
|
151
|
+
const chosen = connected
|
|
152
|
+
? { root: connected }
|
|
153
|
+
: existing && { kind: existing.kind, root: existing.root };
|
|
154
|
+
const input = {
|
|
155
|
+
agentId: this.agent.agentId,
|
|
156
|
+
directory: this.directory,
|
|
157
|
+
home: this.home,
|
|
158
|
+
name: this.agent.name,
|
|
159
|
+
};
|
|
160
|
+
if (chosen) {
|
|
161
|
+
try {
|
|
162
|
+
return await enableNative({ ...input, ...chosen });
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
// Too broad or unavailable: use the managed folder below.
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return await enableNative(input);
|
|
169
|
+
}
|
|
56
170
|
/** The owner's yes exists on this computer (a file, so `native off` is instant). */
|
|
57
171
|
optedIn() {
|
|
58
172
|
return existsSync(join(this.directory, NATIVE_FILE));
|
|
@@ -71,7 +185,9 @@ export class NativeGate {
|
|
|
71
185
|
}
|
|
72
186
|
/** Why an opted-in computer can't use full setup, for the heartbeat. */
|
|
73
187
|
issue() {
|
|
74
|
-
return this.optedIn()
|
|
188
|
+
return this.optedIn() || this.codexIssue?.code === "workspace"
|
|
189
|
+
? this.codexIssue
|
|
190
|
+
: undefined;
|
|
75
191
|
}
|
|
76
192
|
/** Whether to tell the plane this computer is ready (heartbeat). */
|
|
77
193
|
reportable() {
|
|
@@ -103,6 +219,7 @@ export class NativeGate {
|
|
|
103
219
|
return;
|
|
104
220
|
}
|
|
105
221
|
this.probe = "failed";
|
|
222
|
+
this.codexIssue ??= { code: "setup_checks" };
|
|
106
223
|
// A failing provider is not re-probed on every heartbeat.
|
|
107
224
|
this.retryAt = Date.now() + RETRY_MS;
|
|
108
225
|
});
|
|
@@ -147,6 +264,7 @@ export class NativeGate {
|
|
|
147
264
|
hookEntry: this.hookEntry,
|
|
148
265
|
version: stdout.trim().split(WHITESPACE)[0] ?? "unknown",
|
|
149
266
|
});
|
|
267
|
+
this.codexIssue = undefined;
|
|
150
268
|
}
|
|
151
269
|
/**
|
|
152
270
|
* The login-shell env. Within ten minutes of a capture it is reused. For the
|
|
@@ -183,6 +183,8 @@ export async function runHook(jobDir, raw, holdMs = HOLD_MS) {
|
|
|
183
183
|
dirty: existsSync(join(jobDir, "dirty")),
|
|
184
184
|
home: context.home,
|
|
185
185
|
roomId: context.roomId,
|
|
186
|
+
roomFileIds: context.roomFileIds,
|
|
187
|
+
triggerId: context.triggerId,
|
|
186
188
|
writeRoots: context.writeRoots,
|
|
187
189
|
};
|
|
188
190
|
verdict = classifyCall(call, policy);
|
|
@@ -51,6 +51,8 @@ export async function prepareOwnerLaunch(input) {
|
|
|
51
51
|
...(input.askSocket ? { askSocket: input.askSocket } : {}),
|
|
52
52
|
home: input.home,
|
|
53
53
|
...(input.roomId ? { roomId: input.roomId } : {}),
|
|
54
|
+
...(input.roomFileIds ? { roomFileIds: input.roomFileIds } : {}),
|
|
55
|
+
...(input.triggerId ? { triggerId: input.triggerId } : {}),
|
|
54
56
|
writeRoots: input.workspace.writeRoots,
|
|
55
57
|
}));
|
|
56
58
|
await writePrivateFile(join(jobDir, "settings.json"), JSON.stringify({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const ROOM_ONLY_STATUS = "Codex is answering room-only: full setup isn't available on that computer right now.";
|
|
2
2
|
/** The neutral room line when an owner job runs room-only, for either provider. */
|
|
3
|
-
export const roomOnlyStatus = (provider) => provider === "
|
|
4
|
-
?
|
|
5
|
-
:
|
|
3
|
+
export const roomOnlyStatus = (provider) => provider === "claude_code"
|
|
4
|
+
? "Claude Code is answering room-only: full setup isn't available on that computer right now."
|
|
5
|
+
: ROOM_ONLY_STATUS;
|