talentos 1.4.19 → 1.4.20
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/native/codex-launch.js +18 -11
- package/dist/agent/native/hook-client.js +118 -0
- package/dist/agent/native/hook-denial.js +13 -0
- package/dist/agent/native/hook-entry.js +58 -5
- package/dist/agent/native/launch.js +16 -2
- package/dist/agent/native/probe.js +6 -2
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ import { join } from "node:path";
|
|
|
3
3
|
import { writePrivateFile } from "../../agent-config.js";
|
|
4
4
|
import { codexOwnerArgs, ownerCatalog } from "./codex-fence.js";
|
|
5
5
|
import { codexHookArgs, trustHookArgs } from "./codex-owner.js";
|
|
6
|
-
import { HOOK_ENTRY, ownerRules, roomMcpEntry } from "./launch.js";
|
|
6
|
+
import { HOOK_ENTRY, ownerRules, roomMcpEntry, warmHook } from "./launch.js";
|
|
7
7
|
/** The room MCP proxy command for a Codex owner job: adds the owner job dir. */
|
|
8
8
|
export function codexRoomMcpEntry(input) {
|
|
9
9
|
// Claude's entry, so both fall back to the CLI when no launcher is installed.
|
|
@@ -17,15 +17,6 @@ export function codexRoomMcpEntry(input) {
|
|
|
17
17
|
export async function prepareCodexOwnerLaunch(input) {
|
|
18
18
|
const jobDir = join(input.directory, "jobs", input.jobId.replace(/[^\w-]/gu, ""));
|
|
19
19
|
await mkdir(jobDir, { recursive: true, mode: 0o700 });
|
|
20
|
-
await writePrivateFile(join(jobDir, "context.json"), JSON.stringify({
|
|
21
|
-
...(input.askSocket ? { askSocket: input.askSocket } : {}),
|
|
22
|
-
home: input.home,
|
|
23
|
-
...(input.ownAsk ? { ownAsk: true } : {}),
|
|
24
|
-
...(input.roomId ? { roomId: input.roomId } : {}),
|
|
25
|
-
...(input.roomFileIds ? { roomFileIds: input.roomFileIds } : {}),
|
|
26
|
-
...(input.triggerId ? { triggerId: input.triggerId } : {}),
|
|
27
|
-
writeRoots: input.workspace.writeRoots,
|
|
28
|
-
}));
|
|
29
20
|
const catalogPath = join(jobDir, "catalog.json");
|
|
30
21
|
await writePrivateFile(catalogPath, ownerCatalog(input.bundledCatalog));
|
|
31
22
|
// A tiny per-job wrapper so the hook is a single executable path (as Codex's
|
|
@@ -40,6 +31,19 @@ export async function prepareCodexOwnerLaunch(input) {
|
|
|
40
31
|
env: input.env,
|
|
41
32
|
signal: input.signal,
|
|
42
33
|
});
|
|
34
|
+
// Started after the last step that can fail, so a failed launch leaves no
|
|
35
|
+
// listener behind (#13248).
|
|
36
|
+
const warm = await warmHook(jobDir);
|
|
37
|
+
await writePrivateFile(join(jobDir, "context.json"), JSON.stringify({
|
|
38
|
+
...(input.askSocket ? { askSocket: input.askSocket } : {}),
|
|
39
|
+
...(warm ? { hookSocket: warm.socketPath } : {}),
|
|
40
|
+
home: input.home,
|
|
41
|
+
...(input.ownAsk ? { ownAsk: true } : {}),
|
|
42
|
+
...(input.roomId ? { roomId: input.roomId } : {}),
|
|
43
|
+
...(input.roomFileIds ? { roomFileIds: input.roomFileIds } : {}),
|
|
44
|
+
...(input.triggerId ? { triggerId: input.triggerId } : {}),
|
|
45
|
+
writeRoots: input.workspace.writeRoots,
|
|
46
|
+
}));
|
|
43
47
|
const mcp = codexRoomMcpEntry({
|
|
44
48
|
agentId: input.agentId,
|
|
45
49
|
home: input.home,
|
|
@@ -65,7 +69,10 @@ export async function prepareCodexOwnerLaunch(input) {
|
|
|
65
69
|
];
|
|
66
70
|
return {
|
|
67
71
|
args,
|
|
68
|
-
cleanup: () =>
|
|
72
|
+
cleanup: () => {
|
|
73
|
+
warm?.stop();
|
|
74
|
+
return rm(jobDir, { force: true, recursive: true });
|
|
75
|
+
},
|
|
69
76
|
jobDir,
|
|
70
77
|
};
|
|
71
78
|
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { lstatSync, readFileSync } from "node:fs";
|
|
2
|
+
import { connect } from "node:net";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { denial, HOOK_FAILED } from "./hook-denial.js";
|
|
5
|
+
// The per-call half of the owner-native PreToolUse hook (#13248). The provider
|
|
6
|
+
// starts a fresh node for every tool call; loading the policy modules and
|
|
7
|
+
// classifying in it cost ~14 ms of the ~46 ms a call paid. This entry imports
|
|
8
|
+
// only node built-ins and hands the hook input to the job's warm classifier
|
|
9
|
+
// (serveHook in hook-entry.ts, run by the supervisor for the whole job), which
|
|
10
|
+
// runs the same runHook. With no warm classifier it classifies in this process,
|
|
11
|
+
// as before.
|
|
12
|
+
//
|
|
13
|
+
// Fail-closed: once the request is sent, anything but a well-formed decision
|
|
14
|
+
// (a hang-up, a timeout, garbage) is a denial. It never falls back after that
|
|
15
|
+
// point: the warm side may already hold, report or record the call.
|
|
16
|
+
// Just past the warm side's longest hold (HOLD_MS, 14 minutes) and inside the
|
|
17
|
+
// provider's 15 minute hook timeout.
|
|
18
|
+
const ANSWER_MS = 14.5 * 60_000;
|
|
19
|
+
/** The job's warm classifier socket, or undefined to classify in process. */
|
|
20
|
+
function warmSocket(jobDir) {
|
|
21
|
+
try {
|
|
22
|
+
const { hookSocket } = JSON.parse(readFileSync(join(jobDir, "context.json"), "utf8"));
|
|
23
|
+
if (typeof hookSocket !== "string") {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const info = lstatSync(hookSocket);
|
|
27
|
+
return info.isSocket() && (!process.getuid || info.uid === process.getuid())
|
|
28
|
+
? hookSocket
|
|
29
|
+
: undefined;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** The warm side's line if it is a PreToolUse allow or deny, else a denial. */
|
|
36
|
+
function checked(line) {
|
|
37
|
+
try {
|
|
38
|
+
const output = JSON.parse(line).hookSpecificOutput;
|
|
39
|
+
if (output?.hookEventName === "PreToolUse" &&
|
|
40
|
+
(output.permissionDecision === "allow" ||
|
|
41
|
+
output.permissionDecision === "deny")) {
|
|
42
|
+
return line;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// Not a decision.
|
|
47
|
+
}
|
|
48
|
+
return denial(HOOK_FAILED);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Sends `<jobDir as JSON>\n<raw hook input>` and reads one line back.
|
|
52
|
+
* Undefined means it never connected, so nothing reached the warm side.
|
|
53
|
+
*/
|
|
54
|
+
function askWarm(socketPath, jobDir, raw, answerMs) {
|
|
55
|
+
return new Promise((resolve) => {
|
|
56
|
+
let connected = false;
|
|
57
|
+
let settled = false;
|
|
58
|
+
let received = "";
|
|
59
|
+
const finish = (output) => {
|
|
60
|
+
if (!settled) {
|
|
61
|
+
settled = true;
|
|
62
|
+
clearTimeout(timer);
|
|
63
|
+
socket.destroy();
|
|
64
|
+
resolve(output);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const socket = connect(socketPath);
|
|
68
|
+
const timer = setTimeout(() => finish(denial(HOOK_FAILED)), answerMs);
|
|
69
|
+
socket.setEncoding("utf8");
|
|
70
|
+
socket.on("connect", () => {
|
|
71
|
+
connected = true;
|
|
72
|
+
socket.end(`${JSON.stringify(jobDir)}\n${raw}`);
|
|
73
|
+
});
|
|
74
|
+
socket.on("data", (chunk) => {
|
|
75
|
+
received += chunk;
|
|
76
|
+
const end = received.indexOf("\n");
|
|
77
|
+
if (end >= 0) {
|
|
78
|
+
finish(checked(received.slice(0, end)));
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
const lost = () => finish(connected ? denial(HOOK_FAILED) : undefined);
|
|
82
|
+
socket.on("close", lost);
|
|
83
|
+
socket.on("error", lost);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
export async function hookMain(jobDir, raw, answerMs = ANSWER_MS) {
|
|
87
|
+
try {
|
|
88
|
+
const socketPath = warmSocket(jobDir);
|
|
89
|
+
const answer = socketPath === undefined
|
|
90
|
+
? undefined
|
|
91
|
+
: await askWarm(socketPath, jobDir, raw, answerMs);
|
|
92
|
+
if (answer !== undefined) {
|
|
93
|
+
return answer;
|
|
94
|
+
}
|
|
95
|
+
const { runHook } = await import("./hook-entry.js");
|
|
96
|
+
return await runHook(jobDir, raw);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return denial(HOOK_FAILED);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function readStdin() {
|
|
103
|
+
let raw = "";
|
|
104
|
+
process.stdin.setEncoding("utf8");
|
|
105
|
+
for await (const chunk of process.stdin) {
|
|
106
|
+
raw += chunk;
|
|
107
|
+
}
|
|
108
|
+
return raw;
|
|
109
|
+
}
|
|
110
|
+
// No top-level await: an entry still awaiting at the top level never settles
|
|
111
|
+
// if a module it imports imports it back, and node then exits with no answer,
|
|
112
|
+
// which the provider treats as a hook error and runs the call anyway.
|
|
113
|
+
if (/hook-client\.[jt]s$/u.test(process.argv[1] ?? "")) {
|
|
114
|
+
readStdin()
|
|
115
|
+
.then((raw) => hookMain(process.argv[2] ?? "", raw))
|
|
116
|
+
.catch(() => denial(HOOK_FAILED))
|
|
117
|
+
.then((output) => process.stdout.write(output));
|
|
118
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// The hook's own refusal, shared by the per-call client and runHook. Its own
|
|
2
|
+
// module so neither imports the other (#13248): the client imports runHook
|
|
3
|
+
// only when it must classify in process.
|
|
4
|
+
export const HOOK_FAILED = "This action could not be checked, so it did not run. Do not retry; say in one plain line what you could not do.";
|
|
5
|
+
export function denial(reason) {
|
|
6
|
+
return JSON.stringify({
|
|
7
|
+
hookSpecificOutput: {
|
|
8
|
+
hookEventName: "PreToolUse",
|
|
9
|
+
permissionDecision: "deny",
|
|
10
|
+
permissionDecisionReason: reason,
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { appendFileSync, existsSync, lstatSync, mkdirSync, readFileSync, writeFileSync, } from "node:fs";
|
|
3
|
-
import { connect } from "node:net";
|
|
2
|
+
import { appendFileSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync, } from "node:fs";
|
|
3
|
+
import { connect, createServer } from "node:net";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
4
5
|
import { dirname, join } from "node:path";
|
|
6
|
+
import { denial, HOOK_FAILED } from "./hook-denial.js";
|
|
5
7
|
import { classifyCall } from "./policy.js";
|
|
6
8
|
import { readsWeb, taintsJob, touchesPrivate } from "./touch.js";
|
|
7
|
-
// The PreToolUse hook the owner-native profile installs (#10987).
|
|
8
|
-
//
|
|
9
|
+
// The PreToolUse hook the owner-native profile installs (#10987). Each tool call
|
|
10
|
+
// starts hook-client.js, which hands the call to serveHook below, warm in the
|
|
11
|
+
// supervisor for the whole job (#13248), or runs runHook itself.
|
|
9
12
|
// Allowlist-shaped and fail-closed: any error is a denial. It never prints a
|
|
10
13
|
// secret, and it records every decision (tool, tier, outcome, a short redacted
|
|
11
14
|
// target) for the job's receipts.
|
|
@@ -32,7 +35,6 @@ export function dirtyMarker(context) {
|
|
|
32
35
|
}
|
|
33
36
|
// A report is one server round trip; far longer means the server is gone.
|
|
34
37
|
const TOUCH_MS = 20_000;
|
|
35
|
-
export const HOOK_FAILED = "This action could not be checked, so it did not run. Do not retry; say in one plain line what you could not do.";
|
|
36
38
|
const DECLINED = "The owner declined this. Do not retry or work around it; say in your reply what you were trying to do.";
|
|
37
39
|
// The sheet's labels (agent-permissions-dialog.tsx), by the class names the
|
|
38
40
|
// server sends when an Off setting refused an ask (#13236).
|
|
@@ -263,6 +265,57 @@ export async function runHook(jobDir, raw, holdMs = HOLD_MS) {
|
|
|
263
265
|
},
|
|
264
266
|
});
|
|
265
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* The warm classifier for one job (#13248): the per-call hook-client sends
|
|
270
|
+
* `<jobDir as JSON>\n<hook input>` and gets runHook's answer back as one line.
|
|
271
|
+
* runHook reads the job's context and marker afresh on every call, so nothing
|
|
272
|
+
* here is cached. A request for any other job is a denial. Like the ask socket,
|
|
273
|
+
* it lives in a fresh 0700 folder under the system temp folder.
|
|
274
|
+
*/
|
|
275
|
+
export async function serveHook(jobDir, holdMs = HOLD_MS) {
|
|
276
|
+
const directory = mkdtempSync(join(tmpdir(), "tos-"));
|
|
277
|
+
const socketPath = join(directory, "h.sock");
|
|
278
|
+
const open = new Set();
|
|
279
|
+
const server = createServer({ allowHalfOpen: true }, (socket) => {
|
|
280
|
+
open.add(socket);
|
|
281
|
+
let received = "";
|
|
282
|
+
socket.setEncoding("utf8");
|
|
283
|
+
socket.on("data", (chunk) => {
|
|
284
|
+
received += chunk;
|
|
285
|
+
});
|
|
286
|
+
socket.on("end", () => {
|
|
287
|
+
const end = received.indexOf("\n");
|
|
288
|
+
let forJob;
|
|
289
|
+
try {
|
|
290
|
+
forJob = JSON.parse(received.slice(0, end));
|
|
291
|
+
}
|
|
292
|
+
catch {
|
|
293
|
+
// Not a request.
|
|
294
|
+
}
|
|
295
|
+
(end >= 0 && forJob === jobDir
|
|
296
|
+
? runHook(jobDir, received.slice(end + 1), holdMs)
|
|
297
|
+
: Promise.resolve(denial(HOOK_FAILED))).then((output) => socket.end(`${output}\n`), () => socket.destroy());
|
|
298
|
+
});
|
|
299
|
+
socket.on("error", () => socket.destroy());
|
|
300
|
+
socket.on("close", () => open.delete(socket));
|
|
301
|
+
});
|
|
302
|
+
await new Promise((resolve, reject) => {
|
|
303
|
+
server.once("error", reject);
|
|
304
|
+
server.listen(socketPath, resolve);
|
|
305
|
+
});
|
|
306
|
+
// Never what keeps the supervisor alive.
|
|
307
|
+
server.unref();
|
|
308
|
+
return {
|
|
309
|
+
socketPath,
|
|
310
|
+
stop: () => {
|
|
311
|
+
server.close();
|
|
312
|
+
for (const socket of open) {
|
|
313
|
+
socket.destroy();
|
|
314
|
+
}
|
|
315
|
+
rmSync(directory, { force: true, recursive: true });
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
}
|
|
266
319
|
if (process.argv[1]?.endsWith("hook-entry.js")) {
|
|
267
320
|
const jobDir = process.argv[2] ?? "";
|
|
268
321
|
let raw = "";
|
|
@@ -4,11 +4,13 @@ import { join } from "node:path";
|
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { writePrivateFile } from "../../agent-config.js";
|
|
6
6
|
import { gatewayLauncherPath } from "../../gateway-install.js";
|
|
7
|
+
import { serveHook } from "./hook-entry.js";
|
|
7
8
|
// The owner-native launch profile for Claude Code (#10987): the owner's real
|
|
8
9
|
// setup (their config, MCP servers, skills, plugins, CLAUDE.md, model and
|
|
9
10
|
// permission settings) plus the TalentOS room tools and one safety hook.
|
|
10
11
|
// Nothing here strips the owner's configuration.
|
|
11
|
-
|
|
12
|
+
// The per-call entry; it hands each call to the job's warm classifier (#13248).
|
|
13
|
+
export const HOOK_ENTRY = fileURLToPath(new URL("./hook-client.js", import.meta.url));
|
|
12
14
|
export const ROOM_SERVER = "talentos_room";
|
|
13
15
|
// Servers and tools a room job must never reach, whatever the owner has
|
|
14
16
|
// configured: their personal-key TalentOS server (owner authority) and the
|
|
@@ -47,8 +49,10 @@ export function roomMcpEntry(agentId, home, uploadRoot) {
|
|
|
47
49
|
export async function prepareOwnerLaunch(input) {
|
|
48
50
|
const jobDir = join(input.directory, "jobs", input.jobId.replace(/[^\w-]/gu, ""));
|
|
49
51
|
await mkdir(jobDir, { recursive: true, mode: 0o700 });
|
|
52
|
+
const warm = await warmHook(jobDir);
|
|
50
53
|
await writePrivateFile(join(jobDir, "context.json"), JSON.stringify({
|
|
51
54
|
...(input.askSocket ? { askSocket: input.askSocket } : {}),
|
|
55
|
+
...(warm ? { hookSocket: warm.socketPath } : {}),
|
|
52
56
|
home: input.home,
|
|
53
57
|
...(input.ownAsk ? { ownAsk: true } : {}),
|
|
54
58
|
...(input.roomId ? { roomId: input.roomId } : {}),
|
|
@@ -101,7 +105,17 @@ export async function prepareOwnerLaunch(input) {
|
|
|
101
105
|
}
|
|
102
106
|
return {
|
|
103
107
|
args,
|
|
104
|
-
cleanup: () =>
|
|
108
|
+
cleanup: () => {
|
|
109
|
+
warm?.stop();
|
|
110
|
+
return rm(jobDir, { force: true, recursive: true });
|
|
111
|
+
},
|
|
105
112
|
jobDir,
|
|
106
113
|
};
|
|
107
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* The job's warm classifier, or undefined when it cannot listen: each call is
|
|
117
|
+
* then classified in its own process, as before (#13248).
|
|
118
|
+
*/
|
|
119
|
+
export function warmHook(jobDir) {
|
|
120
|
+
return serveHook(jobDir).catch(() => undefined);
|
|
121
|
+
}
|
|
@@ -8,7 +8,7 @@ import { join } from "node:path";
|
|
|
8
8
|
import { writePrivateFile } from "../../agent-config.js";
|
|
9
9
|
import { providerPathEnv } from "../../provider-binary.js";
|
|
10
10
|
import { ApprovalBridge } from "./approvals.js";
|
|
11
|
-
import { HOOK_ENTRY, ROOM_SERVER } from "./launch.js";
|
|
11
|
+
import { HOOK_ENTRY, ROOM_SERVER, warmHook } from "./launch.js";
|
|
12
12
|
// The behavioural proof the owner-native profile rests on (#10987, R12 R3/R4).
|
|
13
13
|
// A real `claude` runs against a loopback Messages API that scripts tool calls,
|
|
14
14
|
// in an isolated HOME and config, with our hook installed exactly as in a job.
|
|
@@ -16,7 +16,8 @@ import { HOOK_ENTRY, ROOM_SERVER } from "./launch.js";
|
|
|
16
16
|
// refusal to hold, in every permission mode and for subagent calls too.
|
|
17
17
|
// Cached per binary identity, version, probe revision and hook code; a changed
|
|
18
18
|
// rule or provider re-proves it. Never run per job.
|
|
19
|
-
|
|
19
|
+
// 2: the hook runs through the job's warm classifier, as in a job (#13248).
|
|
20
|
+
export const PROBE_REVISION = 2;
|
|
20
21
|
const PROBE_MS = 45_000;
|
|
21
22
|
const SUB_MARK = "TALENTOS_SUBAGENT_PROBE";
|
|
22
23
|
const MODEL = "claude-sonnet-4-5";
|
|
@@ -147,8 +148,10 @@ export async function runScenario(binary, scenario, hookEntry) {
|
|
|
147
148
|
},
|
|
148
149
|
statusEveryMs: 50,
|
|
149
150
|
}).start();
|
|
151
|
+
const warm = await warmHook(jobDir);
|
|
150
152
|
await writeFile(join(jobDir, "context.json"), JSON.stringify({
|
|
151
153
|
askSocket: owner.socketPath,
|
|
154
|
+
...(warm ? { hookSocket: warm.socketPath } : {}),
|
|
152
155
|
home,
|
|
153
156
|
writeRoots: [realpathSync.native(work)],
|
|
154
157
|
}));
|
|
@@ -286,6 +289,7 @@ export async function runScenario(binary, scenario, hookEntry) {
|
|
|
286
289
|
await new Promise((resolve) => child.once("close", () => resolve()));
|
|
287
290
|
clearTimeout(timer);
|
|
288
291
|
owner?.stop();
|
|
292
|
+
warm?.stop();
|
|
289
293
|
server.closeAllConnections();
|
|
290
294
|
await new Promise((resolve) => server.close(() => resolve()));
|
|
291
295
|
const initServers = [];
|
package/package.json
CHANGED