talentos 1.4.18 → 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.
@@ -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: () => rm(jobDir, { force: true, recursive: true }),
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). It is its own
8
- // small entry so each tool call pays one tiny node start, not the whole CLI.
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
- export const HOOK_ENTRY = fileURLToPath(new URL("./hook-entry.js", import.meta.url));
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: () => rm(jobDir, { force: true, recursive: true }),
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
- export const PROBE_REVISION = 1;
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 = [];
@@ -55,6 +55,26 @@ export async function setupApiOrigin(link, override) {
55
55
  }
56
56
  return apiOrigin(apiUrl);
57
57
  }
58
+ /**
59
+ * Tells the Connect dialog how far this link got, keyed by the prompt's token.
60
+ * Best effort: the setup never waits on it or fails because of it. The API
61
+ * origin is resolved once, on the first report.
62
+ */
63
+ export function linkProgressReporter(link, override) {
64
+ let origin;
65
+ return async (report) => {
66
+ origin ??= setupApiOrigin(link, override).catch(() => undefined);
67
+ const apiUrl = await origin;
68
+ if (!apiUrl) {
69
+ return;
70
+ }
71
+ await safeFetch(`${apiUrl}/agent-link/progress`, {
72
+ body: JSON.stringify({ token: link.token, ...report }),
73
+ headers: { "Content-Type": "application/json" },
74
+ method: "POST",
75
+ }).catch(() => undefined);
76
+ };
77
+ }
58
78
  // A room-only provider with no sign-in status command is checked by what a
59
79
  // sign-in leaves (its profile's signInProblem; Gemini: agent/gemini-login.ts).
