talentos 1.4.14 → 1.4.16

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.
@@ -0,0 +1,166 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { homeDir } from "../install.js";
4
+ // Where a Hermes Agent login lives (checked against the real CLI, hermes-agent
5
+ // 2026.9): HERMES_HOME (default ~/.hermes) holds config.yaml, whose `model:`
6
+ // block names the provider, model and endpoint (and may hold an inline key);
7
+ // `providers:` holds user-defined endpoints; .env holds provider keys;
8
+ // auth.json holds OAuth state and the credential pool. A room job gets a fresh
9
+ // home, so exactly these carry across: the login and where it points, never the
10
+ // owner's memory, skills, SOUL.md, sessions, plugins, hooks or other settings.
11
+ /**
12
+ * The provider keys Hermes reads from its environment (its config example and
13
+ * provider list). A room job carries one of these, a proxy or CA variable, or a
14
+ * variable the copied `model:`/`providers:` blocks name (an `api_key_env` or a
15
+ * `${VAR}`); nothing else of the owner's environment: not TALENTOS_*, and no
16
+ * cloud or GitHub credentials unless the blocks name that provider. Never
17
+ * written to a file.
18
+ */
19
+ export const HERMES_PROVIDER_KEYS = new Set([
20
+ "AI_GATEWAY_API_KEY",
21
+ "ALIBABA_CODING_PLAN_API_KEY",
22
+ "ANTHROPIC_API_KEY",
23
+ "ARCEEAI_API_KEY",
24
+ "CEREBRAS_API_KEY",
25
+ "DASHSCOPE_API_KEY",
26
+ "DEEPINFRA_API_KEY",
27
+ "DEEPSEEK_API_KEY",
28
+ "FIREWORKS_API_KEY",
29
+ "GEMINI_API_KEY",
30
+ "GLM_API_KEY",
31
+ "GMI_API_KEY",
32
+ "GOOGLE_API_KEY",
33
+ "GROQ_API_KEY",
34
+ "HERMES_CUSTOM_API_KEY",
35
+ "KILOCODE_API_KEY",
36
+ "KIMI_API_KEY",
37
+ "KIMI_CN_API_KEY",
38
+ "KIMI_CODING_API_KEY",
39
+ "LM_API_KEY",
40
+ "MINIMAX_API_KEY",
41
+ "MINIMAX_CN_API_KEY",
42
+ "MISTRAL_API_KEY",
43
+ "NEBIUS_API_KEY",
44
+ "NOUS_API_KEY",
45
+ "NVIDIA_API_KEY",
46
+ "OLLAMA_API_KEY",
47
+ "OPENAI_API_KEY",
48
+ "OPENCODE_GO_API_KEY",
49
+ "OPENCODE_ZEN_API_KEY",
50
+ "OPENROUTER_API_KEY",
51
+ "STEPFUN_API_KEY",
52
+ "TOGETHER_API_KEY",
53
+ "TOKENHUB_API_KEY",
54
+ "UPSTAGE_API_KEY",
55
+ "XAI_API_KEY",
56
+ "XIAOMI_API_KEY",
57
+ "ZAI_API_KEY",
58
+ "Z_AI_API_KEY",
59
+ ]);
60
+ const ROUTING_ENV = /^(?:HERMES_INFERENCE_PROVIDER|(?:HTTPS?|NO|ALL)_PROXY|NODE_EXTRA_CA_CERTS|SSL_CERT_FILE|REQUESTS_CA_BUNDLE)$/iu;
61
+ // A provider whose credentials are not a single key: carried only when the
62
+ // copied blocks name the provider.
63
+ const PROVIDER_GROUPS = [
64
+ {
65
+ env: /^(?:GITHUB_TOKEN|GH_TOKEN|COPILOT_GITHUB_TOKEN)$/u,
66
+ when: /copilot/iu,
67
+ },
68
+ { env: /^AWS_[A-Z0-9_]+$/u, when: /bedrock|aws/iu },
69
+ { env: /^AZURE_[A-Z0-9_]+$/u, when: /azure/iu },
70
+ {
71
+ env: /^GOOGLE_APPLICATION_CREDENTIALS$/u,
72
+ when: /vertex|gcp|google-cloud/iu,
73
+ },
74
+ { env: /^HF_TOKEN$/u, when: /huggingface/iu },
75
+ ];
76
+ const ENV_WORD = /\b[A-Z][A-Z0-9_]{2,}\b/gu;
77
+ /** Does this variable travel with a job whose copied blocks are `blocks`? */
78
+ export function carriesHermesLogin(name, blocks) {
79
+ if (name.startsWith("TALENTOS_")) {
80
+ return false;
81
+ }
82
+ return (HERMES_PROVIDER_KEYS.has(name) ||
83
+ ROUTING_ENV.test(name) ||
84
+ PROVIDER_GROUPS.some((group) => group.env.test(name) && group.when.test(blocks)) ||
85
+ (blocks.match(ENV_WORD) ?? []).includes(name));
86
+ }
87
+ /** OAuth state, linked (never copied): Hermes refreshes the token in place. */
88
+ export const HERMES_CREDENTIAL_FILES = [
89
+ "auth.json",
90
+ ".anthropic_oauth.json",
91
+ ];
92
+ /** The config.yaml blocks that say which model to call and how to sign in. */
93
+ const LOGIN_BLOCKS = ["model", "providers", "custom_providers"];
94
+ const MAX_BLOCK_CHARS = 64_000;
95
+ const ENV_LINE = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$/u;
96
+ const QUOTED = /^(["'])(.*)\1$/u;
97
+ const TOP_LEVEL_KEY = /^([A-Za-z_][\w-]*):/u;
98
+ const SET_MODEL = /^model:\s*\S|^\s+(?:default|model|provider):\s*\S/mu;
99
+ export function hermesDir(env) {
100
+ return env.HERMES_HOME || join(homeDir(env), ".hermes");
101
+ }
102
+ function readText(path) {
103
+ try {
104
+ return readFileSync(path, "utf8");
105
+ }
106
+ catch {
107
+ // Missing or unreadable carries no login; never echo what failed.
108
+ return;
109
+ }
110
+ }
111
+ function parseDotenv(text, carries) {
112
+ const values = {};
113
+ for (const line of text.split("\n")) {
114
+ if (line.trimStart().startsWith("#")) {
115
+ continue;
116
+ }
117
+ const match = ENV_LINE.exec(line);
118
+ if (match?.[1] && carries(match[1])) {
119
+ const raw = match[2] ?? "";
120
+ values[match[1]] = QUOTED.exec(raw)?.[2] ?? raw;
121
+ }
122
+ }
123
+ return values;
124
+ }
125
+ /**
126
+ * The text of the named top-level blocks, copied as written: reading them as
127
+ * YAML would need a parser, and the job only has to hand them back to Hermes.
128
+ * A block ends at the next top-level key.
129
+ */
130
+ export function copyTopLevelBlocks(yaml, names) {
131
+ const kept = [];
132
+ let keeping = false;
133
+ for (const line of yaml.split("\n")) {
134
+ const key = TOP_LEVEL_KEY.exec(line)?.[1];
135
+ if (key) {
136
+ keeping = names.includes(key);
137
+ }
138
+ if (keeping) {
139
+ kept.push(line);
140
+ }
141
+ }
142
+ const text = kept.join("\n").trimEnd();
143
+ return text.length <= MAX_BLOCK_CHARS ? text : "";
144
+ }
145
+ // Synchronous on purpose: three small files, read once per job or once at link.
146
+ export function readHermesLogin(env) {
147
+ const dir = hermesDir(env);
148
+ const blocks = copyTopLevelBlocks(readText(join(dir, "config.yaml")) ?? "", LOGIN_BLOCKS);
149
+ const carries = (name) => carriesHermesLogin(name, blocks);
150
+ const fromProcess = Object.fromEntries(Object.entries(env).filter((entry) => carries(entry[0]) && typeof entry[1] === "string"));
151
+ return {
152
+ blocks,
153
+ dir,
154
+ env: {
155
+ ...parseDotenv(readText(join(dir, ".env")) ?? "", carries),
156
+ ...fromProcess,
157
+ },
158
+ files: HERMES_CREDENTIAL_FILES.filter((name) => existsSync(join(dir, name))),
159
+ };
160
+ }
161
+ /** Does this computer have any way for Hermes to reach a model? */
162
+ export function hermesSignedIn(login) {
163
+ return (SET_MODEL.test(login.blocks) ||
164
+ login.files.includes("auth.json") ||
165
+ Object.keys(login.env).some((name) => HERMES_PROVIDER_KEYS.has(name)));
166
+ }
@@ -0,0 +1,179 @@
1
+ import { execFile } from "node:child_process";
2
+ import { readFile, realpath } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { promisify } from "node:util";
5
+ import { ROOM_TOOLS } from "./codex-policy.js";
6
+ // A Hermes Agent room job's boundary, written as the CLI's own config and
7
+ // toolset selection (verified against hermes-agent 2026.9.24 with its own
8
+ // binary: see docs/features/agent-access/README.md, "Hermes Agent"). Two layers:
9
+ //
10
+ // 1. `-t talentos` selects one toolset: the tools of the one MCP server named
11
+ // `talentos` (Hermes matches `-t` against the `mcp_servers` keys; the
12
+ // `mcp-<server>` spelling is only an alias in some builds and is unknown in
13
+ // others, such as the v2026.9.24 tag). The built-in toolsets (terminal, file, web, browser,
14
+ // memory, skills, code execution, delegation, cron...) are not selected, so
15
+ // the model is never offered them. Hermes puts the MCP tools behind a
16
+ // three-tool bridge (tool_search, tool_describe, tool_call); a call through
17
+ // it to a tool that is not selected is refused ("not available in this
18
+ // execution context").
19
+ // 2. `tools.include` on the server holds the room tools only, so a tool the
20
+ // server lists but a room job may not use is never registered.
21
+ // Without `-t`, the same config offers twenty tools, terminal and file tools
22
+ // among them: the toolset flag is the fence, and the probe checks it on the
23
+ // real binary.
24
+ export const HERMES_SERVER = "talentos";
25
+ export const HERMES_TOOLSET = HERMES_SERVER;
26
+ /** What Hermes calls an MCP tool when the model invokes it through the bridge. */
27
+ export const hermesToolName = (tool) => `mcp__${HERMES_SERVER}__${tool}`;
28
+ /** The three bridge tools Hermes offers in place of the MCP server's tools. */
29
+ export const HERMES_BRIDGE_TOOLS = [
30
+ "tool_search",
31
+ "tool_describe",
32
+ "tool_call",
33
+ ];
34
+ /**
35
+ * The config.yaml of the job's own home: the owner's model and provider blocks
36
+ * as written (so a login that works today keeps working), then the one room
37
+ * server. JSON is valid YAML, so the values are written with JSON.stringify and
38
+ * a key or URL can never break the file. A model block that is empty leaves
39
+ * Hermes to say it is not signed in.
40
+ */
41
+ export function hermesRoomConfig(input) {
42
+ const ours = {
43
+ // Titles a session with a second model call that would carry the packet
44
+ // again; a one-shot job needs none.
45
+ auxiliary: { title_generation: { enabled: false } },
46
+ // Hermes downloads a security scanner binary on first use; a job must not
47
+ // fetch anything but the model's answer.
48
+ security: { tirith_enabled: false },
49
+ // Hermes starts a background gateway for a chat; if it outlives the job it
50
+ // ends itself a few seconds after the last client.
51
+ gateway: { unmanaged_idle_exit_seconds: 5 },
52
+ mcp_servers: {
53
+ [HERMES_SERVER]: {
54
+ headers: { Authorization: `Bearer ${input.apiKey}` },
55
+ tools: {
56
+ // The server lists more than a room job may use: only these are ever
57
+ // registered with the model.
58
+ include: [...ROOM_TOOLS],
59
+ prompts: false,
60
+ resources: false,
61
+ },
62
+ url: input.mcpUrl,
63
+ },
64
+ },
65
+ };
66
+ return `${input.blocks ? `${input.blocks}\n` : ""}${Object.entries(ours)
67
+ .map(([key, value]) => `${key}: ${JSON.stringify(value)}`)
68
+ .join("\n")}\n`;
69
+ }
70
+ /**
71
+ * The launch: one query from stdin, JSON events out, the room toolset alone. No
72
+ * `--yolo`, no `--safe-mode` (it would drop the room server) and no
73
+ * `--ignore-user-config` (the job's config is the room config).
74
+ */
75
+ export function hermesRoomArgs() {
76
+ return [
77
+ "chat",
78
+ "--query-file",
79
+ "-",
80
+ "--format",
81
+ "stream-json",
82
+ "-t",
83
+ HERMES_TOOLSET,
84
+ ];
85
+ }
86
+ const GATEWAY_WAIT_MS = 5000;
87
+ const GATEWAY_POLL_MS = 100;
88
+ const GATEWAY_COMMAND = /\bgateway\b.*\brun\b/u;
89
+ /**
90
+ * Is this `ps` line (command, then environment) a Hermes gateway run for one of
91
+ * these homes? Without the home a recycled pid that is another home's gateway
92
+ * could be signalled.
93
+ */
94
+ export function isGatewayLineFor(line, homes) {
95
+ return (GATEWAY_COMMAND.test(line) &&
96
+ homes.some((home) => line.includes(`HERMES_HOME=${home}`)));
97
+ }
98
+ function alive(pid) {
99
+ try {
100
+ process.kill(pid, 0);
101
+ return true;
102
+ }
103
+ catch (error) {
104
+ // EPERM: it exists and is not ours; ESRCH: it is gone.
105
+ return error.code === "EPERM";
106
+ }
107
+ }
108
+ const canonical = (path) => typeof path === "string" ? realpath(path).catch(() => path) : undefined;
109
+ /**
110
+ * Is `pid` still the process the pid file described? A pid can be recycled once
111
+ * the gateway is gone. Linux: the process start time (clock ticks, field 22 of
112
+ * /proc/<pid>/stat) must equal the record's `start_time`. Elsewhere: its command
113
+ * line must be a Hermes gateway run in this home (`ps -E` shows HERMES_HOME).
114
+ */
115
+ async function isRecordedGateway(pid, startTime, homes) {
116
+ try {
117
+ const stat = await readFile(`/proc/${pid}/stat`, "utf8");
118
+ // The command name is in parentheses and may hold spaces: split after it.
119
+ const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
120
+ return Number(fields[19]) === startTime;
121
+ }
122
+ catch {
123
+ // No /proc (macOS, Windows): ask ps for the command line.
124
+ }
125
+ try {
126
+ // -E appends the environment to the command line (BSD ps).
127
+ const { stdout } = await promisify(execFile)("ps", ["-E", "-ww", "-o", "command=", "-p", String(pid)], { timeout: 3000 });
128
+ return isGatewayLineFor(stdout, homes);
129
+ }
130
+ catch {
131
+ return false;
132
+ }
133
+ }
134
+ /**
135
+ * Stops the background gateway `hermes chat` started for this home. Left alone
136
+ * it holds the home's session database open, so deleting the home leaks the
137
+ * process and the next start on the same path fails. The pid file names the
138
+ * process, its start time and its home; a pid that is not this home's Hermes
139
+ * gateway (another home, or a recycled pid) is never signalled.
140
+ */
141
+ export async function stopHermesGateway(home) {
142
+ let pid;
143
+ try {
144
+ const record = JSON.parse(await readFile(join(home, "gateway.pid"), "utf8"));
145
+ if (record.kind === "hermes-gateway" &&
146
+ (await canonical(record.hermes_home)) === (await canonical(home)) &&
147
+ typeof record.pid === "number" &&
148
+ Number.isInteger(record.pid) &&
149
+ record.pid > 1 &&
150
+ (await isRecordedGateway(record.pid, record.start_time, [
151
+ home,
152
+ String(await canonical(home)),
153
+ ]))) {
154
+ pid = record.pid;
155
+ }
156
+ }
157
+ catch {
158
+ // No gateway was started, or it is already gone.
159
+ return;
160
+ }
161
+ if (pid === undefined) {
162
+ return;
163
+ }
164
+ for (const signal of ["SIGTERM", "SIGKILL"]) {
165
+ try {
166
+ process.kill(pid, signal);
167
+ }
168
+ catch {
169
+ return;
170
+ }
171
+ for (let waited = 0; waited < GATEWAY_WAIT_MS; waited += GATEWAY_POLL_MS) {
172
+ if (!alive(pid)) {
173
+ return;
174
+ }
175
+ await new Promise((resolve) => setTimeout(resolve, GATEWAY_POLL_MS));
176
+ }
177
+ }
178
+ // A process that will not die must not block the end of the job.
179
+ }
@@ -0,0 +1,255 @@
1
+ import { existsSync } from "node:fs";
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 { writePrivateFile } from "../agent-config.js";
7
+ import { ProviderBinaryError } from "../provider-binary.js";
8
+ import { HERMES_BRIDGE_TOOLS, hermesRoomArgs, hermesRoomConfig, hermesToolName, stopHermesGateway, } from "./hermes-policy.js";
9
+ import { cachedProof, closeServer, fakeRoom, listen, NOT_A_ROOM_TOOL, ROOM_TOOL, readBody, runProbeChild, SECRET, } from "./room-probe.js";
10
+ // Proves, against the real binary and with no sign-in, that this Hermes Agent
11
+ // keeps a room job inside its room tools. It runs the exact launch a job uses
12
+ // (same config, same flags) in a throwaway home, pointed at a loopback stand-in
13
+ // for an OpenAI-compatible model and a loopback stand-in for the room endpoint,
14
+ // and checks three things: the tools the model is offered are the room server's
15
+ // alone (behind Hermes' bridge), a model that asks for a shell command or a file
16
+ // read anyway runs nothing and reads nothing (a marker file is not created, a
17
+ // secret is not read into the next request), and the packet reaches the model
18
+ // only in the job's own turn. A Hermes that fails it serves no room job. The
19
+ // result is cached for the binary and its version.
20
+ export class HermesBoundaryError extends ProviderBinaryError {
21
+ constructor(version) {
22
+ super(`Hermes Agent ${version} cannot safely run room jobs. Update Hermes Agent, then run talentos agent repair. If this persists, report this version to TalentOS support.`);
23
+ }
24
+ }
25
+ /**
26
+ * The model was offered no tool at all: Hermes never loaded the room server,
27
+ * which is what an install without its `mcp` package does. Safe, but no job
28
+ * could use the room, so it says what to fix.
29
+ */
30
+ export class HermesMcpMissingError extends HermesBoundaryError {
31
+ constructor(version) {
32
+ super(version);
33
+ this.message = `Hermes Agent ${version} could not load the room tools. Install Hermes with MCP support (the mcp extra: pip install 'hermes-agent[mcp]'), then run talentos agent repair.`;
34
+ }
35
+ }
36
+ const chunk = (delta, finish) => `data: ${JSON.stringify({
37
+ choices: [{ delta, finish_reason: finish, index: 0 }],
38
+ created: 1,
39
+ id: "probe",
40
+ model: "probe",
41
+ object: "chat.completion.chunk",
42
+ })}\n\n`;
43
+ /**
44
+ * The model stand-in. It answers each round with one more thing a room job must
45
+ * not be able to do: a shell command, the same command through Hermes' bridge,
46
+ * a non-room tool of the room server and a file read; then it calls the room
47
+ * tool, which must work. Then it says it is done.
48
+ */
49
+ function fakeModel(seen, secretPath, markerPath) {
50
+ const steps = [
51
+ {
52
+ arguments: { command: `touch ${markerPath}; cat ${secretPath}` },
53
+ name: "terminal",
54
+ },
55
+ // One entry per call: Hermes refuses a whole batch that holds an unknown
56
+ // name, which would test nothing.
57
+ {
58
+ arguments: {
59
+ calls: [
60
+ {
61
+ arguments: { command: `touch ${markerPath}` },
62
+ name: "terminal",
63
+ },
64
+ ],
65
+ },
66
+ name: "tool_call",
67
+ },
68
+ {
69
+ arguments: {
70
+ calls: [{ arguments: {}, name: hermesToolName(NOT_A_ROOM_TOOL) }],
71
+ },
72
+ name: "tool_call",
73
+ },
74
+ { arguments: { path: secretPath }, name: "read_file" },
75
+ // The one thing a room job is for: the room tool works through the fence.
76
+ {
77
+ arguments: {
78
+ calls: [{ arguments: {}, name: hermesToolName(ROOM_TOOL) }],
79
+ },
80
+ name: "tool_call",
81
+ },
82
+ ];
83
+ return createServer(async (request, response) => {
84
+ try {
85
+ const body = await readBody(request);
86
+ if (!request.url?.includes("chat/completions")) {
87
+ response.setHeader("content-type", "application/json");
88
+ response.end(JSON.stringify({ data: [] }));
89
+ return;
90
+ }
91
+ let parsed;
92
+ try {
93
+ parsed = JSON.parse(body);
94
+ }
95
+ catch {
96
+ parsed = null;
97
+ }
98
+ seen.requests.push({
99
+ body,
100
+ tools: (parsed?.tools ?? [])
101
+ .map((tool) => tool.function?.name)
102
+ .filter((name) => typeof name === "string"),
103
+ });
104
+ const round = (parsed?.messages ?? []).filter((message) => message.role === "tool").length;
105
+ const step = steps[round];
106
+ const message = step
107
+ ? {
108
+ content: null,
109
+ role: "assistant",
110
+ tool_calls: [
111
+ {
112
+ function: {
113
+ arguments: JSON.stringify(step.arguments),
114
+ name: step.name,
115
+ },
116
+ id: `call_${round}`,
117
+ type: "function",
118
+ },
119
+ ],
120
+ }
121
+ : { content: "probe done", role: "assistant" };
122
+ if (parsed?.stream) {
123
+ response.setHeader("content-type", "text/event-stream");
124
+ response.write(chunk(message.tool_calls
125
+ ? {
126
+ role: "assistant",
127
+ tool_calls: message.tool_calls.map((call, index) => ({
128
+ ...call,
129
+ index,
130
+ })),
131
+ }
132
+ : message, null));
133
+ response.write(chunk({}, message.tool_calls ? "tool_calls" : "stop"));
134
+ response.end("data: [DONE]\n\n");
135
+ }
136
+ else {
137
+ response.setHeader("content-type", "application/json");
138
+ response.end(JSON.stringify({
139
+ choices: [
140
+ {
141
+ finish_reason: message.tool_calls ? "tool_calls" : "stop",
142
+ index: 0,
143
+ message,
144
+ },
145
+ ],
146
+ created: 1,
147
+ id: "probe",
148
+ model: "probe",
149
+ object: "chat.completion",
150
+ usage: { completion_tokens: 1, prompt_tokens: 1, total_tokens: 2 },
151
+ }));
152
+ }
153
+ }
154
+ catch {
155
+ response.statusCode = 500;
156
+ response.end();
157
+ }
158
+ });
159
+ }
160
+ /** Runs the probe and returns what it saw; `probeHermesBoundary` judges it. */
161
+ export async function runHermesProbe(input) {
162
+ const dir = await mkdtemp(join(tmpdir(), "talentos-hermes-probe-"));
163
+ const seen = { requests: [] };
164
+ const secretPath = join(dir, "secret.txt");
165
+ const markerPath = join(dir, "marker.txt");
166
+ const model = fakeModel(seen, secretPath, markerPath);
167
+ const roomCalls = [];
168
+ const room = fakeRoom(roomCalls);
169
+ const home = join(dir, "home");
170
+ try {
171
+ await writeFile(secretPath, SECRET, { mode: 0o600 });
172
+ const [modelPort, roomPort] = await Promise.all([
173
+ listen(model),
174
+ listen(room),
175
+ ]);
176
+ const work = join(home, "work");
177
+ await mkdir(work, { mode: 0o700, recursive: true });
178
+ await mkdir(join(dir, "user-home"), { mode: 0o700 });
179
+ await writePrivateFile(join(home, "config.yaml"), hermesRoomConfig({
180
+ apiKey: "tos_probe",
181
+ blocks: [
182
+ "model:",
183
+ " default: probe",
184
+ " provider: custom",
185
+ ` base_url: http://127.0.0.1:${modelPort}/v1`,
186
+ " api_key: probe",
187
+ ].join("\n"),
188
+ mcpUrl: `http://127.0.0.1:${roomPort}/mcp`,
189
+ }));
190
+ let finished = false;
191
+ await runProbeChild({
192
+ args: hermesRoomArgs(),
193
+ binary: input.binary,
194
+ cwd: work,
195
+ env: { ...input.env, HERMES_HOME: home, HOME: join(dir, "user-home") },
196
+ onLine: (line) => {
197
+ try {
198
+ const event = JSON.parse(line);
199
+ if (event.type === "result" && event.exit_code === 0) {
200
+ finished = true;
201
+ }
202
+ }
203
+ catch {
204
+ // Not an event line.
205
+ }
206
+ },
207
+ signal: input.signal,
208
+ stdin: '{"probe":true}',
209
+ });
210
+ const offered = seen.requests.filter((request) => request.tools.length > 0);
211
+ return {
212
+ advertised: [...new Set(offered.flatMap((request) => request.tools))],
213
+ commandRan: existsSync(markerPath),
214
+ completed: finished,
215
+ roomCalls,
216
+ secretLeaked: seen.requests.some((request) => request.body.includes(SECRET)),
217
+ };
218
+ }
219
+ finally {
220
+ await stopHermesGateway(home);
221
+ await Promise.all([closeServer(model), closeServer(room)]);
222
+ await rm(dir, { force: true, recursive: true });
223
+ }
224
+ }
225
+ const ALLOWED = new Set([
226
+ ...HERMES_BRIDGE_TOOLS,
227
+ hermesToolName(ROOM_TOOL),
228
+ ]);
229
+ /**
230
+ * Throws HermesBoundaryError unless this binary offered the model only the room
231
+ * server's tools and ran nothing it asked for. Cached per binary and version; a
232
+ * failure is cached too, so a bad Hermes is not retried on every job.
233
+ */
234
+ export function probeHermesBoundary(input) {
235
+ return cachedProof(`hermes:${input.binary}@${input.version}`, () => runHermesProbe(input).then((result) => {
236
+ // Offered nothing and did nothing: Hermes never loaded the room server.
237
+ // A Hermes without its `mcp` package exits with an error here, so the
238
+ // turn need not have finished.
239
+ if (result.advertised.length === 0 &&
240
+ !result.commandRan &&
241
+ !result.secretLeaked) {
242
+ throw new HermesMcpMissingError(input.version);
243
+ }
244
+ if (result.advertised.some((name) => !ALLOWED.has(name)) ||
245
+ result.commandRan ||
246
+ result.secretLeaked ||
247
+ !result.completed ||
248
+ // The room tool ran, and the room server's other tool never did.
249
+ result.roomCalls.join() !== ROOM_TOOL) {
250
+ throw new HermesBoundaryError(input.version);
251
+ }
252
+ }, () => {
253
+ throw new HermesBoundaryError(input.version);
254
+ }));
255
+ }