talentos 1.4.10 → 1.4.12
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/README.md +3 -3
- package/dist/agent/adapters.js +207 -14
- package/dist/agent/codex-policy.js +22 -0
- package/dist/agent/codex-probe.js +114 -30
- package/dist/agent/gemini-login.js +74 -0
- package/dist/agent/gemini-policy.js +91 -0
- package/dist/agent/gemini-probe.js +308 -0
- package/dist/agent/mcp-entry.js +22 -9
- package/dist/agent/native/approvals.js +15 -11
- package/dist/agent/native/codex-launch.js +3 -0
- package/dist/agent/native/config.js +4 -2
- package/dist/agent/native/gate.js +160 -8
- package/dist/agent/native/hook-entry.js +33 -8
- package/dist/agent/native/launch.js +3 -0
- package/dist/agent/native/native-issue.js +3 -3
- package/dist/agent/native/policy.js +62 -14
- package/dist/agent/native/probe.js +13 -1
- package/dist/agent/native/touch.js +33 -1
- package/dist/agent/node-floor.js +140 -0
- package/dist/agent/provider-failure.js +2 -2
- package/dist/agent/provider-login.js +134 -0
- package/dist/agent/room-profile.js +41 -4
- package/dist/agent/serve.js +75 -9
- package/dist/agent-config.js +6 -1
- package/dist/agent-http.js +57 -0
- package/dist/agent-link.js +4 -2
- package/dist/agent-session.js +137 -0
- package/dist/args.js +1 -0
- package/dist/client.js +11 -2
- package/dist/commands/agent-native.js +0 -3
- package/dist/commands/agent-serve.js +7 -2
- package/dist/commands/agent-session.js +160 -0
- package/dist/commands/agent.js +37 -3
- package/dist/commands/init.js +2 -2
- package/dist/commands/login.js +2 -2
- package/dist/gateway-install.js +50 -11
- package/dist/index.js +13 -4
- package/dist/install.js +39 -14
- package/dist/mcp-proxy.js +30 -2
- package/dist/provider-binary.js +12 -2
- package/package.json +2 -2
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import { launcherNodeCandidates, npmSpawnEnv } from "../gateway-install.js";
|
|
4
|
+
import { compareGatewayVersions } from "../gateway-version.js";
|
|
5
|
+
const exec = promisify(execFile);
|
|
6
|
+
const NPM_VIEW_TIMEOUT_MS = 15_000;
|
|
7
|
+
// Only the grammar `engines.node` uses here: `||` sets of space-separated
|
|
8
|
+
// comparators. Anything else (^, ~, x, hyphen ranges) is "can't tell".
|
|
9
|
+
const COMPARATOR = /^(>=|<=|>|<|=)?(\d+)(?:\.(\d+))?(?:\.(\d+))?$/u;
|
|
10
|
+
const WHITESPACE = /\s+/u;
|
|
11
|
+
const NODE_RANGE = /^[\w<>=.|\s-]{1,200}$/u;
|
|
12
|
+
function compareTriples(a, b) {
|
|
13
|
+
return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
14
|
+
}
|
|
15
|
+
function satisfiesComparator(node, token) {
|
|
16
|
+
const match = COMPARATOR.exec(token);
|
|
17
|
+
if (!match) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const [, operator = "=", major, minor, patch] = match;
|
|
21
|
+
const partial = minor === undefined || patch === undefined;
|
|
22
|
+
const bound = [Number(major), Number(minor ?? 0), Number(patch ?? 0)];
|
|
23
|
+
const difference = compareTriples(node, bound);
|
|
24
|
+
if (operator === ">=") {
|
|
25
|
+
return difference >= 0;
|
|
26
|
+
}
|
|
27
|
+
if (operator === "<") {
|
|
28
|
+
return difference < 0;
|
|
29
|
+
}
|
|
30
|
+
// A partial bound on the others means "the whole 22.x", which this does not
|
|
31
|
+
// model.
|
|
32
|
+
if (partial) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (operator === ">") {
|
|
36
|
+
return difference > 0;
|
|
37
|
+
}
|
|
38
|
+
return operator === "<=" ? difference <= 0 : difference === 0;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Whether `nodeVersion` satisfies an `engines.node` range: true, false, or
|
|
42
|
+
* undefined when the range is outside the small grammar read here, so the
|
|
43
|
+
* caller never blocks on a range it did not understand.
|
|
44
|
+
*/
|
|
45
|
+
export function nodeSatisfies(range, nodeVersion) {
|
|
46
|
+
const node = nodeVersion.split(".").map(Number);
|
|
47
|
+
if (!NODE_RANGE.test(range) ||
|
|
48
|
+
node.length !== 3 ||
|
|
49
|
+
node.some((part) => !Number.isInteger(part))) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
let unknown = false;
|
|
53
|
+
for (const set of range.split("||")) {
|
|
54
|
+
const results = set
|
|
55
|
+
.trim()
|
|
56
|
+
.split(WHITESPACE)
|
|
57
|
+
.map((token) => satisfiesComparator(node, token));
|
|
58
|
+
if (results.length === 0 || results.includes(undefined)) {
|
|
59
|
+
unknown = true;
|
|
60
|
+
}
|
|
61
|
+
else if (results.every(Boolean)) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return unknown ? undefined : false;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The `engines.node` range the registry publishes for a CLI version, or
|
|
69
|
+
* undefined when it cannot be read (offline, npm missing, no range): the
|
|
70
|
+
* caller then updates as before and never goes offline over a metadata miss.
|
|
71
|
+
*/
|
|
72
|
+
export async function targetNodeRange(version, signal) {
|
|
73
|
+
// The version reaches a shell on Windows, so only a plain version passes.
|
|
74
|
+
if (compareGatewayVersions(version, version) === undefined) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const windows = process.platform === "win32";
|
|
78
|
+
try {
|
|
79
|
+
const { stdout } = await exec(windows ? "npm.cmd" : "npm", ["view", `talentos@${version}`, "engines.node", "--json"], {
|
|
80
|
+
env: npmSpawnEnv(),
|
|
81
|
+
shell: windows,
|
|
82
|
+
signal,
|
|
83
|
+
timeout: NPM_VIEW_TIMEOUT_MS,
|
|
84
|
+
});
|
|
85
|
+
const range = JSON.parse(stdout.trim() || "null");
|
|
86
|
+
return typeof range === "string" && range.length <= 200 ? range : undefined;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const PROBE_TIMEOUT_MS = 3000;
|
|
93
|
+
// The whole candidate walk is bounded: a hung Node must not hold up claims.
|
|
94
|
+
const PROBE_BUDGET_MS = 10_000;
|
|
95
|
+
const NODE_VERSION = /^\d{1,3}\.\d{1,3}\.\d{1,3}$/u;
|
|
96
|
+
/** The version a Node executable runs, as the launcher asks it; undefined when it is missing, not executable or silent. */
|
|
97
|
+
export async function probeNodeVersion(path, signal) {
|
|
98
|
+
try {
|
|
99
|
+
const { stdout } = await exec(path, ["-p", "process.versions.node"], {
|
|
100
|
+
signal,
|
|
101
|
+
timeout: PROBE_TIMEOUT_MS,
|
|
102
|
+
});
|
|
103
|
+
const version = stdout.trim();
|
|
104
|
+
return NODE_VERSION.test(version) ? version : undefined;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Whether installing `version` would leave this computer unable to start it:
|
|
112
|
+
* `engines.node` excludes the running Node AND every other Node the launcher
|
|
113
|
+
* would start (its own candidate list, probed). Anything unreadable, or a range
|
|
114
|
+
* outside the grammar read here, is not a block.
|
|
115
|
+
*/
|
|
116
|
+
export async function nodeBlocksUpdate(version, options = {}) {
|
|
117
|
+
const nodeVersion = options.nodeVersion ?? process.versions.node;
|
|
118
|
+
const range = await (options.range ?? targetNodeRange)(version, options.signal);
|
|
119
|
+
if (!range || nodeSatisfies(range, nodeVersion) !== false) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const probe = options.probe ?? probeNodeVersion;
|
|
123
|
+
const deadline = Date.now() + PROBE_BUDGET_MS;
|
|
124
|
+
for (const candidate of await (options.candidates?.() ??
|
|
125
|
+
launcherNodeCandidates())) {
|
|
126
|
+
if (Date.now() >= deadline || options.signal?.aborted) {
|
|
127
|
+
// Out of time to look is not proof that none qualifies.
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const found = await probe(candidate, options.signal);
|
|
131
|
+
if (found && nodeSatisfies(range, found) !== false) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
forVersion: version,
|
|
137
|
+
range,
|
|
138
|
+
message: `TalentOS CLI ${version} needs Node ${range}; this computer runs ${nodeVersion}. Update Node, then run npx talentos@${version} agent repair.`,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
@@ -13,8 +13,8 @@ export const PROVIDER_FAILURE_REASONS = [
|
|
|
13
13
|
"crashed",
|
|
14
14
|
"unknown",
|
|
15
15
|
];
|
|
16
|
-
const SIGNED_OUT = /invalid api key|run \/login|codex login|not logged in|not signed in|log(?:ged)? in again|unauthori[sz]ed|(?:status|http|error|code)[ :]+401\b|authentication[_ ](?:failed|error)|oauth token (?:has )?expired|token[_ ](?:has )?expired|refresh token/iu;
|
|
17
|
-
const USAGE_LIMIT = /usage limit|hit your limit|limit reached|rate[_ ]limit|(?:status|http|error|code)[ :]+429\b|credit balance|quota|billing[_ ]error|out of credits|insufficient[_ ]credit/iu;
|
|
16
|
+
const SIGNED_OUT = /invalid api key|run \/login|codex login|not logged in|not signed in|log(?:ged)? in again|unauthori[sz]ed|(?:status|http|error|code)[ :]+401\b|authentication[_ ](?:failed|error)|oauth token (?:has )?expired|token[_ ](?:has )?expired|refresh token|api key not valid|api_key_invalid|set an auth method|unauthenticated/iu;
|
|
17
|
+
const USAGE_LIMIT = /usage limit|hit your limit|limit reached|rate[_ ]limit|(?:status|http|error|code)[ :]+429\b|credit balance|quota|billing[_ ]error|out of credits|insufficient[_ ]credit|resource_exhausted/iu;
|
|
18
18
|
const CRASHED = /\bpanicked\b|segmentation fault|fatal error|out of memory|uncaught exception|^\s+at .+\(.+:\d+:\d+\)$/imu;
|
|
19
19
|
// 126 is "found but not executable"; 127 is the shell's "command not found".
|
|
20
20
|
const NOT_STARTED = new Set(["ENOENT", "EACCES", "ENOTDIR"]);
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { homeDir } from "../install.js";
|
|
6
|
+
import { childEnvironment } from "./adapters.js";
|
|
7
|
+
import { matchFailureText } from "./provider-failure.js";
|
|
8
|
+
// Gemini CLI has no status command: its sign-in is read from what it leaves
|
|
9
|
+
// (gemini-login.ts), so here it is always "can't tell".
|
|
10
|
+
const STATUS_COMMAND = {
|
|
11
|
+
claude_code: ["auth", "status", "--json"],
|
|
12
|
+
codex: ["login", "status"],
|
|
13
|
+
};
|
|
14
|
+
const PROBE_MS = 5000;
|
|
15
|
+
// Signed in, so how long a yes is believed. A no is asked again each heartbeat,
|
|
16
|
+
// so a person who just signed in sees it clear within seconds.
|
|
17
|
+
const SIGNED_IN_TTL_MS = 5 * 60_000;
|
|
18
|
+
// Claude Code's own routing and keys: a login the status command can't see
|
|
19
|
+
// (an API key, an OAuth token, a helper, Bedrock or Vertex), so its "not logged
|
|
20
|
+
// in" proves nothing about whether a job runs.
|
|
21
|
+
const OTHER_LOGINS = /^(?:ANTHROPIC_(?:API_KEY|AUTH_TOKEN)|CLAUDE_CODE_OAUTH_TOKEN$|CLAUDE_CODE_USE_|OPENAI_API_KEY$|CODEX_API_KEY$)/iu;
|
|
22
|
+
// Claude Code's user settings can hold a login the status command never looks
|
|
23
|
+
// at (a key helper, a cloud credential command, an `env` block with keys): a
|
|
24
|
+
// job runs with it, so "not logged in" would be a false alarm.
|
|
25
|
+
const SETTINGS_LOGIN_KEYS = [
|
|
26
|
+
"apiKeyHelper",
|
|
27
|
+
"awsAuthRefresh",
|
|
28
|
+
"awsCredentialExport",
|
|
29
|
+
"gcpAuthRefresh",
|
|
30
|
+
];
|
|
31
|
+
async function settingsHoldOtherLogin(env) {
|
|
32
|
+
try {
|
|
33
|
+
const settings = JSON.parse(await readFile(join(env.CLAUDE_CONFIG_DIR || join(homeDir(env), ".claude"), "settings.json"), "utf8"));
|
|
34
|
+
const inner = settings.env && typeof settings.env === "object"
|
|
35
|
+
? Object.keys(settings.env)
|
|
36
|
+
: [];
|
|
37
|
+
return (SETTINGS_LOGIN_KEYS.some((key) => key in settings) ||
|
|
38
|
+
inner.some((key) => OTHER_LOGINS.test(key)));
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// No settings file, or one we can't read: nothing hides a login.
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function runStatus(binary, args, env) {
|
|
46
|
+
try {
|
|
47
|
+
const { stdout } = await promisify(execFile)(binary, args, {
|
|
48
|
+
env,
|
|
49
|
+
maxBuffer: 64_000,
|
|
50
|
+
timeout: PROBE_MS,
|
|
51
|
+
});
|
|
52
|
+
return { code: 0, stdout };
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
const failed = error;
|
|
56
|
+
return {
|
|
57
|
+
code: typeof failed.code === "number" && !failed.killed ? failed.code : null,
|
|
58
|
+
stdout: String(failed.stdout ?? ""),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export function readProviderLogin(provider, run) {
|
|
63
|
+
if (provider === "claude_code") {
|
|
64
|
+
try {
|
|
65
|
+
const parsed = JSON.parse(run.stdout);
|
|
66
|
+
const loggedIn = parsed?.loggedIn;
|
|
67
|
+
if (typeof loggedIn === "boolean") {
|
|
68
|
+
return loggedIn;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// Not the JSON a status command prints: fall through to its exit code.
|
|
73
|
+
}
|
|
74
|
+
return run.code === 0 ? true : undefined;
|
|
75
|
+
}
|
|
76
|
+
if (run.code === 0) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
return run.code === 1 && matchFailureText(run.stdout) === "signed_out"
|
|
80
|
+
? false
|
|
81
|
+
: undefined;
|
|
82
|
+
}
|
|
83
|
+
export async function probeProviderLogin(input) {
|
|
84
|
+
if (input.provider === "gemini_cli") {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const args = STATUS_COMMAND[input.provider];
|
|
88
|
+
const source = input.env ?? process.env;
|
|
89
|
+
if (Object.keys(source).some((key) => OTHER_LOGINS.test(key)) ||
|
|
90
|
+
(input.provider === "claude_code" && (await settingsHoldOtherLogin(source)))) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const result = await (input.run ?? runStatus)(input.binary, args, childEnvironment(source, input.binary));
|
|
94
|
+
return readProviderLogin(input.provider, result);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The latest verdict, never waiting for one: a heartbeat must not stall behind
|
|
98
|
+
* a status command that hangs, so `current` answers from the last probe (can't
|
|
99
|
+
* tell before the first lands) and starts the next one when it is due. A yes is
|
|
100
|
+
* believed for minutes; a no is asked again each beat, so a person who just
|
|
101
|
+
* signed in sees it clear within seconds.
|
|
102
|
+
*
|
|
103
|
+
* A no from a probe that began before the last good answer is dropped: the
|
|
104
|
+
* answer proves the login works now, and the probe may have run just before the
|
|
105
|
+
* person signed back in.
|
|
106
|
+
*/
|
|
107
|
+
export class ProviderLoginWatch {
|
|
108
|
+
last;
|
|
109
|
+
pending = false;
|
|
110
|
+
probe;
|
|
111
|
+
now;
|
|
112
|
+
constructor(probe, now = Date.now) {
|
|
113
|
+
this.probe = probe;
|
|
114
|
+
this.now = now;
|
|
115
|
+
}
|
|
116
|
+
current(answeredAt = 0) {
|
|
117
|
+
const due = !this.last ||
|
|
118
|
+
this.last.login !== true ||
|
|
119
|
+
this.now() - this.last.at >= SIGNED_IN_TTL_MS;
|
|
120
|
+
if (due && !this.pending) {
|
|
121
|
+
this.pending = true;
|
|
122
|
+
const ranAt = this.now();
|
|
123
|
+
this.probe()
|
|
124
|
+
.catch(() => undefined)
|
|
125
|
+
.then((login) => {
|
|
126
|
+
this.last = { at: this.now(), login, ranAt };
|
|
127
|
+
this.pending = false;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return this.last?.login === false && answeredAt > this.last.ranAt
|
|
131
|
+
? undefined
|
|
132
|
+
: this.last?.login;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -3,6 +3,8 @@ import { access, mkdir, readFile, rm, rmdir, symlink } from "node:fs/promises";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { writePrivateFile } from "../agent-config.js";
|
|
5
5
|
import { homeDir } from "../install.js";
|
|
6
|
+
import { GEMINI_CREDENTIAL_FILES, readGeminiLogin } from "./gemini-login.js";
|
|
7
|
+
import { geminiRoomPolicy, geminiRoomSettings } from "./gemini-policy.js";
|
|
6
8
|
import { ProviderFailureError } from "./provider-failure.js";
|
|
7
9
|
// The room-only profile (#12712): a job for a teammate, a not-ready owner job
|
|
8
10
|
// and every Codex room job sees what TalentOS hands it (the packet and the room
|
|
@@ -59,15 +61,21 @@ async function claudeLoginSettings(env) {
|
|
|
59
61
|
: {}),
|
|
60
62
|
};
|
|
61
63
|
}
|
|
62
|
-
/**
|
|
64
|
+
/** A provider could not be kept apart from the owner's setup, so no job runs. */
|
|
63
65
|
export class RoomIsolationError extends ProviderFailureError {
|
|
64
|
-
constructor() {
|
|
65
|
-
super("unknown",
|
|
66
|
+
constructor(label = "Codex") {
|
|
67
|
+
super("unknown", `${label} could not be isolated from your setup on this computer.`);
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
export async function prepareRoomProfile(input) {
|
|
69
71
|
const jobDir = join(input.directory, ROOM_JOBS, input.jobId.replace(/[^\w-]/gu, ""));
|
|
70
|
-
|
|
72
|
+
// Gemini CLI reads context files from the working directory upward to its
|
|
73
|
+
// home, so its directory sits inside the job's own home: nothing above it is
|
|
74
|
+
// ever read.
|
|
75
|
+
const geminiHome = join(jobDir, "home");
|
|
76
|
+
const cwd = input.provider === "gemini_cli"
|
|
77
|
+
? join(geminiHome, "work")
|
|
78
|
+
: join(jobDir, "cwd");
|
|
71
79
|
const profile = {
|
|
72
80
|
cleanup: async () => {
|
|
73
81
|
await rm(jobDir, { force: true, recursive: true });
|
|
@@ -101,6 +109,35 @@ export async function prepareRoomProfile(input) {
|
|
|
101
109
|
await writePrivateFile(profile.settingsPath, login.file);
|
|
102
110
|
}
|
|
103
111
|
}
|
|
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
|
+
}
|
|
104
141
|
else {
|
|
105
142
|
profile.codexHome = join(jobDir, "codex-home");
|
|
106
143
|
await mkdir(profile.codexHome, { mode: 0o700 });
|
package/dist/agent/serve.js
CHANGED
|
@@ -2,9 +2,10 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { mkdir, open, readFile, rm } from "node:fs/promises";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { setTimeout as delay } from "node:timers/promises";
|
|
5
|
-
import { installSharedGateway, newerInstalledVersion, } from "../gateway-install.js";
|
|
5
|
+
import { installSharedGateway, launcherNodeCandidates, newerInstalledVersion, } from "../gateway-install.js";
|
|
6
6
|
import { compareGatewayVersions } from "../gateway-version.js";
|
|
7
7
|
import { homeDir } from "../install.js";
|
|
8
|
+
import { resolveProviderBinary } from "../provider-binary.js";
|
|
8
9
|
import { RoomToolsUnavailableError, runProvider, } from "./adapters.js";
|
|
9
10
|
import { AgentGateway, GatewayError } from "./gateway.js";
|
|
10
11
|
import { holdMs, renewDelayMs } from "./lease-hold.js";
|
|
@@ -13,7 +14,9 @@ import { NativeGate } from "./native/gate.js";
|
|
|
13
14
|
import { ROOM_ONLY_STATUS, roomOnlyStatus } from "./native/native-issue.js";
|
|
14
15
|
import { ProjectRequests } from "./native/project-requests.js";
|
|
15
16
|
import { mirrorOf } from "./native/projects.js";
|
|
17
|
+
import { nodeBlocksUpdate } from "./node-floor.js";
|
|
16
18
|
import { failureReasonOf } from "./provider-failure.js";
|
|
19
|
+
import { ProviderLoginWatch, probeProviderLogin } from "./provider-login.js";
|
|
17
20
|
import { sweepRoomJobs } from "./room-profile.js";
|
|
18
21
|
const HEARTBEAT_MS = 20_000;
|
|
19
22
|
// A native job holds a 30 s server lease and is re-derived on every renewal.
|
|
@@ -21,6 +24,9 @@ const NATIVE_RENEW_MS = 10_000;
|
|
|
21
24
|
// A launch waits this long for the server before it starts the provider anyway.
|
|
22
25
|
const START_WAIT_MS = 120_000;
|
|
23
26
|
const IDLE_MS = 30 * 60_000;
|
|
27
|
+
// A declined update (no Node here can run it) is not looked at again sooner,
|
|
28
|
+
// unless the floor it was declined for changes.
|
|
29
|
+
const NODE_BLOCK_RETRY_MS = 60 * 60_000;
|
|
24
30
|
// The room-only reason stays up this long before progress lines resume.
|
|
25
31
|
const FALLBACK_HOLD_MS = 5000;
|
|
26
32
|
export function needsUpdate(current, minimum) {
|
|
@@ -79,6 +85,16 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
79
85
|
const gate = options.gate ??
|
|
80
86
|
new NativeGate({ agent: config, directory, home: homeDir() });
|
|
81
87
|
const fallbackHoldMs = options.fallbackHoldMs ?? FALLBACK_HOLD_MS;
|
|
88
|
+
// Sign-in, asked the provider's own way and told with each heartbeat, so the
|
|
89
|
+
// room greys a signed-out agent before anyone asks it.
|
|
90
|
+
const loginWatch = new ProviderLoginWatch(options.probe ??
|
|
91
|
+
(async () => probeProviderLogin({
|
|
92
|
+
binary: resolveProviderBinary(config.provider, config.providerPath),
|
|
93
|
+
provider: config.provider,
|
|
94
|
+
})));
|
|
95
|
+
// When the provider last produced an answer: proof it was signed in then.
|
|
96
|
+
let answeredAt = 0;
|
|
97
|
+
const login = options.login ?? (() => loginWatch.current(answeredAt));
|
|
82
98
|
const service = new AbortController();
|
|
83
99
|
const signal = AbortSignal.any([stop, service.signal]);
|
|
84
100
|
let wakeResolve, wakePending = true;
|
|
@@ -87,7 +103,10 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
87
103
|
wakeResolve?.();
|
|
88
104
|
};
|
|
89
105
|
let active;
|
|
90
|
-
let minimum = version,
|
|
106
|
+
let minimum = version,
|
|
107
|
+
// The Node range of an update this computer declined, reported until the
|
|
108
|
+
// update is no longer blocked.
|
|
109
|
+
blocked, lastJobAt = Date.now(), push = false, dispose;
|
|
91
110
|
let terminalError;
|
|
92
111
|
const failService = (error) => {
|
|
93
112
|
if (error instanceof GatewayError &&
|
|
@@ -114,9 +133,17 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
114
133
|
.catch(() => undefined)
|
|
115
134
|
: undefined;
|
|
116
135
|
const issue = gate.issue?.();
|
|
136
|
+
const signedIn = login();
|
|
117
137
|
const response = await gateway.request("/agent-gateway/heartbeat", {
|
|
118
138
|
cliVersion: version,
|
|
139
|
+
nodeVersion: options.node?.nodeVersion ?? process.versions.node,
|
|
140
|
+
// Only while the update it was declined for is still the one due.
|
|
141
|
+
...(blocked?.forVersion === minimum && needsUpdate(version, minimum)
|
|
142
|
+
? { updateBlockedNodeRange: blocked.range }
|
|
143
|
+
: {}),
|
|
119
144
|
nativeOptIn: gate.reportable(),
|
|
145
|
+
// Absent when it can't tell, which leaves what the server knows alone.
|
|
146
|
+
...(signedIn === undefined ? {} : { providerSignedIn: signedIn }),
|
|
120
147
|
...(mirror ? { projects: mirror } : {}),
|
|
121
148
|
// Why an opted-in computer can't use full setup (an untested Codex),
|
|
122
149
|
// so the owner sees it in the Access menu.
|
|
@@ -127,6 +154,7 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
127
154
|
// The server's exact list of Codex versions allowed full setup; the
|
|
128
155
|
// background probe waits for it.
|
|
129
156
|
gate.setCodexTested?.(response.codexFenceTested);
|
|
157
|
+
await gate.syncComputerSetup?.(response.computerSetup);
|
|
130
158
|
if (response.pendingJobs > 0 || needsUpdate(version, minimum)) {
|
|
131
159
|
wake();
|
|
132
160
|
}
|
|
@@ -272,19 +300,48 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
272
300
|
return newer;
|
|
273
301
|
}
|
|
274
302
|
}
|
|
303
|
+
// A block is for one floor: a new floor is looked at at once, and when
|
|
304
|
+
// no update is due the range stops being sent.
|
|
305
|
+
if (blocked &&
|
|
306
|
+
(blocked.forVersion !== minimum || !needsUpdate(version, minimum))) {
|
|
307
|
+
blocked = undefined;
|
|
308
|
+
updateAfter = 0;
|
|
309
|
+
}
|
|
275
310
|
if (needsUpdate(version, minimum) && Date.now() >= updateAfter) {
|
|
276
311
|
if (process.platform === "win32") {
|
|
277
312
|
throw new Error(`Gateway update required; re-run npx talentos@${minimum} agent serve --agent ${config.agentId}. Windows gateways update in the foreground.`);
|
|
278
313
|
}
|
|
279
|
-
|
|
280
|
-
|
|
314
|
+
// Never update into a CLI no Node here can start: it would go offline
|
|
315
|
+
// with nothing but the owner's terminal saying why. An unreadable or
|
|
316
|
+
// unfamiliar range is not a block, and the update goes ahead.
|
|
317
|
+
const block = await nodeBlocksUpdate(minimum, {
|
|
318
|
+
candidates: () => launcherNodeCandidates(dirname(dirname(dirname(directory)))),
|
|
319
|
+
...options.node,
|
|
320
|
+
signal,
|
|
321
|
+
});
|
|
322
|
+
if (block) {
|
|
323
|
+
updateAfter = Date.now() + NODE_BLOCK_RETRY_MS;
|
|
324
|
+
if (block.range !== blocked?.range ||
|
|
325
|
+
block.forVersion !== blocked.forVersion) {
|
|
326
|
+
blocked = block;
|
|
327
|
+
console.error(block.message);
|
|
328
|
+
// Tell the server now, not at the next beat, so a waiting job's
|
|
329
|
+
// room line names Node.
|
|
330
|
+
await heartbeat().catch(failService);
|
|
331
|
+
}
|
|
281
332
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
333
|
+
else {
|
|
334
|
+
blocked = undefined;
|
|
335
|
+
try {
|
|
336
|
+
return await installGatewayUpdate(directory, minimum, signal);
|
|
337
|
+
}
|
|
338
|
+
catch {
|
|
339
|
+
updateAfter = Date.now() + 60_000;
|
|
340
|
+
console.error("Gateway update unavailable. Serving the current version; retrying in one minute.");
|
|
341
|
+
}
|
|
285
342
|
}
|
|
286
343
|
}
|
|
287
|
-
if (config.provider
|
|
344
|
+
if (config.provider !== "claude_code") {
|
|
288
345
|
await verify?.();
|
|
289
346
|
}
|
|
290
347
|
wakePending = false;
|
|
@@ -322,7 +379,10 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
322
379
|
let owner;
|
|
323
380
|
// Why this computer went room-only without telling the room.
|
|
324
381
|
let fellBack;
|
|
325
|
-
|
|
382
|
+
// Only the providers with an owner-native fence ever get here; a Gemini
|
|
383
|
+
// CLI job runs room-only whatever the claim carried.
|
|
384
|
+
if (job.native &&
|
|
385
|
+
(config.provider === "claude_code" || config.provider === "codex")) {
|
|
326
386
|
const post = (statusLine) => gateway
|
|
327
387
|
.request(`/agent-gateway/jobs/${job.jobId}/status`, { leaseToken: job.leaseToken, statusLine }, signal)
|
|
328
388
|
.catch(failService);
|
|
@@ -401,6 +461,11 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
401
461
|
job,
|
|
402
462
|
workDir,
|
|
403
463
|
owner: owner && { ...owner, watch: bridge },
|
|
464
|
+
// Tells the server the job read the web, before it can write
|
|
465
|
+
// what a page steered (#13163).
|
|
466
|
+
webRead: async () => {
|
|
467
|
+
await gateway.request(`/agent-gateway/jobs/${job.jobId}/web-read`, { leaseToken: job.leaseToken }, signal);
|
|
468
|
+
},
|
|
404
469
|
// Room tools and the current packet carry continuity. Replaying
|
|
405
470
|
// provider history grows forever and carries stale file copies.
|
|
406
471
|
signal: AbortSignal.any([signal, cancel.signal]),
|
|
@@ -434,6 +499,7 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
434
499
|
// job may drop it, never the quiet-gateway backstop. The server
|
|
435
500
|
// takes a late completion from this attempt until a newer claim.
|
|
436
501
|
current.answered = true;
|
|
502
|
+
answeredAt = Date.now();
|
|
437
503
|
// A transient delivery error retries this same completion. It must
|
|
438
504
|
// never become a new provider run or a duplicate final reply.
|
|
439
505
|
while (!(signal.aborted || cancel.signal.aborted)) {
|
package/dist/agent-config.js
CHANGED
|
@@ -95,10 +95,15 @@ function isLinkedAgent(value) {
|
|
|
95
95
|
typeof config.name === "string" &&
|
|
96
96
|
typeof config.linkHash === "string" &&
|
|
97
97
|
typeof config.linkedAt === "number" &&
|
|
98
|
+
(config.connectCwd === undefined ||
|
|
99
|
+
(typeof config.connectCwd === "string" &&
|
|
100
|
+
isAbsolute(config.connectCwd))) &&
|
|
98
101
|
(config.providerPath === undefined ||
|
|
99
102
|
(typeof config.providerPath === "string" &&
|
|
100
103
|
isAbsolute(config.providerPath))) &&
|
|
101
|
-
(config.provider === "claude_code" ||
|
|
104
|
+
(config.provider === "claude_code" ||
|
|
105
|
+
config.provider === "codex" ||
|
|
106
|
+
config.provider === "gemini_cli"));
|
|
102
107
|
}
|
|
103
108
|
export function isMissing(error) {
|
|
104
109
|
return (error !== null &&
|
package/dist/agent-http.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
2
|
import { childEnvironment } from "./agent/adapters.js";
|
|
3
|
+
import { geminiSignedIn, readGeminiLogin } from "./agent/gemini-login.js";
|
|
3
4
|
import { isSecureUrl, } from "./agent-link.js";
|
|
4
5
|
import { resolveProviderBinary } from "./provider-binary.js";
|
|
5
6
|
const REQUEST_TIMEOUT_MS = 10_000;
|
|
@@ -54,6 +55,8 @@ export async function setupApiOrigin(link, override) {
|
|
|
54
55
|
}
|
|
55
56
|
return apiOrigin(apiUrl);
|
|
56
57
|
}
|
|
58
|
+
// Gemini CLI has no sign-in status command, so linking looks for what a sign-in
|
|
59
|
+
// leaves: an OAuth file, an API key, or a Vertex setting (agent/gemini-login.ts).
|
|
57
60
|
export function inspectProvider(provider, configured) {
|
|
58
61
|
const binary = resolveProviderBinary(provider, configured);
|
|
59
62
|
const version = spawnSync(binary, ["--version"], {
|
|
@@ -64,6 +67,12 @@ export function inspectProvider(provider, configured) {
|
|
|
64
67
|
if (version.status !== 0 || !version.stdout?.trim()) {
|
|
65
68
|
throw new Error(`Install the official ${binary} CLI and sign in before linking.`);
|
|
66
69
|
}
|
|
70
|
+
if (provider === "gemini_cli") {
|
|
71
|
+
if (!geminiSignedIn(readGeminiLogin(process.env))) {
|
|
72
|
+
throw new Error("Sign in through the official gemini CLI before linking: start gemini once and choose how to sign in.");
|
|
73
|
+
}
|
|
74
|
+
return version.stdout.trim().split("\n")[0]?.slice(0, 200) ?? "unknown";
|
|
75
|
+
}
|
|
67
76
|
const args = provider === "claude_code"
|
|
68
77
|
? ["auth", "status", "--json"]
|
|
69
78
|
: ["login", "status"];
|
|
@@ -152,6 +161,41 @@ export async function unlinkRemoteAgent(agent) {
|
|
|
152
161
|
}
|
|
153
162
|
return true;
|
|
154
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Asks, with the agent's gateway key, for a terminal key bound to the same
|
|
166
|
+
* agent (#10527). Only the new key's hash is sent; a repeat replaces the
|
|
167
|
+
* agent's previous terminal key, so `replaced` says one was cut.
|
|
168
|
+
*/
|
|
169
|
+
export async function registerSessionKey(agent, keyHash) {
|
|
170
|
+
const response = await safeFetch(`${apiOrigin(agent.apiUrl)}/agent-link/session-key`, {
|
|
171
|
+
method: "POST",
|
|
172
|
+
headers: {
|
|
173
|
+
Authorization: `Bearer ${agent.apiKey}`,
|
|
174
|
+
"Content-Type": "application/json",
|
|
175
|
+
},
|
|
176
|
+
body: JSON.stringify({ keyHash }),
|
|
177
|
+
});
|
|
178
|
+
if (response.status === 409) {
|
|
179
|
+
// The server's own sentence: a busy agent says to try again later.
|
|
180
|
+
throw new Error((await refusalSentence(response)) ?? "Could not connect this terminal.");
|
|
181
|
+
}
|
|
182
|
+
if (!response.ok) {
|
|
183
|
+
throw new AgentHttpError("Could not connect this terminal", response);
|
|
184
|
+
}
|
|
185
|
+
const value = (await readJson(response));
|
|
186
|
+
return { replaced: value.replaced === true };
|
|
187
|
+
}
|
|
188
|
+
/** Stops every terminal key of the agent. False when the agent itself is gone. */
|
|
189
|
+
export async function revokeSessionKeys(agent) {
|
|
190
|
+
const response = await safeFetch(`${apiOrigin(agent.apiUrl)}/agent-link/session-key`, { method: "DELETE", headers: { Authorization: `Bearer ${agent.apiKey}` } });
|
|
191
|
+
if (response.status === 401) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
if (!response.ok) {
|
|
195
|
+
throw new AgentHttpError("Could not disconnect this terminal", response);
|
|
196
|
+
}
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
155
199
|
export async function waitForHeartbeat(agent, options = {}) {
|
|
156
200
|
const deadline = Date.now() + (options.timeoutMs ?? 10 * 60_000);
|
|
157
201
|
let serverStartedAt;
|
|
@@ -218,6 +262,19 @@ async function linkRefusal(response, token) {
|
|
|
218
262
|
}
|
|
219
263
|
: undefined;
|
|
220
264
|
}
|
|
265
|
+
async function refusalSentence(response) {
|
|
266
|
+
try {
|
|
267
|
+
const value = (await response.json());
|
|
268
|
+
return typeof value.error === "string" &&
|
|
269
|
+
value.error.length <= REFUSAL_MAX_LENGTH &&
|
|
270
|
+
ONE_LINE.test(value.error)
|
|
271
|
+
? value.error
|
|
272
|
+
: undefined;
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
221
278
|
async function readJson(response) {
|
|
222
279
|
try {
|
|
223
280
|
return await response.json();
|
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)\/?$/;
|
|
2
|
+
const SETUP_PATH = /^\/agent-setup\/(claude_code|codex|gemini_cli)\/?$/;
|
|
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;
|
|
@@ -12,7 +12,9 @@ export function parseAgentLink(value) {
|
|
|
12
12
|
const tokens = fragment.getAll("token");
|
|
13
13
|
const token = tokens[0];
|
|
14
14
|
if (!(isSecureUrl(url) &&
|
|
15
|
-
(provider === "claude_code" ||
|
|
15
|
+
(provider === "claude_code" ||
|
|
16
|
+
provider === "codex" ||
|
|
17
|
+
provider === "gemini_cli") &&
|
|
16
18
|
!url.search &&
|
|
17
19
|
fragment.size === 1 &&
|
|
18
20
|
tokens.length === 1 &&
|