60
80
  export function inspectProvider(provider, configured) {
@@ -0,0 +1,114 @@
1
+ import { execFile } from "node:child_process";
2
+ import { createHash, randomUUID } from "node:crypto";
3
+ import { mkdir, readdir, readlink, rename, rm, symlink, writeFile, } from "node:fs/promises";
4
+ import { join } from "node:path";
5
+ import { promisify } from "node:util";
6
+ const exec = promisify(execFile);
7
+ // The gateway's own Node, so the owner's Node, Homebrew or nvm can never stop
8
+ // it (a link on Node 20, a removed nvm version, a Homebrew upgrade past the
9
+ // floor). One pinned release, checked against the sums nodejs.org published for
10
+ // it (SHASUMS256.txt, read 2026-11-04), kept in ~/.talentos/node/<version>
11
+ // with `current` pointing at it. The launcher tries it first after
12
+ // TALENTOS_NODE; the owner's Nodes stay the fallback, so a failed download
13
+ // changes nothing.
14
+ export const BUNDLED_NODE = {
15
+ baseUrl: "https://nodejs.org/dist",
16
+ sha256: {
17
+ "darwin-arm64": "aa9549349e47dffaa42dcf95d6e06ade8c4bdafc980979883b88767670df385a",
18
+ "darwin-x64": "d5e336d588c45be0c37dbd52cc29895593009ca4997a77a1fd02815131ed0e52",
19
+ "linux-arm64": "95c264150aceb7f3437a29fd6984924f5f8d1511ea3cbd6c508b83f6c555dae2",
20
+ "linux-x64": "361718c444e49af2ca5a110c83ba6a8901143f23ab285ebbef0341f391f482a9",
21
+ },
22
+ version: "24.22.2",
23
+ };
24
+ // About 50 MB; a slow link gets the rest of a repair's patience, not forever.
25
+ const DOWNLOAD_MS = 120_000;
26
+ /** The bundled Node the launcher would start, once installed. */
27
+ export function bundledNodePath(home) {
28
+ return join(home, ".talentos", "node", "current", "bin", "node");
29
+ }
30
+ async function runs(node, version) {
31
+ try {
32
+ const { stdout } = await exec(node, ["-p", "process.versions.node"], {
33
+ timeout: 10_000,
34
+ });
35
+ return stdout.trim() === version;
36
+ }
37
+ catch {
38
+ return false;
39
+ }
40
+ }
41
+ /**
42
+ * Installs the pinned Node for this platform if it is not there yet. Best
43
+ * effort: an unknown platform, no network, a checksum mismatch or a broken
44
+ * archive leaves the owner's Node in charge and returns undefined.
45
+ */
46
+ export async function ensureBundledNode(home, options = {}) {
47
+ const release = options.release ?? BUNDLED_NODE;
48
+ const target = `${options.platform ?? process.platform}-${options.arch ?? process.arch}`;
49
+ const expected = release.sha256[target];
50
+ if (!expected) {
51
+ return;
52
+ }
53
+ const root = join(home, ".talentos", "node");
54
+ const name = `v${release.version}`;
55
+ const node = join(root, name, "bin", "node");
56
+ if (!(await runs(node, release.version))) {
57
+ const temporary = join(root, `.install-${randomUUID()}`);
58
+ try {
59
+ await mkdir(temporary, { recursive: true, mode: 0o700 });
60
+ const file = `node-${name}-${target}.tar.gz`;
61
+ const signal = AbortSignal.any([
62
+ AbortSignal.timeout(DOWNLOAD_MS),
63
+ ...(options.signal ? [options.signal] : []),
64
+ ]);
65
+ const response = await (options.fetch ?? fetch)(`${release.baseUrl}/${name}/${file}`, { signal });
66
+ if (!response.ok) {
67
+ return;
68
+ }
69
+ const archive = Buffer.from(await response.arrayBuffer());
70
+ if (createHash("sha256").update(archive).digest("hex") !== expected) {
71
+ return;
72
+ }
73
+ const tarball = join(temporary, file);
74
+ await writeFile(tarball, archive, { mode: 0o600 });
75
+ const unpacked = join(temporary, "unpacked");
76
+ await mkdir(unpacked, { mode: 0o700 });
77
+ // Node itself and npm (gateway updates run it); not the C headers or docs.
78
+ const top = `node-${name}-${target}`;
79
+ await exec("tar", [
80
+ "-xzf",
81
+ tarball,
82
+ "-C",
83
+ unpacked,
84
+ "--strip-components=1",
85
+ `${top}/bin`,
86
+ `${top}/lib`,
87
+ ], { signal, timeout: DOWNLOAD_MS });
88
+ if (!(await runs(join(unpacked, "bin", "node"), release.version))) {
89
+ return;
90
+ }
91
+ await rm(join(root, name), { recursive: true, force: true });
92
+ await rename(unpacked, join(root, name));
93
+ }
94
+ catch {
95
+ return;
96
+ }
97
+ finally {
98
+ await rm(temporary, { recursive: true, force: true });
99
+ }
100
+ }
101
+ const current = join(root, "current");
102
+ if ((await readlink(current).catch(() => "")) !== name) {
103
+ const pointer = join(root, `.current-${randomUUID()}`);
104
+ await symlink(name, pointer);
105
+ await rename(pointer, current);
106
+ }
107
+ // A pin moved on: the old release is no longer started by anything.
108
+ for (const entry of await readdir(root)) {
109
+ if (entry.startsWith("v") && entry !== name) {
110
+ await rm(join(root, entry), { recursive: true, force: true });
111
+ }
112
+ }
113
+ return bundledNodePath(home);
114
+ }
@@ -4,7 +4,7 @@ import { join } from "node:path";
4
4
  import { createInterface } from "node:readline/promises";
5
5
  import { repoRoot } from "../agent/native/config.js";
6
6
  import { agentConfigPath, agentLogPath, agentsDir, agentWorkDir, isMissing, localAgents, storeAgent, writePrivateFile, } from "../agent-config.js";
7
- import { AgentHttpError, fetchAgentStatus, inspectProvider, redeemAgent, setupApiOrigin, unlinkRemoteAgent, waitForHeartbeat, } from "../agent-http.js";
7
+ import { AgentHttpError, fetchAgentStatus, inspectProvider, linkProgressReporter, redeemAgent, setupApiOrigin, unlinkRemoteAgent, waitForHeartbeat, } from "../agent-http.js";
8
8
  import { parseAgentLink, redactAgentOutput } from "../agent-link.js";
9
9
  import { installAgentService, uninstallAgentService, } from "../agent-service.js";
10
10
  import { readSessionKey } from "../agent-session.js";
@@ -143,13 +143,27 @@ export async function runAgent(parsed, dependencies = {}) {
143
143
  }
144
144
  }
