talentos 1.4.11 → 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/dist/agent/adapters.js +134 -5
- package/dist/agent/codex-policy.js +11 -0
- package/dist/agent/codex-probe.js +106 -26
- 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/native/codex-launch.js +2 -0
- package/dist/agent/native/config.js +4 -2
- package/dist/agent/native/gate.js +125 -7
- package/dist/agent/native/hook-entry.js +2 -0
- package/dist/agent/native/launch.js +2 -0
- package/dist/agent/native/native-issue.js +3 -3
- package/dist/agent/native/touch.js +19 -1
- 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 +22 -2
- package/dist/agent-config.js +6 -1
- package/dist/agent-http.js +9 -0
- package/dist/agent-link.js +4 -2
- package/dist/commands/agent-native.js +0 -3
- package/dist/commands/agent-serve.js +7 -2
- package/dist/commands/agent.js +8 -0
- package/dist/provider-binary.js +12 -2
- package/package.json +1 -1
|
@@ -50,6 +50,23 @@ function readsOtherRoom(call, jobRoomId) {
|
|
|
50
50
|
const aimed = call.toolInput.roomId;
|
|
51
51
|
return aimed !== undefined && aimed !== jobRoomId;
|
|
52
52
|
}
|
|
53
|
+
// read_file and read_app_state name no room, so the id has to: only a file id
|
|
54
|
+
// the packet listed for the job's room, or an attachment of the message that
|
|
55
|
+
// started the job (the owner's own words), stays inside it (#13471). A read by
|
|
56
|
+
// versionId or another messageId, or a job with no list, fails closed.
|
|
57
|
+
const BY_ID_TOOLS = new Set(["read_file", "read_app_state"].map((name) => ROOM_SERVER_PREFIX + name));
|
|
58
|
+
function readsOtherRoomFile(call, context) {
|
|
59
|
+
if (!BY_ID_TOOLS.has(call.tool)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const { artifactId, messageId } = call.toolInput;
|
|
63
|
+
if (messageId !== undefined) {
|
|
64
|
+
return !(artifactId === undefined &&
|
|
65
|
+
typeof messageId === "string" &&
|
|
66
|
+
messageId === context.triggerId);
|
|
67
|
+
}
|
|
68
|
+
return !(typeof artifactId === "string" && context.roomFileIds?.includes(artifactId));
|
|
69
|
+
}
|
|
53
70
|
export function touchesPrivate(call, context, allowedByPolicy) {
|
|
54
71
|
// The policy had to ask the owner: it is outward, irreversible or unknown, and
|
|
55
72
|
// once approved it may read anything.
|
|
@@ -66,7 +83,8 @@ export function touchesPrivate(call, context, allowedByPolicy) {
|
|
|
66
83
|
};
|
|
67
84
|
if (tool.startsWith("mcp__")) {
|
|
68
85
|
return (!tool.startsWith(ROOM_SERVER_PREFIX) ||
|
|
69
|
-
readsOtherRoom(call, context.roomId)
|
|
86
|
+
readsOtherRoom(call, context.roomId) ||
|
|
87
|
+
readsOtherRoomFile(call, context));
|
|
70
88
|
}
|
|
71
89
|
if (NEUTRAL_TOOLS.has(tool)) {
|
|
72
90
|
return false;
|
|
@@ -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
|
@@ -5,6 +5,7 @@ import { setTimeout as delay } from "node:timers/promises";
|
|
|
5
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";
|
|
@@ -15,6 +16,7 @@ import { ProjectRequests } from "./native/project-requests.js";
|
|
|
15
16
|
import { mirrorOf } from "./native/projects.js";
|
|
16
17
|
import { nodeBlocksUpdate } from "./node-floor.js";
|
|
17
18
|
import { failureReasonOf } from "./provider-failure.js";
|
|
19
|
+
import { ProviderLoginWatch, probeProviderLogin } from "./provider-login.js";
|
|
18
20
|
import { sweepRoomJobs } from "./room-profile.js";
|
|
19
21
|
const HEARTBEAT_MS = 20_000;
|
|
20
22
|
// A native job holds a 30 s server lease and is re-derived on every renewal.
|
|
@@ -83,6 +85,16 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
83
85
|
const gate = options.gate ??
|
|
84
86
|
new NativeGate({ agent: config, directory, home: homeDir() });
|
|
85
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));
|
|
86
98
|
const service = new AbortController();
|
|
87
99
|
const signal = AbortSignal.any([stop, service.signal]);
|
|
88
100
|
let wakeResolve, wakePending = true;
|
|
@@ -121,6 +133,7 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
121
133
|
.catch(() => undefined)
|
|
122
134
|
: undefined;
|
|
123
135
|
const issue = gate.issue?.();
|
|
136
|
+
const signedIn = login();
|
|
124
137
|
const response = await gateway.request("/agent-gateway/heartbeat", {
|
|
125
138
|
cliVersion: version,
|
|
126
139
|
nodeVersion: options.node?.nodeVersion ?? process.versions.node,
|
|
@@ -129,6 +142,8 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
129
142
|
? { updateBlockedNodeRange: blocked.range }
|
|
130
143
|
: {}),
|
|
131
144
|
nativeOptIn: gate.reportable(),
|
|
145
|
+
// Absent when it can't tell, which leaves what the server knows alone.
|
|
146
|
+
...(signedIn === undefined ? {} : { providerSignedIn: signedIn }),
|
|
132
147
|
...(mirror ? { projects: mirror } : {}),
|
|
133
148
|
// Why an opted-in computer can't use full setup (an untested Codex),
|
|
134
149
|
// so the owner sees it in the Access menu.
|
|
@@ -139,6 +154,7 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
139
154
|
// The server's exact list of Codex versions allowed full setup; the
|
|
140
155
|
// background probe waits for it.
|
|
141
156
|
gate.setCodexTested?.(response.codexFenceTested);
|
|
157
|
+
await gate.syncComputerSetup?.(response.computerSetup);
|
|
142
158
|
if (response.pendingJobs > 0 || needsUpdate(version, minimum)) {
|
|
143
159
|
wake();
|
|
144
160
|
}
|
|
@@ -325,7 +341,7 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
325
341
|
}
|
|
326
342
|
}
|
|
327
343
|
}
|
|
328
|
-
if (config.provider
|
|
344
|
+
if (config.provider !== "claude_code") {
|
|
329
345
|
await verify?.();
|
|
330
346
|
}
|
|
331
347
|
wakePending = false;
|
|
@@ -363,7 +379,10 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
363
379
|
let owner;
|
|
364
380
|
// Why this computer went room-only without telling the room.
|
|
365
381
|
let fellBack;
|
|
366
|
-
|
|
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")) {
|
|
367
386
|
const post = (statusLine) => gateway
|
|
368
387
|
.request(`/agent-gateway/jobs/${job.jobId}/status`, { leaseToken: job.leaseToken, statusLine }, signal)
|
|
369
388
|
.catch(failService);
|
|
@@ -480,6 +499,7 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
480
499
|
// job may drop it, never the quiet-gateway backstop. The server
|
|
481
500
|
// takes a late completion from this attempt until a newer claim.
|
|
482
501
|
current.answered = true;
|
|
502
|
+
answeredAt = Date.now();
|
|
483
503
|
// A transient delivery error retries this same completion. It must
|
|
484
504
|
// never become a new provider run or a duplicate final reply.
|
|
485
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"];
|
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 &&
|
|
@@ -78,9 +78,6 @@ export async function runAgentProject(parsed, home = homeDir()) {
|
|
|
78
78
|
throw new Error("Use talentos agent project add | list | remove.");
|
|
79
79
|
}
|
|
80
80
|
const agent = await pickAgent(parsed, home, `project ${action}`);
|
|
81
|
-
if (agent.provider !== "claude_code") {
|
|
82
|
-
throw new Error("Projects support Claude Code first. Codex is not available yet.");
|
|
83
|
-
}
|
|
84
81
|
const directory = dirname(agentWorkDir(agent.agentId, home));
|
|
85
82
|
if (action === "add") {
|
|
86
83
|
const project = await registerRoot(directory, await checkRepo(process.cwd(), home));
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { dirname } from "node:path";
|
|
3
|
-
import { verifyClaudeCode, verifyCodex, verifyCodexWeb, } from "../agent/adapters.js";
|
|
3
|
+
import { verifyClaudeCode, verifyCodex, verifyCodexWeb, verifyGemini, } from "../agent/adapters.js";
|
|
4
4
|
import { CodexBoundaryError } from "../agent/codex-probe.js";
|
|
5
5
|
import { AgentGateway, GatewayError } from "../agent/gateway.js";
|
|
6
|
+
import { GeminiBoundaryError } from "../agent/gemini-probe.js";
|
|
6
7
|
import { serveAgent } from "../agent/serve.js";
|
|
7
8
|
import { agentWorkDir, localAgents, storeAgent, } from "../agent-config.js";
|
|
8
9
|
import { AgentHttpError, fetchAgentStatus } from "../agent-http.js";
|
|
@@ -70,6 +71,9 @@ async function verifyAgent(config, options, signal) {
|
|
|
70
71
|
if (config.provider === "claude_code") {
|
|
71
72
|
await verifyClaudeCode(binary);
|
|
72
73
|
}
|
|
74
|
+
else if (config.provider === "gemini_cli") {
|
|
75
|
+
await verifyGemini(binary, signal);
|
|
76
|
+
}
|
|
73
77
|
else {
|
|
74
78
|
await verifyCodex(binary, signal);
|
|
75
79
|
await verifyCodexWeb(binary, signal);
|
|
@@ -77,7 +81,8 @@ async function verifyAgent(config, options, signal) {
|
|
|
77
81
|
}
|
|
78
82
|
catch (error) {
|
|
79
83
|
if (error instanceof ProviderBinaryError) {
|
|
80
|
-
if (!(error instanceof CodexBoundaryError
|
|
84
|
+
if (!(error instanceof CodexBoundaryError ||
|
|
85
|
+
error instanceof GeminiBoundaryError)) {
|
|
81
86
|
try {
|
|
82
87
|
await new AgentGateway(config).request("/agent-gateway/provider-unavailable");
|
|
83
88
|
}
|
package/dist/commands/agent.js
CHANGED
|
@@ -2,6 +2,7 @@ import { readFileSync } from "node:fs";
|
|
|
2
2
|
import { chmod, mkdir, open, readFile, rm } from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { createInterface } from "node:readline/promises";
|
|
5
|
+
import { repoRoot } from "../agent/native/config.js";
|
|
5
6
|
import { agentConfigPath, agentLogPath, agentsDir, agentWorkDir, isMissing, localAgents, storeAgent, writePrivateFile, } from "../agent-config.js";
|
|
6
7
|
import { AgentHttpError, fetchAgentStatus, inspectProvider, redeemAgent, setupApiOrigin, unlinkRemoteAgent, waitForHeartbeat, } from "../agent-http.js";
|
|
7
8
|
import { parseAgentLink, redactAgentOutput } from "../agent-link.js";
|
|
@@ -231,6 +232,13 @@ export async function installLinkedAgent(parsed, dependencies = {}) {
|
|
|
231
232
|
}
|
|
232
233
|
await rm(pendingPath, { force: true });
|
|
233
234
|
}
|
|
235
|
+
// The folder the agent was connected from is where it works once the owner
|
|
236
|
+
// allows the computer in the app; a repair from elsewhere keeps the first.
|
|
237
|
+
const connectCwd = await repoRoot(process.cwd());
|
|
238
|
+
if (connectCwd && connectCwd !== agent.connectCwd) {
|
|
239
|
+
agent.connectCwd = connectCwd;
|
|
240
|
+
await storeAgent(agent, home);
|
|
241
|
+
}
|
|
234
242
|
const service = await (dependencies.install ??
|
|
235
243
|
(async (config) => {
|
|
236
244
|
if (process.platform !== "win32") {
|
package/dist/provider-binary.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { accessSync, constants, statSync } from "node:fs";
|
|
2
2
|
import { delimiter, dirname, isAbsolute, join, resolve } from "node:path";
|
|
3
3
|
import { homeDir } from "./install.js";
|
|
4
|
+
const BINARY = {
|
|
5
|
+
claude_code: "claude",
|
|
6
|
+
codex: "codex",
|
|
7
|
+
gemini_cli: "gemini",
|
|
8
|
+
};
|
|
9
|
+
const LABEL = {
|
|
10
|
+
claude_code: "Claude Code",
|
|
11
|
+
codex: "Codex",
|
|
12
|
+
gemini_cli: "Gemini CLI",
|
|
13
|
+
};
|
|
4
14
|
export class ProviderBinaryError extends Error {
|
|
5
15
|
exitCode = 78;
|
|
6
16
|
}
|
|
7
17
|
export function resolveProviderBinary(provider, configured) {
|
|
8
|
-
const binary = provider
|
|
18
|
+
const binary = BINARY[provider];
|
|
9
19
|
const candidates = configured
|
|
10
20
|
? [configured]
|
|
11
21
|
: (process.env.PATH ?? "")
|
|
@@ -28,7 +38,7 @@ export function resolveProviderBinary(provider, configured) {
|
|
|
28
38
|
/* Try the next PATH directory. */
|
|
29
39
|
}
|
|
30
40
|
}
|
|
31
|
-
const label = provider
|
|
41
|
+
const label = LABEL[provider];
|
|
32
42
|
throw new ProviderBinaryError(`${label} not found at ${configured ?? join(homeDir(), ".local/bin", binary)}; run talentos agent repair`);
|
|
33
43
|
}
|
|
34
44
|
export function providerPathEnv(binary, home = homeDir(), includeRuntimeNode = true) {
|
package/package.json
CHANGED