talentos 1.4.8 → 1.4.9
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 +72 -6
- package/dist/agent/codex-policy.js +4 -2
- package/dist/agent/codex-probe.js +46 -8
- package/dist/agent/native/config.js +15 -0
- package/dist/agent/native/disqualify.js +43 -3
- package/dist/agent/native/gate.js +78 -8
- package/dist/agent/native/native-issue.js +4 -0
- package/dist/agent/native/paths.js +1 -1
- package/dist/agent/native/policy.js +220 -17
- package/dist/agent/room-page.js +254 -0
- package/dist/agent/room-web-mcp.js +59 -0
- package/dist/agent/serve.js +15 -3
- package/dist/agent/web-guard.js +99 -0
- package/dist/commands/agent-native.js +6 -1
- package/dist/commands/agent-serve.js +2 -1
- package/dist/commands/agent.js +23 -2
- package/dist/gateway-install.js +7 -2
- package/package.json +2 -2
package/dist/agent/adapters.js
CHANGED
|
@@ -10,11 +10,12 @@ import { redactAgentOutput, } from "../agent-link.js";
|
|
|
10
10
|
import { gatewayLauncherPath } from "../gateway-install.js";
|
|
11
11
|
import { providerPathEnv, resolveProviderBinary } from "../provider-binary.js";
|
|
12
12
|
import { codexRoomArgs, ROOM_TOOLS } from "./codex-policy.js";
|
|
13
|
-
import { CodexBoundaryError, probeCodexBoundary } from "./codex-probe.js";
|
|
13
|
+
import { CodexBoundaryError, codexWebProven, probeCodexBoundary, } from "./codex-probe.js";
|
|
14
14
|
import { prepareCodexOwnerLaunch } from "./native/codex-launch.js";
|
|
15
15
|
import { prepareOwnerLaunch } from "./native/launch.js";
|
|
16
16
|
import { readReceipts } from "./native/receipts.js";
|
|
17
17
|
import { classifyProviderFailure, matchFailureText, ProviderFailureError, } from "./provider-failure.js";
|
|
18
|
+
import { READ_PAGE_TOOL, ROOM_WEB_MCP_ENTRY, ROOM_WEB_SERVER, } from "./room-page.js";
|
|
18
19
|
import { prepareRoomProfile, ROOM_CATALOG_FILE, ROOM_MCP_FILE, } from "./room-profile.js";
|
|
19
20
|
const CHILD_ENV = [
|
|
20
21
|
"HOME",
|
|
@@ -35,6 +36,16 @@ const CHILD_ENV = [
|
|
|
35
36
|
const CLAUDE_VERSION = /^\d+\.\d+\.\d+/u;
|
|
36
37
|
const CODEX_VERSION = /\b\d+\.\d+\.\d+\b/u;
|
|
37
38
|
const DONT_ASK = /\bdontAsk\b/u;
|
|
39
|
+
// What the room line says while a job uses web. Neither names a page or a
|
|
40
|
+
// query, and neither is a private tool, so an owner job shows them too.
|
|
41
|
+
const SEARCHING = "Searching the web…";
|
|
42
|
+
const READING = "Reading a page…";
|
|
43
|
+
const WEB_STATUS = {
|
|
44
|
+
[READ_PAGE_TOOL]: READING,
|
|
45
|
+
WebFetch: READING,
|
|
46
|
+
WebSearch: SEARCHING,
|
|
47
|
+
};
|
|
48
|
+
const WEB_LINES = new Set([READING, SEARCHING]);
|
|
38
49
|
// A room-only job needs both to keep the owner's profile and transcripts out.
|
|
39
50
|
const CLAUDE_ISOLATION_FLAGS = [
|
|
40
51
|
"--setting-sources",
|
|
@@ -43,6 +54,12 @@ const CLAUDE_ISOLATION_FLAGS = [
|
|
|
43
54
|
// What Codex prints when the required room server never listed its tools.
|
|
44
55
|
const ROOM_SERVER_FAILED = /required MCP servers failed to initialize/u;
|
|
45
56
|
const CLAUDE_TOOLS = ROOM_TOOLS.map((tool) => `mcp__talentos__${tool}`).join(",");
|
|
57
|
+
// A room job with web: Claude's own search (run by Anthropic, it reads nothing on
|
|
58
|
+
// this computer), no other built-in tool. WebFetch stays out: it would run on the
|
|
59
|
+
// owner's computer and could be pointed at their network (#13155 review). Pages
|
|
60
|
+
// open through read_page instead (room-page.ts: resolve once, connect to that
|
|
61
|
+
// address, every redirect hop checked).
|
|
62
|
+
const CLAUDE_WEB_TOOLS = "WebSearch";
|
|
46
63
|
export function childEnvironment(source = process.env, binary) {
|
|
47
64
|
return {
|
|
48
65
|
...Object.fromEntries(CHILD_ENV.filter((key) => source[key] !== undefined).map((key) => [
|
|
@@ -116,6 +133,29 @@ export async function verifyCodex(configured, signal) {
|
|
|
116
133
|
}
|
|
117
134
|
throw new Error(`Update Codex (${version}) to a version supporting isolated room turns, exec/resume flags and a local model catalog.`);
|
|
118
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Proves this Codex's tool surface with live web search on, after the room
|
|
138
|
+
* proof passed. Optional: a Codex that fails it (or cannot be probed) still
|
|
139
|
+
* serves room jobs, without web, because a job checks the cached result.
|
|
140
|
+
*/
|
|
141
|
+
export async function verifyCodexWeb(configured, signal) {
|
|
142
|
+
try {
|
|
143
|
+
const binary = resolveProviderBinary("codex", configured);
|
|
144
|
+
const { stdout } = await promisify(execFile)(binary, ["--version"], {
|
|
145
|
+
env: childEnvironment(process.env, binary),
|
|
146
|
+
timeout: 5000,
|
|
147
|
+
signal,
|
|
148
|
+
maxBuffer: 256_000,
|
|
149
|
+
});
|
|
150
|
+
const version = CODEX_VERSION.exec(stdout)?.[0];
|
|
151
|
+
if (version) {
|
|
152
|
+
await probeCodexBoundary(binary, version, await codexRoomCatalog(binary), signal, { web: true });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
// Web stays off for this Codex.
|
|
157
|
+
}
|
|
158
|
+
}
|
|
119
159
|
async function codexRoomCatalog(binary) {
|
|
120
160
|
try {
|
|
121
161
|
const { stdout } = await promisify(execFile)(binary, ["debug", "models", "--bundled"], {
|
|
@@ -187,7 +227,9 @@ export function readProviderEvent(provider, value) {
|
|
|
187
227
|
if (event.type === "assistant" &&
|
|
188
228
|
Array.isArray(message?.content) &&
|
|
189
229
|
message.content.some((part) => part.type === "tool_use")) {
|
|
190
|
-
return {
|
|
230
|
+
return {
|
|
231
|
+
status: WEB_STATUS[message.content.find((part) => part.type === "tool_use")?.name ?? ""] ?? "Using room tools…",
|
|
232
|
+
};
|
|
191
233
|
}
|
|
192
234
|
}
|
|
193
235
|
else {
|
|
@@ -212,6 +254,9 @@ export function readProviderEvent(provider, value) {
|
|
|
212
254
|
if (event.type === "item.started" && item?.type === "mcp_tool_call") {
|
|
213
255
|
return { status: "Using room tools…" };
|
|
214
256
|
}
|
|
257
|
+
if (event.type === "item.started" && item?.type === "web_search") {
|
|
258
|
+
return { status: SEARCHING };
|
|
259
|
+
}
|
|
215
260
|
}
|
|
216
261
|
return {};
|
|
217
262
|
}
|
|
@@ -267,6 +312,7 @@ export async function runProvider(input) {
|
|
|
267
312
|
args = ownerLaunch.args;
|
|
268
313
|
}
|
|
269
314
|
else if (config.provider === "claude_code") {
|
|
315
|
+
const web = job.web === true;
|
|
270
316
|
await writePrivateFile(mcpPath, JSON.stringify({
|
|
271
317
|
mcpServers: {
|
|
272
318
|
talentos: {
|
|
@@ -274,6 +320,16 @@ export async function runProvider(input) {
|
|
|
274
320
|
url: new URL("/mcp", config.apiUrl).href,
|
|
275
321
|
headers: { Authorization: `Bearer ${config.apiKey}` },
|
|
276
322
|
},
|
|
323
|
+
// One more server, only with web: it opens public pages and holds no
|
|
324
|
+
// key, login or file access (room-web-mcp.ts).
|
|
325
|
+
...(web
|
|
326
|
+
? {
|
|
327
|
+
[ROOM_WEB_SERVER]: {
|
|
328
|
+
args: [ROOM_WEB_MCP_ENTRY],
|
|
329
|
+
command: process.execPath,
|
|
330
|
+
},
|
|
331
|
+
}
|
|
332
|
+
: {}),
|
|
277
333
|
},
|
|
278
334
|
}));
|
|
279
335
|
// Last step that can fail: nothing after it leaves the job's files behind.
|
|
@@ -296,9 +352,11 @@ export async function runProvider(input) {
|
|
|
296
352
|
"--append-system-prompt",
|
|
297
353
|
instructions,
|
|
298
354
|
"--tools",
|
|
299
|
-
"",
|
|
355
|
+
web ? CLAUDE_WEB_TOOLS : "",
|
|
300
356
|
"--allowedTools",
|
|
301
|
-
|
|
357
|
+
web
|
|
358
|
+
? `${CLAUDE_TOOLS},${CLAUDE_WEB_TOOLS},${READ_PAGE_TOOL}`
|
|
359
|
+
: CLAUDE_TOOLS,
|
|
302
360
|
"--disallowedTools",
|
|
303
361
|
"Bash,Agent,Task",
|
|
304
362
|
"--permission-mode",
|
|
@@ -324,7 +382,12 @@ export async function runProvider(input) {
|
|
|
324
382
|
command = binary;
|
|
325
383
|
const launcher = gatewayLauncherPath();
|
|
326
384
|
const useLauncher = process.platform !== "win32" && existsSync(launcher);
|
|
327
|
-
|
|
385
|
+
const catalog = await codexRoomCatalog(binary);
|
|
386
|
+
await writePrivateFile(catalogPath, catalog);
|
|
387
|
+
// Live search runs on OpenAI's side, but only a Codex whose tool surface
|
|
388
|
+
// was proven with it on may use it; otherwise the job runs without.
|
|
389
|
+
const web = job.web === true &&
|
|
390
|
+
(await (input.codexWebProven ?? codexWebProven)(binary, catalog));
|
|
328
391
|
// Last step that can fail: nothing after it leaves the job's files behind.
|
|
329
392
|
roomProfile = await prepareRoomProfile({
|
|
330
393
|
directory: dirname(workDir),
|
|
@@ -348,6 +411,7 @@ export async function runProvider(input) {
|
|
|
348
411
|
],
|
|
349
412
|
prompt,
|
|
350
413
|
isolated: true,
|
|
414
|
+
web,
|
|
351
415
|
});
|
|
352
416
|
}
|
|
353
417
|
const child = spawn(command, args, {
|
|
@@ -457,7 +521,9 @@ export async function runProvider(input) {
|
|
|
457
521
|
}
|
|
458
522
|
if (event.status) {
|
|
459
523
|
// Room-visible status never names the owner's private tools.
|
|
460
|
-
input.status(ownerLaunch
|
|
524
|
+
input.status(ownerLaunch && !WEB_LINES.has(event.status)
|
|
525
|
+
? "Working on your computer…"
|
|
526
|
+
: event.status);
|
|
461
527
|
}
|
|
462
528
|
if (event.text !== undefined) {
|
|
463
529
|
text = event.text.slice(0, 12_000);
|
|
@@ -6,6 +6,7 @@ export const ROOM_TOOLS = [
|
|
|
6
6
|
"list_threads",
|
|
7
7
|
"reply_route",
|
|
8
8
|
"read_thread",
|
|
9
|
+
"search_room",
|
|
9
10
|
"read_room",
|
|
10
11
|
"write_room_memory",
|
|
11
12
|
"list_room_files",
|
|
@@ -23,11 +24,12 @@ export const ROOM_TOOLS = [
|
|
|
23
24
|
"commit_upload",
|
|
24
25
|
"post_message",
|
|
25
26
|
"post_to_thread",
|
|
27
|
+
"start_thread",
|
|
26
28
|
"share_link",
|
|
27
29
|
"whoami",
|
|
28
30
|
];
|
|
29
31
|
export function codexRoomArgs(input) {
|
|
30
|
-
const { catalogPath, mcpCommand, mcpArgs, prompt, sessionId, isolated } = input;
|
|
32
|
+
const { catalogPath, mcpCommand, mcpArgs, prompt, sessionId, isolated, web } = input;
|
|
31
33
|
const args = [
|
|
32
34
|
"-c",
|
|
33
35
|
'sandbox_mode="read-only"',
|
|
@@ -38,7 +40,7 @@ export function codexRoomArgs(input) {
|
|
|
38
40
|
"-c",
|
|
39
41
|
"features.unified_exec=false",
|
|
40
42
|
"-c",
|
|
41
|
-
|
|
43
|
+
`web_search="${web ? "live" : "disabled"}"`,
|
|
42
44
|
"-c",
|
|
43
45
|
"features.view_image=false",
|
|
44
46
|
"-c",
|
|
@@ -198,31 +198,68 @@ async function identity(binary) {
|
|
|
198
198
|
info.ctimeMs,
|
|
199
199
|
]);
|
|
200
200
|
}
|
|
201
|
-
/**
|
|
202
|
-
|
|
201
|
+
/**
|
|
202
|
+
* A synthetic turn uses no owner login or live API. Inconclusive probes never
|
|
203
|
+
* permit service. With `web` the same proof runs with live web search on: the
|
|
204
|
+
* tool surface must still be the room tools, so a Codex that added a local tool
|
|
205
|
+
* for search fails it and its room jobs run without web.
|
|
206
|
+
*/
|
|
207
|
+
export async function probeCodexBoundary(binary, version, catalog, stop, { web = false } = {}) {
|
|
203
208
|
try {
|
|
204
|
-
await proveCodexBoundary(binary, version, catalog, stop);
|
|
209
|
+
await proveCodexBoundary(binary, version, catalog, stop, web);
|
|
205
210
|
}
|
|
206
211
|
catch {
|
|
207
212
|
throw new CodexBoundaryError(version);
|
|
208
213
|
}
|
|
209
214
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
215
|
+
// The web proof's cache key leaves the version out: a job has the binary and
|
|
216
|
+
// its catalog, and the binary's identity already changes with every update.
|
|
217
|
+
function webProofKey(before, catalog) {
|
|
218
|
+
return digest(JSON.stringify([
|
|
213
219
|
PROBE_REVISION,
|
|
220
|
+
"web",
|
|
214
221
|
RESOURCE_HELPERS,
|
|
215
222
|
before,
|
|
216
|
-
version,
|
|
217
223
|
catalog,
|
|
218
224
|
codexRoomArgs({
|
|
219
225
|
catalogPath: "catalog",
|
|
220
226
|
mcpCommand: "mcp",
|
|
221
227
|
mcpArgs: [],
|
|
222
228
|
prompt: "probe",
|
|
229
|
+
web: true,
|
|
223
230
|
}),
|
|
224
231
|
]));
|
|
225
|
-
|
|
232
|
+
}
|
|
233
|
+
const proofCache = (key) => join(homeDir(), ".talentos", "codex-boundary", `${key}.json`);
|
|
234
|
+
/** Whether this Codex binary passed the proof with live web search on. */
|
|
235
|
+
export async function codexWebProven(binary, catalog) {
|
|
236
|
+
try {
|
|
237
|
+
const key = webProofKey(await identity(binary), catalog);
|
|
238
|
+
return ((await readFile(proofCache(key), "utf8")) ===
|
|
239
|
+
JSON.stringify({ key, safe: true }));
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async function proveCodexBoundary(binary, version, catalog, stop, web = false) {
|
|
246
|
+
const before = await identity(binary);
|
|
247
|
+
const key = web
|
|
248
|
+
? webProofKey(before, catalog)
|
|
249
|
+
: digest(JSON.stringify([
|
|
250
|
+
PROBE_REVISION,
|
|
251
|
+
RESOURCE_HELPERS,
|
|
252
|
+
before,
|
|
253
|
+
version,
|
|
254
|
+
catalog,
|
|
255
|
+
codexRoomArgs({
|
|
256
|
+
catalogPath: "catalog",
|
|
257
|
+
mcpCommand: "mcp",
|
|
258
|
+
mcpArgs: [],
|
|
259
|
+
prompt: "probe",
|
|
260
|
+
}),
|
|
261
|
+
]));
|
|
262
|
+
const cache = proofCache(key);
|
|
226
263
|
try {
|
|
227
264
|
if ((await readFile(cache, "utf8")) === JSON.stringify({ key, safe: true })) {
|
|
228
265
|
return;
|
|
@@ -392,6 +429,7 @@ await server.connect(new StdioServerTransport());`, { mode: 0o600 });
|
|
|
392
429
|
mcpArgs: [mcp, String(turn === 0 ? SLOW_LIST_MS : 0)],
|
|
393
430
|
prompt: "Verify the room boundary.",
|
|
394
431
|
sessionId: session,
|
|
432
|
+
web,
|
|
395
433
|
});
|
|
396
434
|
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"');
|
|
397
435
|
const output = await execute(binary, args, directory, env, signal);
|
|
@@ -26,6 +26,21 @@ export async function readNativeConfig(directory) {
|
|
|
26
26
|
throw error;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
// Why the last owner job on this computer ran room-only, in plain words, kept
|
|
30
|
+
// here and never sent anywhere: `talentos agent native status` prints it. Absent
|
|
31
|
+
// once a later owner job got the owner's setup.
|
|
32
|
+
export const NATIVE_FALLBACK_FILE = "native-fallback.json";
|
|
33
|
+
export async function readNativeFallback(directory) {
|
|
34
|
+
try {
|
|
35
|
+
const value = JSON.parse(await readFile(join(directory, NATIVE_FALLBACK_FILE), "utf8"));
|
|
36
|
+
return typeof value.at === "number" && typeof value.reason === "string"
|
|
37
|
+
? { at: value.at, reason: value.reason }
|
|
38
|
+
: undefined;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
29
44
|
export async function disableNative(directory) {
|
|
30
45
|
await rm(join(directory, NATIVE_FILE), { force: true });
|
|
31
46
|
}
|
|
@@ -8,9 +8,49 @@ const MANAGED = [
|
|
|
8
8
|
"/Library/Application Support/ClaudeCode/managed-settings.json",
|
|
9
9
|
"/etc/claude-code/managed-settings.json",
|
|
10
10
|
];
|
|
11
|
+
// JSON with comments and trailing commas. Claude Code 2.1.308 ignores a settings
|
|
12
|
+
// file written that way, but a tolerant version could apply it, so it is read
|
|
13
|
+
// as a superset: whatever it says about hooks is honoured, never skipped.
|
|
14
|
+
function stripJsonc(text) {
|
|
15
|
+
let out = "";
|
|
16
|
+
let at = 0;
|
|
17
|
+
while (at < text.length) {
|
|
18
|
+
const char = text[at];
|
|
19
|
+
const next = text[at + 1];
|
|
20
|
+
if (char === '"') {
|
|
21
|
+
let end = at + 1;
|
|
22
|
+
while (end < text.length && text[end] !== '"') {
|
|
23
|
+
end += text[end] === "\\" ? 2 : 1;
|
|
24
|
+
}
|
|
25
|
+
out += text.slice(at, end + 1);
|
|
26
|
+
at = end + 1;
|
|
27
|
+
}
|
|
28
|
+
else if (char === "/" && next === "/") {
|
|
29
|
+
const end = text.indexOf("\n", at);
|
|
30
|
+
at = end === -1 ? text.length : end;
|
|
31
|
+
}
|
|
32
|
+
else if (char === "/" && next === "*") {
|
|
33
|
+
const end = text.indexOf("*/", at + 2);
|
|
34
|
+
at = end === -1 ? text.length : end + 2;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
out += char;
|
|
38
|
+
at += 1;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return out.replace(TRAILING_COMMA, "$1");
|
|
42
|
+
}
|
|
43
|
+
const TRAILING_COMMA = /,(\s*[}\]])/gu;
|
|
11
44
|
function readSettings(path) {
|
|
12
45
|
try {
|
|
13
|
-
const
|
|
46
|
+
const raw = readFileSync(path, "utf8");
|
|
47
|
+
let value;
|
|
48
|
+
try {
|
|
49
|
+
value = JSON.parse(raw);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
value = JSON.parse(stripJsonc(raw));
|
|
53
|
+
}
|
|
14
54
|
return value && typeof value === "object" && !Array.isArray(value)
|
|
15
55
|
? value
|
|
16
56
|
: "bad";
|
|
@@ -35,11 +75,11 @@ export function claudeDisqualifier(input) {
|
|
|
35
75
|
for (const file of files) {
|
|
36
76
|
const settings = readSettings(file);
|
|
37
77
|
if (settings === "bad") {
|
|
38
|
-
return
|
|
78
|
+
return `A Claude Code settings file (${file}) could not be read, so the room safety hook cannot be confirmed.`;
|
|
39
79
|
}
|
|
40
80
|
if (settings?.disableAllHooks === true ||
|
|
41
81
|
settings?.allowManagedHooksOnly === true) {
|
|
42
|
-
return
|
|
82
|
+
return `Your Claude Code settings (${file}) turn hooks off, which the room safety check needs.`;
|
|
43
83
|
}
|
|
44
84
|
}
|
|
45
85
|
return;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
+
import { rm } from "node:fs/promises";
|
|
3
4
|
import { join } from "node:path";
|
|
4
5
|
import { promisify } from "node:util";
|
|
6
|
+
import { writePrivateFile, } from "../../agent-config.js";
|
|
5
7
|
import { providerPathEnv, resolveProviderBinary, } from "../../provider-binary.js";
|
|
6
8
|
import { codexFenceEligible, codexFenceVersion, codexUnsupportedMessage, } from "./codex-fence.js";
|
|
7
9
|
import { codexFenceProbeCached, ensureCodexFenceProbe, } from "./codex-fence-probe.js";
|
|
8
10
|
import { codexDisqualifier, codexOwnerContextPresent } from "./codex-owner.js";
|
|
9
|
-
import { NATIVE_FILE, readNativeConfig } from "./config.js";
|
|
11
|
+
import { NATIVE_FALLBACK_FILE, NATIVE_FILE, readNativeConfig, } from "./config.js";
|
|
10
12
|
import { ownerContextPresent } from "./context.js";
|
|
11
13
|
import { claudeDisqualifier } from "./disqualify.js";
|
|
12
14
|
import { loginShellEnv } from "./env.js";
|
|
@@ -16,10 +18,14 @@ import { prepareWorkspace } from "./workspace.js";
|
|
|
16
18
|
const WHITESPACE = /\s+/u;
|
|
17
19
|
const exec = promisify(execFile);
|
|
18
20
|
const ENV_TTL_MS = 10 * 60_000;
|
|
21
|
+
const ENV_MAX_STALE_MS = 60 * 60_000;
|
|
19
22
|
const RETRY_MS = 10 * 60_000;
|
|
20
23
|
export const UNKNOWN_PROJECT = "That project isn't set up on this computer, so I'm working room-only.";
|
|
21
24
|
export const NO_PROJECT = "No project is set up on this computer, so I'm working room-only.";
|
|
22
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 = "Full setup is off on this computer. Run talentos agent native enable to turn it on.";
|
|
27
|
+
export const NOT_READY = "The safety check for your setup hasn't passed on this computer yet. Run talentos agent native enable again, and check talentos agent logs.";
|
|
28
|
+
export const PREPARE_FAILED = "Something went wrong preparing your setup on this computer.";
|
|
23
29
|
export const LOCAL_BASE = "Couldn't get the latest code, so I started from your local copy.";
|
|
24
30
|
/**
|
|
25
31
|
* Everything the owner-native profile needs on this computer, decided here and
|
|
@@ -138,12 +144,41 @@ export class NativeGate {
|
|
|
138
144
|
version: stdout.trim().split(WHITESPACE)[0] ?? "unknown",
|
|
139
145
|
});
|
|
140
146
|
}
|
|
141
|
-
/**
|
|
147
|
+
/**
|
|
148
|
+
* The login-shell env. Within ten minutes of a capture it is reused. For the
|
|
149
|
+
* next hour the last capture is returned at once while a new one is taken in
|
|
150
|
+
* the background, so a job after a short idle spell never waits on the
|
|
151
|
+
* owner's shell startup (an `-ilc` shell loads their rc files and can take
|
|
152
|
+
* seconds). Older than that, the job waits for a fresh capture.
|
|
153
|
+
*/
|
|
142
154
|
loginEnv() {
|
|
143
|
-
|
|
144
|
-
|
|
155
|
+
const current = this.env;
|
|
156
|
+
const age = current ? Date.now() - current.at : Number.POSITIVE_INFINITY;
|
|
157
|
+
if (!current || age > ENV_MAX_STALE_MS) {
|
|
158
|
+
this.env = { at: Date.now(), refreshing: false, value: loginShellEnv() };
|
|
159
|
+
return this.env.value;
|
|
160
|
+
}
|
|
161
|
+
if (age > ENV_TTL_MS && !current.refreshing) {
|
|
162
|
+
current.refreshing = true;
|
|
163
|
+
loginShellEnv()
|
|
164
|
+
.then((value) => {
|
|
165
|
+
this.env = {
|
|
166
|
+
at: Date.now(),
|
|
167
|
+
refreshing: false,
|
|
168
|
+
value: Promise.resolve(value),
|
|
169
|
+
};
|
|
170
|
+
})
|
|
171
|
+
.catch(() => {
|
|
172
|
+
current.refreshing = false;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return current.value;
|
|
176
|
+
}
|
|
177
|
+
/** Takes the first capture now, so the first owner job does not wait for it. */
|
|
178
|
+
prewarmEnv() {
|
|
179
|
+
if (!this.env) {
|
|
180
|
+
this.loginEnv();
|
|
145
181
|
}
|
|
146
|
-
return this.env.value;
|
|
147
182
|
}
|
|
148
183
|
/** The registry, for the heartbeat's id + name mirror; never a path. */
|
|
149
184
|
async projects() {
|
|
@@ -156,9 +191,37 @@ export class NativeGate {
|
|
|
156
191
|
* claim without one (an older server) uses project #1.
|
|
157
192
|
*/
|
|
158
193
|
async prepare(threadId, job = {}) {
|
|
194
|
+
let ready;
|
|
195
|
+
let reason;
|
|
196
|
+
try {
|
|
197
|
+
ready = await this.prepareOwner(threadId, job, (text, told = false) => {
|
|
198
|
+
reason = { told, text };
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
reason = { told: false, text: PREPARE_FAILED };
|
|
203
|
+
}
|
|
204
|
+
if (ready) {
|
|
205
|
+
await rm(join(this.directory, NATIVE_FALLBACK_FILE), {
|
|
206
|
+
force: true,
|
|
207
|
+
}).catch(() => undefined);
|
|
208
|
+
return ready;
|
|
209
|
+
}
|
|
210
|
+
if (reason) {
|
|
211
|
+
// Best effort: the owner's own record never changes how the job ends.
|
|
212
|
+
await writePrivateFile(join(this.directory, NATIVE_FALLBACK_FILE), JSON.stringify({ at: Date.now(), reason: reason.text })).catch(() => undefined);
|
|
213
|
+
// Per call, never on the gate: parallel jobs must not read each other's.
|
|
214
|
+
if (!reason.told) {
|
|
215
|
+
job.fallback?.(reason.text);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
async prepareOwner(threadId, job, fell) {
|
|
159
221
|
this.refresh();
|
|
160
222
|
const config = await readNativeConfig(this.directory);
|
|
161
223
|
if (!config || this.probe !== "ok") {
|
|
224
|
+
fell(config ? NOT_READY : NATIVE_OFF);
|
|
162
225
|
return;
|
|
163
226
|
}
|
|
164
227
|
const env = await this.loginEnv();
|
|
@@ -167,6 +230,7 @@ export class NativeGate {
|
|
|
167
230
|
? await this.codexReady(env, job.codexTested)
|
|
168
231
|
: undefined;
|
|
169
232
|
if (this.agent.provider === "codex" && !codex) {
|
|
233
|
+
fell(NOT_READY);
|
|
170
234
|
return;
|
|
171
235
|
}
|
|
172
236
|
const configDir = env.CLAUDE_CONFIG_DIR || join(this.home, ".claude");
|
|
@@ -175,11 +239,16 @@ export class NativeGate {
|
|
|
175
239
|
? projects[0]
|
|
176
240
|
: projects.find((entry) => entry.id === job.projectId);
|
|
177
241
|
if (!project) {
|
|
178
|
-
|
|
242
|
+
const line = projects.length > 0 ? UNKNOWN_PROJECT : NO_PROJECT;
|
|
243
|
+
job.status?.(line);
|
|
244
|
+
fell(line, true);
|
|
179
245
|
return;
|
|
180
246
|
}
|
|
181
|
-
|
|
182
|
-
|
|
247
|
+
const disqualified = codex
|
|
248
|
+
? undefined
|
|
249
|
+
: claudeDisqualifier({ configDir, projectRoots: [project.root] });
|
|
250
|
+
if (disqualified) {
|
|
251
|
+
fell(disqualified);
|
|
183
252
|
return;
|
|
184
253
|
}
|
|
185
254
|
let workspace;
|
|
@@ -195,6 +264,7 @@ export class NativeGate {
|
|
|
195
264
|
catch {
|
|
196
265
|
// A moved, replaced or missing folder (device + inode) is never guessed at.
|
|
197
266
|
job.status?.(MISSING_PROJECT);
|
|
267
|
+
fell(MISSING_PROJECT, true);
|
|
198
268
|
return;
|
|
199
269
|
}
|
|
200
270
|
if (workspace.base?.tried && !workspace.base.fetched) {
|
|
@@ -1 +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
|
+
/** The neutral room line when an owner job runs room-only, for either provider. */
|
|
3
|
+
export const roomOnlyStatus = (provider) => provider === "codex"
|
|
4
|
+
? ROOM_ONLY_STATUS
|
|
5
|
+
: "Claude Code is answering room-only: full setup isn't available on that computer right now.";
|
|
@@ -52,7 +52,7 @@ const HOME_WRITE_ONLY = [".gitconfig", ".config/git"];
|
|
|
52
52
|
const SECRET_NAME = /^(\.env(\..+)?|\.envrc|\.netrc|\.npmrc|\.pgpass|\.pypirc|\.git-credentials|credentials(\.json)?|id_(rsa|dsa|ecdsa|ed25519)(\.pub)?|.+\.(pem|p12|pfx|key|keystore|jks))$/iu;
|
|
53
53
|
const SECRET_NAME_OK = /\.(example|sample|template|dist)$|\.pub$/iu;
|
|
54
54
|
/** Names that configure the provider, the hook or what runs on commit: the model may read, never write. */
|
|
55
|
-
const WRITE_PROTECTED_SEGMENTS = [
|
|
55
|
+
export const WRITE_PROTECTED_SEGMENTS = [
|
|
56
56
|
".claude",
|
|
57
57
|
".codex",
|
|
58
58
|
".cursor",
|