145
145
  export async function installLinkedAgent(parsed, dependencies = {}) {
146
+ const link = parseAgentLink(parsed.options.url ?? "");
147
+ // The Connect dialog shows each step and the reason a link stopped (#15553).
148
+ const report = dependencies.reportProgress ??
149
+ linkProgressReporter(link, parsed.options["api-url"] ?? process.env.TALENTOS_API_URL);
150
+ const failed = async (code, error, detail) => {
151
+ await report({ failure: { code, ...(detail ? { detail } : {}) } });
152
+ throw error;
153
+ };
146
154
  if (!meetsNodeFloor(process.versions.node)) {
147
- throw new Error(nodeFloorMessage(process.versions.node));
155
+ await failed("node", new Error(nodeFloorMessage(process.versions.node)), process.versions.node);
148
156
  }
149
- const link = parseAgentLink(parsed.options.url ?? "");
157
+ await report({ stage: "started" });
150
158
  const home = dependencies.home ?? homeDir();
151
159
  const linkHash = hashKey(link.token);
152
- const providerPath = (dependencies.resolveBinary ?? resolveProviderBinary)(link.provider);
160
+ let providerPath = "";
161
+ try {
162
+ providerPath = (dependencies.resolveBinary ?? resolveProviderBinary)(link.provider);
163
+ }
164
+ catch (error) {
165
+ await failed("provider", error);
166
+ }
153
167
  const savedAgents = await localAgents(home);
154
168
  let agent = savedAgents.find((item) => item.linkHash === linkHash && item.provider === link.provider);
155
169
  if (agent) {
@@ -207,7 +221,14 @@ export async function installLinkedAgent(parsed, dependencies = {}) {
207
221
  previousAgentIds: candidates.map((item) => item.agentId),
208
222
  keyHash: hashKey(apiKey),
209
223
  provider: link.provider,
210
- providerVersion: (dependencies.probe ?? inspectProvider)(link.provider, providerPath),
224
+ providerVersion: await (async () => {
225
+ try {
226
+ return (dependencies.probe ?? inspectProvider)(link.provider, providerPath);
227
+ }
228
+ catch (error) {
229
+ return await failed("provider", error);
230
+ }
231
+ })(),
211
232
  deviceName: parsed.options.name ?? defaultDeviceName(),
212
233
  os: process.platform,
213
234
  cliVersion: packageVersion(),
@@ -239,14 +260,22 @@ export async function installLinkedAgent(parsed, dependencies = {}) {
239
260
  agent.connectCwd = connectCwd;
240
261
  await storeAgent(agent, home);
241
262
  }
242
- const service = await (dependencies.install ??
243
- (async (config) => {
244
- if (process.platform !== "win32") {
245
- await installSharedGateway({ home });
246
- }
247
- return await installAgentService(config, { home });
248
- }))(agent);
249
- return { agent, service };
263
+ await report({ stage: "setting_up" });
264
+ let service;
265
+ try {
266
+ service = await (dependencies.install ??
267
+ (async (config) => {
268
+ if (process.platform !== "win32") {
269
+ await installSharedGateway({ home });
270
+ }
271
+ await report({ stage: "starting" });
272
+ return await installAgentService(config, { home });
273
+ }))(agent);
274
+ }
275
+ catch (error) {
276
+ await failed("setup", error);
277
+ }
278
+ return { agent, service: service };
250
279
  }
251
280
  async function showAgents(parsed) {
252
281
  const agents = await selectAgents(parsed);
@@ -6,6 +6,7 @@ import { setTimeout as delay } from "node:timers/promises";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import { promisify } from "node:util";
8
8
  import { writePrivateFile } from "./agent-config.js";
9
+ import { bundledNodePath, ensureBundledNode } from "./bundled-node.js";
9
10
  import { compareGatewayVersions } from "./gateway-version.js";
10
11
  import { homeDir } from "./install.js";
11
12
  const exec = promisify(execFile);
@@ -50,6 +51,7 @@ export async function launcherNodeCandidates(home = homeDir(), env = process.env
50
51
  if (env.TALENTOS_NODE) {
51
52
  found.push(env.TALENTOS_NODE);
52
53
  }
54
+ found.push(bundledNodePath(home));
53
55
  const hint = (await readFile(join(home, ".talentos/cli/node-path"), "utf8").catch(() => "")).split("\n")[0];
54
56
  if (hint) {
55
57
  found.push(hint);
@@ -126,6 +128,10 @@ IFS= read -r node_hint < "$root/cli/node-path" || :
126
128
  if qualifies "\${TALENTOS_NODE:-}"; then
127
129
  start "$TALENTOS_NODE" "$@"
128
130
  fi
131
+ # The gateway's own Node (bundled-node.ts), before any of the owner's.
132
+ if qualifies "$root/node/current/bin/node"; then
133
+ start "$root/node/current/bin/node" "$@"
134
+ fi
129
135
  if qualifies "$node_hint"; then
130
136
  start "$node_hint" "$@"
131
137
  fi
@@ -359,6 +365,10 @@ export async function installSharedGateway(options = {}) {
359
365
  stagedVersion = undefined;
360
366
  const launcher = gatewayLauncherPath(home);
361
367
  await writePrivateFile(launcher, LAUNCHER, 0o700);
368
+ // Best effort: without it the launcher falls back to the owner's Node.
369
+ if (options.bundledNode ?? options.source === undefined) {
370
+ await ensureBundledNode(home, { signal: options.signal });
371
+ }
362
372
  let nodePath = options.nodePath ?? process.execPath;
363
373
  for (const stable of [
364
374
  "/opt/homebrew/bin/node",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "talentos",
3
- "version": "1.4.18",
3
+ "version": "1.4.20",
4
4
  "type": "module",
5
5
  "description": "TalentOS CLI: push and pull skills, read and write team memory, and delegate work to your Talent from any agent.",
6
6
  "repository": {