talentos 1.4.15 → 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.
- package/dist/agent/adapters.js +37 -65
- package/dist/agent/codex-policy.js +2 -0
- package/dist/agent/gemini-probe.js +33 -122
- package/dist/agent/gemini-room.js +92 -0
- package/dist/agent/hermes-login.js +166 -0
- package/dist/agent/hermes-policy.js +179 -0
- package/dist/agent/hermes-probe.js +255 -0
- package/dist/agent/hermes-room.js +99 -0
- package/dist/agent/native/config.js +27 -13
- package/dist/agent/native/gate.js +7 -4
- package/dist/agent/native/projects.js +38 -1
- package/dist/agent/packet-order.js +26 -0
- package/dist/agent/provider-login.js +4 -3
- package/dist/agent/room-probe.js +129 -0
- package/dist/agent/room-profile.js +21 -45
- package/dist/agent/room-provider.js +7 -0
- package/dist/agent/room-providers.js +11 -0
- package/dist/agent-config.js +2 -1
- package/dist/agent-http.js +8 -6
- package/dist/agent-link.js +3 -2
- package/dist/commands/agent-serve.js +6 -6
- package/dist/provider-binary.js +8 -1
- package/package.json +1 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { mkdir, symlink } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { writePrivateFile } from "../agent-config.js";
|
|
4
|
+
import { HERMES_CREDENTIAL_FILES, hermesSignedIn, readHermesLogin, } from "./hermes-login.js";
|
|
5
|
+
import { hermesRoomArgs, hermesRoomConfig, stopHermesGateway, } from "./hermes-policy.js";
|
|
6
|
+
import { HermesBoundaryError, probeHermesBoundary } from "./hermes-probe.js";
|
|
7
|
+
import { matchFailureText } from "./provider-failure.js";
|
|
8
|
+
import { RoomIsolationError, } from "./room-provider.js";
|
|
9
|
+
// What the room launch needs from this Hermes Agent: a query from a file or
|
|
10
|
+
// stdin, JSON events and a toolset selection. They live on `hermes chat`.
|
|
11
|
+
const HERMES_ROOM_FLAGS = [
|
|
12
|
+
"--query-file",
|
|
13
|
+
"--format",
|
|
14
|
+
"stream-json",
|
|
15
|
+
"--toolsets",
|
|
16
|
+
];
|
|
17
|
+
// What a failed run's error says when Hermes has no model to call (no provider,
|
|
18
|
+
// no key): the same "sign in" the other providers report. Its stderr says more
|
|
19
|
+
// ("no API keys or providers found"), which is never read: this error is the
|
|
20
|
+
// only signal.
|
|
21
|
+
const NOT_CONFIGURED = /credentials or agent init failed/iu;
|
|
22
|
+
// stream-json: system/init, text (answer deltas), tool_use, tool_result and one
|
|
23
|
+
// closing result {exit_code, text, error}. A failed run's `text` is Hermes' own
|
|
24
|
+
// prose about the failure, so it is never used as the answer.
|
|
25
|
+
function readHermesEvent(event) {
|
|
26
|
+
if (event.type === "text") {
|
|
27
|
+
return typeof event.text === "string" ? { textDelta: event.text } : {};
|
|
28
|
+
}
|
|
29
|
+
if (event.type === "tool_use") {
|
|
30
|
+
return { status: "Using room tools…", textReset: true };
|
|
31
|
+
}
|
|
32
|
+
if (event.type === "result") {
|
|
33
|
+
const error = typeof event.error === "string" ? event.error : "";
|
|
34
|
+
if (event.exit_code !== 0 || error) {
|
|
35
|
+
return {
|
|
36
|
+
failed: true,
|
|
37
|
+
failure: matchFailureText(error) ??
|
|
38
|
+
(NOT_CONFIGURED.test(error) ? "signed_out" : undefined),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return typeof event.text === "string" ? { text: event.text } : {};
|
|
42
|
+
}
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
async function prepareHermesHome(input, home) {
|
|
46
|
+
const login = readHermesLogin(input.env);
|
|
47
|
+
// Hermes keeps everything under HERMES_HOME; the working directory sits
|
|
48
|
+
// inside it, and Hermes reads context files (AGENTS.md) from the working
|
|
49
|
+
// directory alone, so the room playbook is the job's own AGENTS.md.
|
|
50
|
+
const cwd = join(home, "work");
|
|
51
|
+
await mkdir(cwd, { mode: 0o700, recursive: true });
|
|
52
|
+
await writePrivateFile(join(home, "config.yaml"), hermesRoomConfig({
|
|
53
|
+
apiKey: input.agent.apiKey,
|
|
54
|
+
blocks: login.blocks,
|
|
55
|
+
mcpUrl: input.agent.mcpUrl,
|
|
56
|
+
}));
|
|
57
|
+
// Links, never copies: Hermes refreshes OAuth tokens in place.
|
|
58
|
+
for (const name of HERMES_CREDENTIAL_FILES) {
|
|
59
|
+
if (login.files.includes(name)) {
|
|
60
|
+
await symlink(join(login.dir, name), join(home, name)).catch(() => {
|
|
61
|
+
throw new RoomIsolationError("Hermes Agent");
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
await writePrivateFile(join(cwd, "AGENTS.md"), input.instructions);
|
|
66
|
+
return {
|
|
67
|
+
args: hermesRoomArgs(),
|
|
68
|
+
cwd,
|
|
69
|
+
env: { ...login.env, HERMES_HOME: home },
|
|
70
|
+
home,
|
|
71
|
+
stop: () => stopHermesGateway(home),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export const hermesRoomProfile = {
|
|
75
|
+
helpArgs: ["chat", "--help"],
|
|
76
|
+
isBoundaryError: (error) => error instanceof HermesBoundaryError,
|
|
77
|
+
label: "Hermes Agent",
|
|
78
|
+
async prepare(input) {
|
|
79
|
+
const home = join(input.jobDir, "home");
|
|
80
|
+
try {
|
|
81
|
+
return await prepareHermesHome(input, home);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
// Nothing is running yet, but the contract holds even if a later change
|
|
85
|
+
// starts something before a step that can throw.
|
|
86
|
+
await stopHermesGateway(home).catch(() => undefined);
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
probe: probeHermesBoundary,
|
|
91
|
+
provider: "hermes_agent",
|
|
92
|
+
readEvent: readHermesEvent,
|
|
93
|
+
requiredFlags: HERMES_ROOM_FLAGS,
|
|
94
|
+
signInProblem: (env) => hermesSignedIn(readHermesLogin(env))
|
|
95
|
+
? undefined
|
|
96
|
+
: "Set up the official hermes CLI before linking: run hermes setup once and choose a model provider.",
|
|
97
|
+
versionMayStall: true,
|
|
98
|
+
versionPattern: /\b\d+\.\d+\.\d+\b/u,
|
|
99
|
+
};
|
|
@@ -72,42 +72,56 @@ export async function repoRoot(cwd) {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
|
-
* Why a root may not serve as the agent's workspace
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
75
|
+
* Why a root may not serve as the agent's workspace. Checked at enable time and
|
|
76
|
+
* again before every owner job: the folder must still be the same directory,
|
|
77
|
+
* owned by this user, and neither the home folder nor anything that contains
|
|
78
|
+
* credentials.
|
|
79
|
+
*
|
|
80
|
+
* macOS assigns an APFS volume a new device number when it is remounted (a
|
|
81
|
+
* reboot can do it), so `dev` is not identity: the canonical path and inode
|
|
82
|
+
* are. A device-only change is reported as `repair`, never as a moved folder,
|
|
83
|
+
* and the caller persists the new number where it can.
|
|
79
84
|
*/
|
|
80
|
-
export function
|
|
85
|
+
export function checkWorkspace(config, home) {
|
|
81
86
|
try {
|
|
82
87
|
const real = realpathSync.native(config.root);
|
|
83
88
|
const stats = statSync(real);
|
|
84
89
|
const homeReal = realpathSync.native(home);
|
|
85
90
|
if (!stats.isDirectory()) {
|
|
86
|
-
return "The workspace is not a folder.";
|
|
91
|
+
return { problem: "The workspace is not a folder." };
|
|
87
92
|
}
|
|
88
|
-
if (stats.
|
|
89
|
-
return "The workspace folder changed since it was set up.";
|
|
93
|
+
if (stats.ino !== config.ino) {
|
|
94
|
+
return { problem: "The workspace folder changed since it was set up." };
|
|
90
95
|
}
|
|
91
96
|
if (process.getuid && stats.uid !== process.getuid()) {
|
|
92
|
-
return "The workspace folder is not yours.";
|
|
97
|
+
return { problem: "The workspace folder is not yours." };
|
|
93
98
|
}
|
|
94
99
|
if (real === "/" ||
|
|
95
100
|
real === homeReal ||
|
|
96
101
|
isInside(homeReal, real) ||
|
|
97
102
|
reachesProtected(real, home)) {
|
|
98
|
-
return "The workspace folder is too broad.";
|
|
103
|
+
return { problem: "The workspace folder is too broad." };
|
|
99
104
|
}
|
|
100
105
|
// Inside ~/.ssh, ~/.claude and the like: never a workspace. (Only the
|
|
101
106
|
// folders: a repo merely named like a secrets file is fine.)
|
|
102
107
|
if (protectedPaths(home).readWrite.some((entry) => isInside(real, entry))) {
|
|
103
|
-
return
|
|
108
|
+
return {
|
|
109
|
+
problem: "The workspace folder holds credentials or provider settings.",
|
|
110
|
+
};
|
|
104
111
|
}
|
|
105
|
-
|
|
112
|
+
if (stats.dev !== config.dev) {
|
|
113
|
+
return { repair: { dev: stats.dev, ino: stats.ino } };
|
|
114
|
+
}
|
|
115
|
+
return {};
|
|
106
116
|
}
|
|
107
117
|
catch {
|
|
108
|
-
return "The workspace folder is missing.";
|
|
118
|
+
return { problem: "The workspace folder is missing." };
|
|
109
119
|
}
|
|
110
120
|
}
|
|
121
|
+
/** Why a root may not serve as the agent's workspace, or undefined. */
|
|
122
|
+
export function rootProblem(config, home) {
|
|
123
|
+
return checkWorkspace(config, home).problem;
|
|
124
|
+
}
|
|
111
125
|
/**
|
|
112
126
|
* Records the owner's yes. The workspace is automatic: the repo the command
|
|
113
127
|
* runs in, otherwise ~/TalentOS/<name>-<id>/ (created here, empty).
|
|
@@ -13,7 +13,7 @@ import { ownerContextPresent } from "./context.js";
|
|
|
13
13
|
import { claudeDisqualifier } from "./disqualify.js";
|
|
14
14
|
import { loginShellEnv } from "./env.js";
|
|
15
15
|
import { ensureOwnerNativeProbe, ownerNativeProbeCached } from "./probe.js";
|
|
16
|
-
import { readProjects, registerRoot } from "./projects.js";
|
|
16
|
+
import { readProjects, refreshProjectIdentity, registerRoot, } from "./projects.js";
|
|
17
17
|
import { prepareWorkspace } from "./workspace.js";
|
|
18
18
|
const WHITESPACE = /\s+/u;
|
|
19
19
|
const exec = promisify(execFile);
|
|
@@ -373,9 +373,12 @@ export class NativeGate {
|
|
|
373
373
|
fell(line, true);
|
|
374
374
|
return;
|
|
375
375
|
}
|
|
376
|
+
// A remount can change the volume's device number while the folder (path +
|
|
377
|
+
// inode) stays the same: persist the fresh number before the job runs.
|
|
378
|
+
const ready = await refreshProjectIdentity(this.directory, project);
|
|
376
379
|
const disqualified = codex
|
|
377
380
|
? undefined
|
|
378
|
-
: claudeDisqualifier({ configDir, projectRoots: [
|
|
381
|
+
: claudeDisqualifier({ configDir, projectRoots: [ready.root] });
|
|
379
382
|
if (disqualified) {
|
|
380
383
|
fell(disqualified);
|
|
381
384
|
return;
|
|
@@ -383,7 +386,7 @@ export class NativeGate {
|
|
|
383
386
|
let workspace;
|
|
384
387
|
try {
|
|
385
388
|
workspace = await prepareWorkspace({
|
|
386
|
-
config:
|
|
389
|
+
config: ready,
|
|
387
390
|
env,
|
|
388
391
|
home: this.home,
|
|
389
392
|
onSlow: () => job.status?.("Getting the latest code…"),
|
|
@@ -420,7 +423,7 @@ export class NativeGate {
|
|
|
420
423
|
}),
|
|
421
424
|
env,
|
|
422
425
|
home: this.home,
|
|
423
|
-
project: { id:
|
|
426
|
+
project: { id: ready.id, ...(ready.legacy ? { legacy: true } : {}) },
|
|
424
427
|
workspace,
|
|
425
428
|
};
|
|
426
429
|
}
|
|
@@ -61,7 +61,18 @@ export async function registerRoot(directory, config, name) {
|
|
|
61
61
|
const projects = await readProjects(directory);
|
|
62
62
|
const known = projects.find((project) => project.root === config.root);
|
|
63
63
|
if (known) {
|
|
64
|
-
|
|
64
|
+
if (known.dev === config.dev && known.ino === config.ino) {
|
|
65
|
+
return known;
|
|
66
|
+
}
|
|
67
|
+
// The same folder after a remount keeps its id, name and sessions; only
|
|
68
|
+
// its device number moved.
|
|
69
|
+
const refreshed = {
|
|
70
|
+
...known,
|
|
71
|
+
dev: config.dev,
|
|
72
|
+
ino: config.ino,
|
|
73
|
+
};
|
|
74
|
+
await writeProjects(directory, projects.map((project) => (project === known ? refreshed : project)));
|
|
75
|
+
return refreshed;
|
|
65
76
|
}
|
|
66
77
|
if (projects.length >= PROJECTS_MAX) {
|
|
67
78
|
throw new Error(`An agent can have ${PROJECTS_MAX} projects. Remove one first.`);
|
|
@@ -74,6 +85,32 @@ export async function registerRoot(directory, config, name) {
|
|
|
74
85
|
await writeProjects(directory, [...projects, project]);
|
|
75
86
|
return project;
|
|
76
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Persists a fresh device number for one project when it is still the same
|
|
90
|
+
* folder (canonical path + inode), keeping its id, name and sessions. Called on
|
|
91
|
+
* the owner-job path so a reboot heals the registry instead of leaving it stale.
|
|
92
|
+
*/
|
|
93
|
+
export async function refreshProjectIdentity(directory, project) {
|
|
94
|
+
try {
|
|
95
|
+
const stats = statSync(realpathSync.native(project.root));
|
|
96
|
+
if (stats.ino !== project.ino || stats.dev === project.dev) {
|
|
97
|
+
return project;
|
|
98
|
+
}
|
|
99
|
+
const healed = { ...project, dev: stats.dev, ino: stats.ino };
|
|
100
|
+
const projects = await readProjects(directory);
|
|
101
|
+
const index = projects.findIndex((entry) => entry.id === project.id);
|
|
102
|
+
if (index === -1) {
|
|
103
|
+
return project;
|
|
104
|
+
}
|
|
105
|
+
const next = [...projects];
|
|
106
|
+
next[index] = healed;
|
|
107
|
+
await writeProjects(directory, next);
|
|
108
|
+
return healed;
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return project;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
77
114
|
/**
|
|
78
115
|
* The repo that contains `folder`, checked like `native enable` checks its
|
|
79
116
|
* root: a git top level, the same folder by device and inode, yours, and
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// The keys a job's prompt opens with: the ask and the thread it came from. The
|
|
2
|
+
// thread directory closes it, so the room's other threads read as background
|
|
3
|
+
// after the question, never before it. The server's key order does not survive
|
|
4
|
+
// the trip here, so the launcher fixes the order itself.
|
|
5
|
+
const LEADING_KEYS = ["kind", "trigger", "thread", "transcript"];
|
|
6
|
+
const TRAILING_KEYS = ["threadIndex"];
|
|
7
|
+
export function orderPacketForPrompt(packet) {
|
|
8
|
+
const ordered = {};
|
|
9
|
+
const put = (key) => {
|
|
10
|
+
if (key in packet) {
|
|
11
|
+
ordered[key] = packet[key];
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
for (const key of LEADING_KEYS) {
|
|
15
|
+
put(key);
|
|
16
|
+
}
|
|
17
|
+
for (const key of Object.keys(packet)) {
|
|
18
|
+
if (!(LEADING_KEYS.includes(key) || TRAILING_KEYS.includes(key))) {
|
|
19
|
+
put(key);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
for (const key of TRAILING_KEYS) {
|
|
23
|
+
put(key);
|
|
24
|
+
}
|
|
25
|
+
return ordered;
|
|
26
|
+
}
|
|
@@ -5,8 +5,9 @@ import { promisify } from "node:util";
|
|
|
5
5
|
import { homeDir } from "../install.js";
|
|
6
6
|
import { childEnvironment } from "./adapters.js";
|
|
7
7
|
import { matchFailureText } from "./provider-failure.js";
|
|
8
|
-
// Gemini CLI
|
|
9
|
-
// (gemini-login.ts), so here it is
|
|
8
|
+
// Gemini CLI and Hermes Agent have no status command: their sign-in is read
|
|
9
|
+
// from what they leave (gemini-login.ts, hermes-login.ts), so here it is
|
|
10
|
+
// always "can't tell".
|
|
10
11
|
const STATUS_COMMAND = {
|
|
11
12
|
claude_code: ["auth", "status", "--json"],
|
|
12
13
|
codex: ["login", "status"],
|
|
@@ -81,7 +82,7 @@ export function readProviderLogin(provider, run) {
|
|
|
81
82
|
: undefined;
|
|
82
83
|
}
|
|
83
84
|
export async function probeProviderLogin(input) {
|
|
84
|
-
if (input.provider === "gemini_cli") {
|
|
85
|
+
if (input.provider === "gemini_cli" || input.provider === "hermes_agent") {
|
|
85
86
|
return;
|
|
86
87
|
}
|
|
87
88
|
const args = STATUS_COMMAND[input.provider];
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { createServer } from "node:http";
|
|
3
|
+
import { createInterface } from "node:readline";
|
|
4
|
+
// The parts every provider's boundary probe shares: the loopback stand-in for
|
|
5
|
+
// the room endpoint, the child run with a time limit, and the per-binary cache.
|
|
6
|
+
// The model stand-in is per wire format and lives with the provider's probe
|
|
7
|
+
// (a Gemini one in gemini-probe.ts). Findings the Gemini probe made, which
|
|
8
|
+
// every provider's probe must keep in mind:
|
|
9
|
+
// - a catch-all deny does not remove MCP tools from what the model is offered;
|
|
10
|
+
// - a server marked trusted lets every tool it lists past the policy;
|
|
11
|
+
// - what holds is an include list on the MCP server itself;
|
|
12
|
+
// - the CLI makes a non-streaming routing call first; the stand-in must answer.
|
|
13
|
+
export const PROBE_MS = 45_000;
|
|
14
|
+
export const MAX_BYTES = 2_000_000;
|
|
15
|
+
export const SECRET = "probe-secret-must-never-reach-the-model";
|
|
16
|
+
export const ROOM_TOOL = "whoami";
|
|
17
|
+
export const NOT_A_ROOM_TOOL = "not_a_room_tool";
|
|
18
|
+
export async function readBody(request) {
|
|
19
|
+
let size = 0;
|
|
20
|
+
const chunks = [];
|
|
21
|
+
for await (const chunk of request) {
|
|
22
|
+
size += chunk.length;
|
|
23
|
+
if (size > MAX_BYTES) {
|
|
24
|
+
throw new Error("Probe request exceeded its limit.");
|
|
25
|
+
}
|
|
26
|
+
chunks.push(chunk);
|
|
27
|
+
}
|
|
28
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The room endpoint stand-in: one room tool and one tool that is not a room
|
|
32
|
+
* tool. Names of the tools a model called are pushed onto `calls`, so a probe
|
|
33
|
+
* can tell that the room tool ran and the other one never did.
|
|
34
|
+
*/
|
|
35
|
+
export function fakeRoom(calls = []) {
|
|
36
|
+
return createServer(async (request, response) => {
|
|
37
|
+
const body = await readBody(request).catch(() => "");
|
|
38
|
+
let message = {};
|
|
39
|
+
try {
|
|
40
|
+
message = JSON.parse(body);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// A GET or an empty body: nothing to answer.
|
|
44
|
+
}
|
|
45
|
+
const reply = (result) => {
|
|
46
|
+
response.setHeader("content-type", "application/json");
|
|
47
|
+
response.end(JSON.stringify({ id: message.id, jsonrpc: "2.0", result }));
|
|
48
|
+
};
|
|
49
|
+
const empty = { properties: {}, type: "object" };
|
|
50
|
+
if (message.method === "initialize") {
|
|
51
|
+
reply({
|
|
52
|
+
capabilities: { tools: {} },
|
|
53
|
+
protocolVersion: "2025-03-26",
|
|
54
|
+
serverInfo: { name: "probe", version: "1" },
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
else if (message.method === "tools/list") {
|
|
58
|
+
reply({
|
|
59
|
+
tools: [
|
|
60
|
+
{ description: "who", inputSchema: empty, name: ROOM_TOOL },
|
|
61
|
+
{ description: "no", inputSchema: empty, name: NOT_A_ROOM_TOOL },
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else if (message.method === "tools/call") {
|
|
66
|
+
calls.push(String(message.params?.name));
|
|
67
|
+
reply({ content: [{ text: "ok", type: "text" }] });
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
response.statusCode = 202;
|
|
71
|
+
response.end();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
export function listen(server) {
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
server.once("error", reject);
|
|
78
|
+
server.listen(0, "127.0.0.1", () => resolve(server.address().port));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
export const closeServer = (server) => new Promise((resolve) => {
|
|
82
|
+
server.closeAllConnections?.();
|
|
83
|
+
server.close(() => resolve());
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* Runs the CLI as a job would (packet on stdin, stderr dropped), hands each
|
|
87
|
+
* stdout line to `onLine`, and kills it after PROBE_MS or when `signal` aborts.
|
|
88
|
+
*/
|
|
89
|
+
export async function runProbeChild(input) {
|
|
90
|
+
const child = spawn(input.binary, input.args, {
|
|
91
|
+
cwd: input.cwd,
|
|
92
|
+
env: input.env,
|
|
93
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
94
|
+
});
|
|
95
|
+
// A CLI that exits before reading stdin must fail its probe, not crash the
|
|
96
|
+
// CLI with an unhandled EPIPE.
|
|
97
|
+
child.stdin?.on("error", () => undefined);
|
|
98
|
+
child.stdin?.end(input.stdin);
|
|
99
|
+
const timer = setTimeout(() => child.kill("SIGKILL"), PROBE_MS);
|
|
100
|
+
input.signal?.addEventListener("abort", () => child.kill("SIGKILL"), {
|
|
101
|
+
once: true,
|
|
102
|
+
});
|
|
103
|
+
const lines = createInterface({ input: child.stdout });
|
|
104
|
+
for await (const line of lines) {
|
|
105
|
+
input.onLine(line);
|
|
106
|
+
}
|
|
107
|
+
await new Promise((resolve) => {
|
|
108
|
+
if (child.exitCode === null) {
|
|
109
|
+
child.once("close", () => resolve());
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
resolve();
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
clearTimeout(timer);
|
|
116
|
+
}
|
|
117
|
+
const proofs = new Map();
|
|
118
|
+
/**
|
|
119
|
+
* Runs `prove` once per binary and version and caches the outcome, a failure
|
|
120
|
+
* too, so a bad CLI is not re-probed on every job.
|
|
121
|
+
*/
|
|
122
|
+
export function cachedProof(key, prove) {
|
|
123
|
+
let proof = proofs.get(key);
|
|
124
|
+
if (!proof) {
|
|
125
|
+
proof = prove();
|
|
126
|
+
proofs.set(key, proof);
|
|
127
|
+
}
|
|
128
|
+
return proof;
|
|
129
|
+
}
|
|
@@ -3,9 +3,8 @@ import { access, mkdir, readFile, realpath, rm, rmdir, symlink, } from "node:fs/
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { writePrivateFile } from "../agent-config.js";
|
|
5
5
|
import { homeDir } from "../install.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { ProviderFailureError } from "./provider-failure.js";
|
|
6
|
+
import { RoomIsolationError } from "./room-provider.js";
|
|
7
|
+
import { roomProvider } from "./room-providers.js";
|
|
9
8
|
// The room-only profile (#12712): a job for a teammate, a not-ready owner job
|
|
10
9
|
// and every Codex room job sees what TalentOS hands it (the packet and the room
|
|
11
10
|
// tools) and nothing from the owner's own setup. Each job gets an empty working
|
|
@@ -61,23 +60,15 @@ async function claudeLoginSettings(env) {
|
|
|
61
60
|
: {}),
|
|
62
61
|
};
|
|
63
62
|
}
|
|
64
|
-
/** A provider could not be kept apart from the owner's setup, so no job runs. */
|
|
65
|
-
export class RoomIsolationError extends ProviderFailureError {
|
|
66
|
-
constructor(label = "Codex") {
|
|
67
|
-
super("unknown", `${label} could not be isolated from your setup on this computer.`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
63
|
export async function prepareRoomProfile(input) {
|
|
71
64
|
const jobDir = join(input.directory, ROOM_JOBS, input.jobId.replace(/[^\w-]/gu, ""));
|
|
72
|
-
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
const geminiHome = join(jobDir, "home");
|
|
76
|
-
const cwd = input.provider === "gemini_cli"
|
|
77
|
-
? join(geminiHome, "work")
|
|
78
|
-
: join(jobDir, "cwd");
|
|
65
|
+
const provider = roomProvider(input.provider);
|
|
66
|
+
// A profile builds its own directories; the others get an empty cwd.
|
|
67
|
+
const cwd = join(jobDir, "cwd");
|
|
79
68
|
const profile = {
|
|
80
69
|
cleanup: async () => {
|
|
70
|
+
// A provider's background process goes before the directory it works in.
|
|
71
|
+
await profile.launch?.stop?.().catch(() => undefined);
|
|
81
72
|
await rm(jobDir, { force: true, recursive: true });
|
|
82
73
|
// Claude Code logs under a cache directory named for the cwd: one small
|
|
83
74
|
// directory per job would pile up. Linux and macOS locations only.
|
|
@@ -100,6 +91,20 @@ export async function prepareRoomProfile(input) {
|
|
|
100
91
|
try {
|
|
101
92
|
// A retry of the same job starts from nothing, whatever an earlier attempt left.
|
|
102
93
|
await profile.cleanup();
|
|
94
|
+
if (provider) {
|
|
95
|
+
if (!input.agent) {
|
|
96
|
+
throw new RoomIsolationError(provider.label);
|
|
97
|
+
}
|
|
98
|
+
profile.launch = await provider.prepare({
|
|
99
|
+
agent: input.agent,
|
|
100
|
+
env: input.env,
|
|
101
|
+
instructions: input.instructions ?? "",
|
|
102
|
+
jobDir,
|
|
103
|
+
});
|
|
104
|
+
profile.cwd = profile.launch.cwd;
|
|
105
|
+
profile.env = profile.launch.env;
|
|
106
|
+
return profile;
|
|
107
|
+
}
|
|
103
108
|
await mkdir(cwd, { recursive: true, mode: 0o700 });
|
|
104
109
|
if (input.provider === "claude_code") {
|
|
105
110
|
const login = await claudeLoginSettings(input.env);
|
|
@@ -109,35 +114,6 @@ export async function prepareRoomProfile(input) {
|
|
|
109
114
|
await writePrivateFile(profile.settingsPath, login.file);
|
|
110
115
|
}
|
|
111
116
|
}
|
|
112
|
-
else if (input.provider === "gemini_cli") {
|
|
113
|
-
if (!input.gemini) {
|
|
114
|
-
throw new RoomIsolationError("Gemini CLI");
|
|
115
|
-
}
|
|
116
|
-
const login = readGeminiLogin(input.env);
|
|
117
|
-
const dotGemini = join(geminiHome, ".gemini");
|
|
118
|
-
await mkdir(dotGemini, { mode: 0o700, recursive: true });
|
|
119
|
-
profile.geminiHome = geminiHome;
|
|
120
|
-
profile.env = { ...login.env, GEMINI_CLI_HOME: geminiHome };
|
|
121
|
-
profile.geminiPolicyPath = join(dotGemini, "room-policy.toml");
|
|
122
|
-
await writePrivateFile(profile.geminiPolicyPath, geminiRoomPolicy());
|
|
123
|
-
await writePrivateFile(join(dotGemini, "settings.json"), geminiRoomSettings({
|
|
124
|
-
apiKey: input.gemini.apiKey,
|
|
125
|
-
// An OAuth sign-in with no method named in settings is still OAuth.
|
|
126
|
-
authType: login.authType ??
|
|
127
|
-
(login.files.includes("oauth_creds.json")
|
|
128
|
-
? "oauth-personal"
|
|
129
|
-
: undefined),
|
|
130
|
-
mcpUrl: input.gemini.mcpUrl,
|
|
131
|
-
}));
|
|
132
|
-
// Links, never copies: Gemini refreshes the token in place.
|
|
133
|
-
for (const name of GEMINI_CREDENTIAL_FILES) {
|
|
134
|
-
if (login.files.includes(name)) {
|
|
135
|
-
await symlink(join(login.dir, name), join(dotGemini, name)).catch(() => {
|
|
136
|
-
throw new RoomIsolationError("Gemini CLI");
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
117
|
else {
|
|
142
118
|
profile.codexHome = join(jobDir, "codex-home");
|
|
143
119
|
await mkdir(profile.codexHome, { mode: 0o700 });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ProviderFailureError } from "./provider-failure.js";
|
|
2
|
+
/** A provider could not be kept apart from the owner's setup, so no job runs. */
|
|
3
|
+
export class RoomIsolationError extends ProviderFailureError {
|
|
4
|
+
constructor(label = "Codex") {
|
|
5
|
+
super("unknown", `${label} could not be isolated from your setup on this computer.`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { geminiRoomProfile } from "./gemini-room.js";
|
|
2
|
+
import { hermesRoomProfile } from "./hermes-room.js";
|
|
3
|
+
// Every provider that runs as a room-only profile. Claude Code and Codex are
|
|
4
|
+
// not here: they also run the owner's setup and keep their own launch code.
|
|
5
|
+
const ROOM_PROVIDERS = {
|
|
6
|
+
gemini_cli: geminiRoomProfile,
|
|
7
|
+
hermes_agent: hermesRoomProfile,
|
|
8
|
+
};
|
|
9
|
+
export function roomProvider(provider) {
|
|
10
|
+
return ROOM_PROVIDERS[provider];
|
|
11
|
+
}
|
package/dist/agent-config.js
CHANGED
|
@@ -103,7 +103,8 @@ function isLinkedAgent(value) {
|
|
|
103
103
|
isAbsolute(config.providerPath))) &&
|
|
104
104
|
(config.provider === "claude_code" ||
|
|
105
105
|
config.provider === "codex" ||
|
|
106
|
-
config.provider === "gemini_cli"
|
|
106
|
+
config.provider === "gemini_cli" ||
|
|
107
|
+
config.provider === "hermes_agent"));
|
|
107
108
|
}
|
|
108
109
|
export function isMissing(error) {
|
|
109
110
|
return (error !== null &&
|
package/dist/agent-http.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
2
|
import { childEnvironment } from "./agent/adapters.js";
|
|
3
|
-
import {
|
|
3
|
+
import { roomProvider } from "./agent/room-providers.js";
|
|
4
4
|
import { isSecureUrl, } from "./agent-link.js";
|
|
5
5
|
import { resolveProviderBinary } from "./provider-binary.js";
|
|
6
6
|
const REQUEST_TIMEOUT_MS = 10_000;
|
|
@@ -55,8 +55,8 @@ export async function setupApiOrigin(link, override) {
|
|
|
55
55
|
}
|
|
56
56
|
return apiOrigin(apiUrl);
|
|
57
57
|
}
|
|
58
|
-
//
|
|
59
|
-
// leaves
|
|
58
|
+
// A room-only provider with no sign-in status command is checked by what a
|
|
59
|
+
// sign-in leaves (its profile's signInProblem; Gemini: agent/gemini-login.ts).
|
|
60
60
|
export function inspectProvider(provider, configured) {
|
|
61
61
|
const binary = resolveProviderBinary(provider, configured);
|
|
62
62
|
const version = spawnSync(binary, ["--version"], {
|
|
@@ -67,9 +67,11 @@ export function inspectProvider(provider, configured) {
|
|
|
67
67
|
if (version.status !== 0 || !version.stdout?.trim()) {
|
|
68
68
|
throw new Error(`Install the official ${binary} CLI and sign in before linking.`);
|
|
69
69
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
const room = roomProvider(provider);
|
|
71
|
+
if (room) {
|
|
72
|
+
const problem = room.signInProblem(process.env);
|
|
73
|
+
if (problem) {
|
|
74
|
+
throw new Error(problem);
|
|
73
75
|
}
|
|
74
76
|
return version.stdout.trim().split("\n")[0]?.slice(0, 200) ?? "unknown";
|
|
75
77
|
}
|
package/dist/agent-link.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const INVALID_LINK = "Get a new setup prompt from TalentOS and pass its complete URL with --url.";
|
|
2
|
-
const SETUP_PATH = /^\/agent-setup\/(claude_code|codex|gemini_cli)\/?$/;
|
|
2
|
+
const SETUP_PATH = /^\/agent-setup\/(claude_code|codex|gemini_cli|hermes_agent)\/?$/;
|
|
3
3
|
const FRAGMENT_TOKEN = /((?:#|%23)token(?:=|%3d))[^\s"'<>]+/giu;
|
|
4
4
|
const RAW_KEY = /\btos_[a-z\d_-]+/giu;
|
|
5
5
|
const BEARER = /\bBearer\s+\S+/giu;
|
|
@@ -14,7 +14,8 @@ export function parseAgentLink(value) {
|
|
|
14
14
|
if (!(isSecureUrl(url) &&
|
|
15
15
|
(provider === "claude_code" ||
|
|
16
16
|
provider === "codex" ||
|
|
17
|
-
provider === "gemini_cli"
|
|
17
|
+
provider === "gemini_cli" ||
|
|
18
|
+
provider === "hermes_agent") &&
|
|
18
19
|
!url.search &&
|
|
19
20
|
fragment.size === 1 &&
|
|
20
21
|
tokens.length === 1 &&
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { dirname } from "node:path";
|
|
3
|
-
import { verifyClaudeCode, verifyCodex, verifyCodexImages, verifyCodexWeb,
|
|
3
|
+
import { verifyClaudeCode, verifyCodex, verifyCodexImages, verifyCodexWeb, verifyRoomProvider, } from "../agent/adapters.js";
|
|
4
4
|
import { CodexBoundaryError } from "../agent/codex-probe.js";
|
|
5
5
|
import { AgentGateway, GatewayError } from "../agent/gateway.js";
|
|
6
|
-
import {
|
|
6
|
+
import { roomProvider } from "../agent/room-providers.js";
|
|
7
7
|
import { serveAgent } from "../agent/serve.js";
|
|
8
8
|
import { agentWorkDir, localAgents, storeAgent, } from "../agent-config.js";
|
|
9
9
|
import { AgentHttpError, fetchAgentStatus } from "../agent-http.js";
|
|
@@ -55,6 +55,7 @@ export async function runAgentServe(parsed, options = {}) {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
async function verifyAgent(config, options, signal) {
|
|
58
|
+
const room = roomProvider(config.provider);
|
|
58
59
|
try {
|
|
59
60
|
let binary;
|
|
60
61
|
try {
|
|
@@ -71,8 +72,8 @@ async function verifyAgent(config, options, signal) {
|
|
|
71
72
|
if (config.provider === "claude_code") {
|
|
72
73
|
await verifyClaudeCode(binary);
|
|
73
74
|
}
|
|
74
|
-
else if (
|
|
75
|
-
await
|
|
75
|
+
else if (room) {
|
|
76
|
+
await verifyRoomProvider(room, binary, signal);
|
|
76
77
|
}
|
|
77
78
|
else {
|
|
78
79
|
await verifyCodex(binary, signal);
|
|
@@ -82,8 +83,7 @@ async function verifyAgent(config, options, signal) {
|
|
|
82
83
|
}
|
|
83
84
|
catch (error) {
|
|
84
85
|
if (error instanceof ProviderBinaryError) {
|
|
85
|
-
if (!(error instanceof CodexBoundaryError ||
|
|
86
|
-
error instanceof GeminiBoundaryError)) {
|
|
86
|
+
if (!(error instanceof CodexBoundaryError || room?.isBoundaryError(error))) {
|
|
87
87
|
try {
|
|
88
88
|
await new AgentGateway(config).request("/agent-gateway/provider-unavailable");
|
|
89
89
|
}
|