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.
Files changed (41) hide show
  1. package/README.md +3 -3
  2. package/dist/agent/adapters.js +207 -14
  3. package/dist/agent/codex-policy.js +22 -0
  4. package/dist/agent/codex-probe.js +114 -30
  5. package/dist/agent/gemini-login.js +74 -0
  6. package/dist/agent/gemini-policy.js +91 -0
  7. package/dist/agent/gemini-probe.js +308 -0
  8. package/dist/agent/mcp-entry.js +22 -9
  9. package/dist/agent/native/approvals.js +15 -11
  10. package/dist/agent/native/codex-launch.js +3 -0
  11. package/dist/agent/native/config.js +4 -2
  12. package/dist/agent/native/gate.js +160 -8
  13. package/dist/agent/native/hook-entry.js +33 -8
  14. package/dist/agent/native/launch.js +3 -0
  15. package/dist/agent/native/native-issue.js +3 -3
  16. package/dist/agent/native/policy.js +62 -14
  17. package/dist/agent/native/probe.js +13 -1
  18. package/dist/agent/native/touch.js +33 -1
  19. package/dist/agent/node-floor.js +140 -0
  20. package/dist/agent/provider-failure.js +2 -2
  21. package/dist/agent/provider-login.js +134 -0
  22. package/dist/agent/room-profile.js +41 -4
  23. package/dist/agent/serve.js +75 -9
  24. package/dist/agent-config.js +6 -1
  25. package/dist/agent-http.js +57 -0
  26. package/dist/agent-link.js +4 -2
  27. package/dist/agent-session.js +137 -0
  28. package/dist/args.js +1 -0
  29. package/dist/client.js +11 -2
  30. package/dist/commands/agent-native.js +0 -3
  31. package/dist/commands/agent-serve.js +7 -2
  32. package/dist/commands/agent-session.js +160 -0
  33. package/dist/commands/agent.js +37 -3
  34. package/dist/commands/init.js +2 -2
  35. package/dist/commands/login.js +2 -2
  36. package/dist/gateway-install.js +50 -11
  37. package/dist/index.js +13 -4
  38. package/dist/install.js +39 -14
  39. package/dist/mcp-proxy.js +30 -2
  40. package/dist/provider-binary.js +12 -2
  41. package/package.json +2 -2
@@ -0,0 +1,137 @@
1
+ import { existsSync } from "node:fs";
2
+ import { chmod, mkdir, readFile, realpath, rm, writeFile, } from "node:fs/promises";
3
+ import { dirname, join, parse, sep } from "node:path";
4
+ import { agentsDir, isMissing, writePrivateFile } from "./agent-config.js";
5
+ import { gatewayLauncherPath } from "./gateway-install.js";
6
+ import { CONFIG_MODE, claudeRun, codexConfigPath, onPath, readIfPresent, removeCodexSection, upsertCodexSection, } from "./install.js";
7
+ /**
8
+ * The member's everyday terminal acts in rooms as their linked agent (#10527).
9
+ * It registers as its own MCP server beside the personal `talentos` one, and
10
+ * as a stdio command, so the key stays in this private file: never in the
11
+ * client's config, its argv, or a log.
12
+ */
13
+ export const SESSION_SERVER = "talentos-room";
14
+ export const SESSION_TARGETS = ["claude", "codex"];
15
+ const CLAUDE_LIST_TIMEOUT_MS = 10_000;
16
+ const NOT_ON_PATH = "the `claude` command is not on PATH";
17
+ export function sessionKeyPath(agentId, home) {
18
+ return join(agentsDir(home), agentId, "session.json");
19
+ }
20
+ export async function readSessionKey(agentId, home) {
21
+ try {
22
+ const value = JSON.parse(await readFile(sessionKeyPath(agentId, home), "utf8"));
23
+ return typeof value.apiKey === "string" &&
24
+ value.apiKey.startsWith("tos_") &&
25
+ typeof value.apiUrl === "string"
26
+ ? { apiKey: value.apiKey, apiUrl: value.apiUrl }
27
+ : undefined;
28
+ }
29
+ catch (error) {
30
+ if (isMissing(error) || error instanceof SyntaxError) {
31
+ return;
32
+ }
33
+ throw error;
34
+ }
35
+ }
36
+ export async function writeSessionKey(agentId, key, home) {
37
+ await writePrivateFile(sessionKeyPath(agentId, home), `${JSON.stringify(key, null, 2)}\n`);
38
+ }
39
+ export async function removeSessionKey(agentId, home) {
40
+ await rm(sessionKeyPath(agentId, home), { force: true });
41
+ }
42
+ /**
43
+ * The folder a terminal's `upload_file` may read: where the session runs, but
44
+ * never the home folder, a folder that contains it, or the filesystem root.
45
+ */
46
+ export async function sessionUploadRoot(cwd, home) {
47
+ try {
48
+ const [real, realHome] = await Promise.all([realpath(cwd), realpath(home)]);
49
+ // Home itself, anything that contains it (/home, /Users, /), or the root
50
+ // would reach everything under the home folder.
51
+ return real === parse(real).root ||
52
+ real === realHome ||
53
+ realHome.startsWith(real + sep)
54
+ ? undefined
55
+ : real;
56
+ }
57
+ catch {
58
+ return;
59
+ }
60
+ }
61
+ /** The command a client runs: the stable launcher when installed, else npx. */
62
+ export function sessionEntry(agentId, home, platform = process.platform) {
63
+ const tail = ["agent", "mcp", "--agent", agentId, "--surface", "session"];
64
+ const launcher = gatewayLauncherPath(home);
65
+ return platform !== "win32" && existsSync(launcher)
66
+ ? { command: launcher, args: tail }
67
+ : { command: "npx", args: ["-y", "talentos@1", ...tail] };
68
+ }
69
+ /** The command to run by hand, for a client we could not write to. */
70
+ export function sessionSnippet(target, entry) {
71
+ return target === "claude"
72
+ ? `claude mcp add --scope user ${SESSION_SERVER} -- ${[entry.command, ...entry.args].join(" ")}`
73
+ : codexBlock(entry);
74
+ }
75
+ export async function registerSession(target, entry, home, run = claudeRun, hasClaude = () => onPath("claude")) {
76
+ if (target === "claude") {
77
+ return registerClaude(entry, run, hasClaude);
78
+ }
79
+ const path = codexConfigPath(home);
80
+ await mkdir(dirname(path), { recursive: true, mode: 0o700 });
81
+ await writeFile(path, upsertCodexSection(await readIfPresent(path), SESSION_SERVER, codexBlock(entry)), { mode: CONFIG_MODE });
82
+ await chmod(path, CONFIG_MODE);
83
+ return { done: true, detail: path };
84
+ }
85
+ export async function unregisterSession(target, home, run = claudeRun, hasClaude = () => onPath("claude")) {
86
+ if (target === "claude") {
87
+ if (!hasClaude()) {
88
+ return { done: false, detail: NOT_ON_PATH };
89
+ }
90
+ run(["mcp", "remove", "--scope", "user", SESSION_SERVER]);
91
+ return { done: true, detail: "claude mcp remove --scope user" };
92
+ }
93
+ const path = codexConfigPath(home);
94
+ const existing = await readIfPresent(path);
95
+ if (existing !== undefined) {
96
+ const next = removeCodexSection(existing, SESSION_SERVER);
97
+ if (next !== existing) {
98
+ await writeFile(path, next, { mode: CONFIG_MODE });
99
+ await chmod(path, CONFIG_MODE);
100
+ }
101
+ }
102
+ return { done: true, detail: path };
103
+ }
104
+ function registerClaude(entry, run, hasClaude) {
105
+ if (!hasClaude()) {
106
+ return { done: false, detail: NOT_ON_PATH };
107
+ }
108
+ const listed = run(["mcp", "list"], { timeout: CLAUDE_LIST_TIMEOUT_MS });
109
+ // Re-adding on top of an existing entry keeps the old command, so drop it.
110
+ if (listed.error === undefined && listed.stdout?.includes(SESSION_SERVER)) {
111
+ run(["mcp", "remove", "--scope", "user", SESSION_SERVER]);
112
+ }
113
+ const added = run([
114
+ "mcp",
115
+ "add",
116
+ "--scope",
117
+ "user",
118
+ SESSION_SERVER,
119
+ "--",
120
+ entry.command,
121
+ ...entry.args,
122
+ ]);
123
+ if (added.status !== 0) {
124
+ return {
125
+ done: false,
126
+ detail: added.stderr?.trim().split("\n")[0] || "`claude mcp add` failed",
127
+ };
128
+ }
129
+ return { done: true, detail: "claude mcp add --scope user" };
130
+ }
131
+ function codexBlock(entry) {
132
+ return [
133
+ `[mcp_servers.${SESSION_SERVER}]`,
134
+ `command = ${JSON.stringify(entry.command)}`,
135
+ `args = [${entry.args.map((arg) => JSON.stringify(arg)).join(", ")}]`,
136
+ ].join("\n");
137
+ }
package/dist/args.js CHANGED
@@ -24,6 +24,7 @@ const CLI_OPTIONS = {
24
24
  agent: { type: "string" },
25
25
  "upload-root": { type: "string" },
26
26
  "owner-job-dir": { type: "string" },
27
+ surface: { type: "string" },
27
28
  };
28
29
  /** Groups whose first positional is a sub-command rather than an argument. */
29
30
  const ACTION_GROUPS = new Set(["agent", "mcp", "skills", "memory", "routines"]);
package/dist/client.js CHANGED
@@ -21,6 +21,7 @@ export const UNAUTHORIZED = "Not logged in or key revoked. Run `talentos login`.
21
21
  export class AgentClient {
22
22
  credentials;
23
23
  client;
24
+ connecting;
24
25
  retryDelaysMs;
25
26
  constructor(credentials, retryDelaysMs = LIST_RETRY_DELAYS_MS) {
26
27
  this.credentials = credentials;
@@ -65,10 +66,18 @@ export class AgentClient {
65
66
  }
66
67
  return await run();
67
68
  }
68
- async connect() {
69
+ // One connection at a time: the proxy lists at boot while a call may already
70
+ // be waiting, and two connects would leave the first session open and unused.
71
+ connect() {
69
72
  if (this.client) {
70
- return this.client;
73
+ return Promise.resolve(this.client);
71
74
  }
75
+ this.connecting ??= this.open().finally(() => {
76
+ this.connecting = undefined;
77
+ });
78
+ return this.connecting;
79
+ }
80
+ async open() {
72
81
  const client = new Client(CLIENT_INFO, { capabilities: {} });
73
82
  const transport = new StreamableHTTPClientTransport(new URL(`${this.credentials.apiUrl}/mcp`), {
74
83
  requestInit: {
@@ -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
  }
@@ -0,0 +1,160 @@
1
+ import { localAgents } from "../agent-config.js";
2
+ import { AgentHttpError, registerSessionKey, revokeSessionKeys, } from "../agent-http.js";
3
+ import { redactAgentOutput } from "../agent-link.js";
4
+ import { readSessionKey, registerSession, removeSessionKey, SESSION_SERVER, SESSION_TARGETS, sessionEntry, sessionSnippet, unregisterSession, writeSessionKey, } from "../agent-session.js";
5
+ import { AgentClient, UNAUTHORIZED } from "../client.js";
6
+ import { dim, emit, warn } from "../format.js";
7
+ import { defaultProbe, detectAgents, homeDir } from "../install.js";
8
+ import { mintKey } from "../login.js";
9
+ import { selectAgents } from "./agent.js";
10
+ const REMOVED = "was removed in TalentOS; run talentos agent link to reconnect.";
11
+ const LABELS = {
12
+ claude: "Claude Code",
13
+ codex: "Codex",
14
+ };
15
+ function isSessionTarget(value) {
16
+ return SESSION_TARGETS.some((target) => target === value);
17
+ }
18
+ function sessionTargets(forOption) {
19
+ if (forOption === undefined) {
20
+ const found = detectAgents(defaultProbe()).filter(isSessionTarget);
21
+ if (found.length === 0) {
22
+ throw new Error("No Claude Code or Codex found. Re-run with --for claude|codex.");
23
+ }
24
+ return found;
25
+ }
26
+ if (forOption === "all") {
27
+ return [...SESSION_TARGETS];
28
+ }
29
+ if (isSessionTarget(forOption)) {
30
+ return [forOption];
31
+ }
32
+ throw new Error(`Unknown --for value: ${forOption}. Use claude, codex or all.`);
33
+ }
34
+ async function oneAgent(parsed, home) {
35
+ const agent = (await selectAgents(parsed, true, home))[0];
36
+ if (!agent) {
37
+ throw new Error("No linked agent matches. Run talentos agent link first.");
38
+ }
39
+ return agent;
40
+ }
41
+ function ended(error) {
42
+ return (error instanceof AgentHttpError &&
43
+ (error.status === 401 || error.status === 410));
44
+ }
45
+ /**
46
+ * Lets this machine's everyday Claude Code or Codex act in rooms as the linked
47
+ * agent: a key of its own, kept in a private file, and a stdio entry that
48
+ * reads it. A repeat run replaces the key.
49
+ */
50
+ export async function runConnectSession(parsed, dependencies = {}) {
51
+ const home = dependencies.home ?? homeDir();
52
+ const agent = await oneAgent(parsed, home);
53
+ const targets = sessionTargets(parsed.options.for);
54
+ const minted = mintKey();
55
+ try {
56
+ await registerSessionKey(agent, minted.hashedKey);
57
+ }
58
+ catch (error) {
59
+ if (ended(error)) {
60
+ throw new Error(`${redactAgentOutput(agent.name)} ${REMOVED}`);
61
+ }
62
+ throw error;
63
+ }
64
+ // Only after the server accepted the new key: a refusal (a busy agent, a
65
+ // removed one) must leave the other agent's terminal as it was.
66
+ await releaseOtherTerminals(agent, home);
67
+ await writeSessionKey(agent.agentId, { apiKey: minted.rawKey, apiUrl: agent.apiUrl }, home);
68
+ const entry = sessionEntry(agent.agentId, home);
69
+ for (const target of targets) {
70
+ const result = await settle(() => registerSession(target, entry, home));
71
+ if (result.done) {
72
+ emit(`✓ ${LABELS[target]} → ${result.detail}`);
73
+ }
74
+ else {
75
+ emit(`· ${LABELS[target]}: ${result.detail}. Add it yourself:\n ${sessionSnippet(target, entry)}`);
76
+ }
77
+ }
78
+ emit(`${redactAgentOutput(agent.name)} can now act in its rooms from this terminal. ${dim("Turn it off with talentos agent disconnect-session.")}`);
79
+ }
80
+ // One terminal speaks as one agent: the `talentos-room` entry is a single
81
+ // name, so connecting this agent stops any other linked agent's terminal here
82
+ // rather than leave its key live with no entry to use it.
83
+ async function releaseOtherTerminals(agent, home) {
84
+ for (const other of await localAgents(home)) {
85
+ if (other.agentId !== agent.agentId &&
86
+ (await readSessionKey(other.agentId, home))) {
87
+ try {
88
+ await revokeSessionKeys(other);
89
+ }
90
+ catch {
91
+ // The key dies with its agent; the file goes either way.
92
+ }
93
+ await removeSessionKey(other.agentId, home);
94
+ emit(`${redactAgentOutput(other.name)} no longer acts from this terminal: one agent per terminal.`);
95
+ }
96
+ }
97
+ }
98
+ export async function runDisconnectSession(parsed, dependencies = {}) {
99
+ const home = dependencies.home ?? homeDir();
100
+ const agent = await oneAgent(parsed, home);
101
+ await disconnectSession(agent, home, parsed.options.for);
102
+ emit(`${redactAgentOutput(agent.name)} no longer acts in rooms from this terminal. The ${SESSION_SERVER} entry is removed from every client unless --for names one.`);
103
+ }
104
+ /**
105
+ * Stops the agent's terminal key on the server, then removes the file and the
106
+ * client entries here. A server that cannot be reached is a warning, not a
107
+ * reason to leave the entries behind: the key stays dead once it is reached.
108
+ */
109
+ export async function disconnectSession(agent, home, forOption) {
110
+ try {
111
+ await revokeSessionKeys(agent);
112
+ }
113
+ catch (error) {
114
+ warn(`The server could not confirm the terminal key is stopped (${error instanceof Error ? error.message : "unreachable"}). Unlinking the agent in TalentOS stops it too.`);
115
+ }
116
+ await removeSessionKey(agent.agentId, home);
117
+ for (const target of sessionTargetsForRemoval(forOption)) {
118
+ const result = await settle(() => unregisterSession(target, home));
119
+ if (!result.done) {
120
+ warn(`${LABELS[target]}: ${result.detail}. Remove ${SESSION_SERVER} from it yourself.`);
121
+ }
122
+ }
123
+ }
124
+ // Removal covers every client: a stale entry is worse than a missing one.
125
+ function sessionTargetsForRemoval(forOption) {
126
+ return forOption === undefined
127
+ ? [...SESSION_TARGETS]
128
+ : sessionTargets(forOption);
129
+ }
130
+ async function settle(run) {
131
+ try {
132
+ return await run();
133
+ }
134
+ catch (error) {
135
+ return {
136
+ done: false,
137
+ detail: error instanceof Error ? error.message : "could not write it",
138
+ };
139
+ }
140
+ }
141
+ /** Whether this machine's terminal can act as the agent right now. */
142
+ export async function terminalState(agent, home) {
143
+ const key = await readSessionKey(agent.agentId, home);
144
+ if (!key) {
145
+ return "off";
146
+ }
147
+ const client = new AgentClient(key, []);
148
+ try {
149
+ await client.listTools();
150
+ return "on";
151
+ }
152
+ catch (error) {
153
+ return error instanceof Error && error.message === UNAUTHORIZED
154
+ ? "reconnect"
155
+ : "unknown";
156
+ }
157
+ finally {
158
+ await client.close();
159
+ }
160
+ }
@@ -2,10 +2,12 @@ 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";
8
9
  import { installAgentService, uninstallAgentService, } from "../agent-service.js";
10
+ import { readSessionKey } from "../agent-session.js";
9
11
  import { emit, emitJson, renderTable, warn } from "../format.js";
10
12
  import { installSharedGateway } from "../gateway-install.js";
11
13
  import { homeDir } from "../install.js";
@@ -113,6 +115,14 @@ export async function runAgent(parsed, dependencies = {}) {
113
115
  await import("../agent/mcp-entry.js");
114
116
  return;
115
117
  }
118
+ case "connect-session": {
119
+ const { runConnectSession } = await import("./agent-session.js");
120
+ return await runConnectSession(parsed, { home: dependencies.home });
121
+ }
122
+ case "disconnect-session": {
123
+ const { runDisconnectSession } = await import("./agent-session.js");
124
+ return await runDisconnectSession(parsed, { home: dependencies.home });
125
+ }
116
126
  case "native": {
117
127
  const { runAgentNative } = await import("./agent-native.js");
118
128
  return await runAgentNative(parsed, dependencies.home);
@@ -129,7 +139,7 @@ export async function runAgent(parsed, dependencies = {}) {
129
139
  case "logs":
130
140
  return await showLogs(parsed);
131
141
  default:
132
- throw new Error("Use talentos agent link | repair | status | list | unlink | logs | native | project.");
142
+ throw new Error("Use talentos agent link | repair | status | list | unlink | logs | connect-session | disconnect-session | native | project.");
133
143
  }
134
144
  }
135
145
  export async function installLinkedAgent(parsed, dependencies = {}) {
@@ -222,6 +232,13 @@ export async function installLinkedAgent(parsed, dependencies = {}) {
222
232
  }
223
233
  await rm(pendingPath, { force: true });
224
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
+ }
225
242
  const service = await (dependencies.install ??
226
243
  (async (config) => {
227
244
  if (process.platform !== "win32") {
@@ -243,6 +260,7 @@ async function showAgents(parsed) {
243
260
  provider: status.provider,
244
261
  state: status.presence,
245
262
  lastSeenAt: status.lastSeenAt,
263
+ terminal: await terminalLabel(agent),
246
264
  });
247
265
  }
248
266
  catch (error) {
@@ -265,12 +283,24 @@ async function showAgents(parsed) {
265
283
  ? renderTable(["Agent", "Provider", "Status", "ID"], rows.map((row) => [
266
284
  row.name,
267
285
  row.provider,
268
- row.hint ?? row.state,
286
+ [row.hint ?? row.state, row.terminal].filter(Boolean).join(" · "),
269
287
  row.agentId,
270
288
  ]))
271
289
  : "No agents linked on this machine. Get a setup prompt from TalentOS.");
272
290
  }
273
291
  }
292
+ // Only an agent whose terminal was ever connected gets a column: the rest of
293
+ // the table stays as it was.
294
+ async function terminalLabel(agent) {
295
+ const { terminalState } = await import("./agent-session.js");
296
+ const state = await terminalState(agent, homeDir());
297
+ return state === "off" ? undefined : TERMINAL_LABELS[state];
298
+ }
299
+ const TERMINAL_LABELS = {
300
+ on: "terminal on",
301
+ reconnect: "terminal needs reconnect (talentos agent connect-session)",
302
+ unknown: "terminal unreachable",
303
+ };
274
304
  function agentAccessEnded(error) {
275
305
  return (error instanceof AgentHttpError &&
276
306
  (error.status === 401 || error.status === 410));
@@ -283,6 +313,10 @@ async function unlinkLocal(parsed) {
283
313
  return;
284
314
  }
285
315
  const revoked = await unlinkRemoteAgent(agent);
316
+ // The terminal's key died with the agent; its entries must not linger.
317
+ if (await readSessionKey(agent.agentId, homeDir())) {
318
+ await (await import("./agent-session.js")).disconnectSession(agent, homeDir());
319
+ }
286
320
  await uninstallAgentService(agent);
287
321
  await rm(agentConfigPath(agent.agentId), { force: true });
288
322
  emit(`Unlinked ${redactAgentOutput(agent.name)} on this machine.`);
@@ -318,7 +352,7 @@ async function showLogs(parsed) {
318
352
  await log.close();
319
353
  }
320
354
  }
321
- async function selectAgents(parsed, single = false, home) {
355
+ export async function selectAgents(parsed, single = false, home) {
322
356
  const selector = parsed.options.agent ?? parsed.args[0];
323
357
  const agents = (await localAgents(home)).filter((agent) => !selector || agent.agentId === selector || agent.name === selector);
324
358
  if (single && agents.length > 1) {
@@ -8,7 +8,7 @@ const DONE = "✓";
8
8
  const SKIPPED = "·";
9
9
  const TRAILING_PUNCTUATION = /[.:\s]+$/;
10
10
  /**
11
- * The one command a new member runs: sign in, configure every coding agent on
11
+ * The one command a new member runs: sign in, configure every agent on
12
12
  * this machine at user level, and drop the company's skills where those agents
13
13
  * already look for them.
14
14
  */
@@ -16,7 +16,7 @@ export async function runInit(parsed) {
16
16
  const session = await signIn(parsed);
17
17
  const targets = chosenTargets(parsed.options.for);
18
18
  if (targets.length === 0) {
19
- step(false, "No coding agent found. Re-run with --for claude|cursor|codex.");
19
+ step(false, "No agent found. Re-run with --for claude|cursor|codex.");
20
20
  }
21
21
  const configured = [];
22
22
  for (const target of targets) {
@@ -6,7 +6,7 @@ import { fetchWhoami, renderWhoami } from "./whoami.js";
6
6
  const POLL_INTERVAL_MS = 2000;
7
7
  /** A 5xx or a dropped wifi must not discard a key the member just approved. */
8
8
  const MAX_POLL_FAILURES = 5;
9
- const REJECTED_KEY = "TalentOS rejected that key. Create a new one in Settings → Agents & CLI, or run `talentos login` without --key.";
9
+ const REJECTED_KEY = "TalentOS rejected that key. Create a new one in Settings → Agents, or run `talentos login` without --key.";
10
10
  export async function runLogin(parsed) {
11
11
  const session = await authorize(parsed);
12
12
  emit(`${bold("Logged in.")}\n${renderWhoami(session.who)}`);
@@ -72,7 +72,7 @@ export function approvalNotice(start) {
72
72
  const heading = `Approve this device in TalentOS:\n\n ${bold(start.code)}\n`;
73
73
  return start.authorizeUrl
74
74
  ? `${heading} ${start.authorizeUrl}\n`
75
- : `${heading}\nOpen TalentOS in your browser, go to Settings → Agents & CLI, and enter this code.\n`;
75
+ : `${heading}\nOpen TalentOS in your browser, go to Settings → Agents, and enter this code.\n`;
76
76
  }
77
77
  /** Polls until the member decides, riding out transient failures. */
78
78
  export async function pollUntilDecided(apiUrl, start, rawKey, deps = { fetchStatus: fetchLoginStatus, wait: sleep }) {
@@ -25,6 +25,47 @@ const NPM_ENV = new Set([
25
25
  "NO_PROXY",
26
26
  "NODE_EXTRA_CA_CERTS",
27
27
  ]);
28
+ /** The environment npm runs with: a PATH that finds this Node, and only the
29
+ * variables npm needs (proxy, CA bundle, `npm_config_*`), never the agent's. */
30
+ export function npmSpawnEnv() {
31
+ const env = {
32
+ PATH: `${process.env.PATH ?? servicePathEnv()}:${dirname(process.execPath)}`,
33
+ };
34
+ for (const [key, value] of Object.entries(process.env)) {
35
+ if ((NPM_ENV.has(key) || key.toLowerCase().startsWith("npm_config_")) &&
36
+ value) {
37
+ env[key] = value;
38
+ }
39
+ }
40
+ return env;
41
+ }
42
+ /**
43
+ * The Nodes the launcher would consider starting the gateway with, in its
44
+ * order: TALENTOS_NODE, the `cli/node-path` hint, each PATH entry, the fixed
45
+ * system paths, then installed nvm versions. Not filtered for the version a
46
+ * candidate runs: the caller probes that.
47
+ */
48
+ export async function launcherNodeCandidates(home = homeDir(), env = process.env) {
49
+ const found = [];
50
+ if (env.TALENTOS_NODE) {
51
+ found.push(env.TALENTOS_NODE);
52
+ }
53
+ const hint = (await readFile(join(home, ".talentos/cli/node-path"), "utf8").catch(() => "")).split("\n")[0];
54
+ if (hint) {
55
+ found.push(hint);
56
+ }
57
+ for (const dir of (env.PATH ?? "").split(":")) {
58
+ if (dir) {
59
+ found.push(join(dir, "node"));
60
+ }
61
+ }
62
+ found.push(...FIXED_NODE_CANDIDATES);
63
+ const nvm = join(home, NVM_NODE_VERSIONS);
64
+ for (const name of (await readdir(nvm).catch(() => [])).sort()) {
65
+ found.push(join(nvm, name, "bin/node"));
66
+ }
67
+ return [...new Set(found)];
68
+ }
28
69
  export function gatewayLauncherPath(home = homeDir()) {
29
70
  return join(home, ".talentos", "bin", "talentos-gateway");
30
71
  }
@@ -43,6 +84,12 @@ export function servicePathEnv(home = homeDir()) {
43
84
  ]),
44
85
  ].join(":");
45
86
  }
87
+ // Where the launcher looks for a Node after TALENTOS_NODE, the node-path hint
88
+ // and PATH. One list for the shell text below and for `launcherNodeCandidates`,
89
+ // so an update's Node check asks about the Nodes the launcher would start.
90
+ const FIXED_NODE_CANDIDATES = ["/opt/homebrew/bin/node", "/usr/local/bin/node"];
91
+ // Under the home directory; nvm has no stable system bin.
92
+ const NVM_NODE_VERSIONS = ".nvm/versions/node";
46
93
  // No user paths are interpolated into executable shell text. The Node hint is data.
47
94
  const LAUNCHER = `#!/bin/sh
48
95
  set -f
@@ -92,14 +139,14 @@ for dir in \${PATH:-}; do
92
139
  IFS=:
93
140
  done
94
141
  IFS=$old_ifs
95
- for candidate in /opt/homebrew/bin/node /usr/local/bin/node; do
142
+ for candidate in ${FIXED_NODE_CANDIDATES.join(" ")}; do
96
143
  if qualifies "$candidate"; then
97
144
  start "$candidate" "$@"
98
145
  fi
99
146
  done
100
147
  # nvm has no stable system bin; discover surviving installations at startup.
101
148
  set +f
102
- for candidate in "$root"/../.nvm/versions/node/*/bin/node; do
149
+ for candidate in "$root"/../${NVM_NODE_VERSIONS}/*/bin/node; do
103
150
  if qualifies "$candidate"; then start "$candidate" "$@"; fi
104
151
  done
105
152
  message="TalentOS gateway requires Node 22.23.4+ or 24.22.1+ (found \${seen_version:-unknown}). Install Node, then run talentos agent repair."
@@ -268,15 +315,7 @@ export async function installSharedGateway(options = {}) {
268
315
  await copyPackage(source, join(temporary, "node_modules/talentos"));
269
316
  }
270
317
  else {
271
- const npmEnv = {
272
- PATH: `${process.env.PATH ?? servicePathEnv()}:${dirname(process.execPath)}`,
273
- };
274
- for (const [key, value] of Object.entries(process.env)) {
275
- if ((NPM_ENV.has(key) || key.toLowerCase().startsWith("npm_config_")) &&
276
- value) {
277
- npmEnv[key] = value;
278
- }
279
- }
318
+ const npmEnv = npmSpawnEnv();
280
319
  try {
281
320
  await exec("npm", [
282
321
  "install",
package/dist/index.js CHANGED
@@ -4,13 +4,13 @@ import { redactAgentOutput } from "./agent-link.js";
4
4
  import { parseArgv } from "./args.js";
5
5
  import { emit } from "./format.js";
6
6
  import { ProviderBinaryError } from "./provider-binary.js";
7
- const USAGE = `talentos — your team's skills, memory and Talent, from any coding agent.
7
+ const USAGE = `talentos — your team's skills, memory and Talent, from any agent.
8
8
 
9
9
  Usage: talentos <command> [options]
10
10
 
11
11
  Commands:
12
12
  init Connect this machine's agents to TalentOS
13
- agent <link|repair|status|list|unlink|logs> Bring your own agent into Rooms
13
+ agent <link|repair|status|list|unlink|logs|connect-session> Bring your own agent into Rooms
14
14
  login Authorize this machine
15
15
  logout Forget the key stored on this machine
16
16
  whoami Show the member and org this key acts as
@@ -35,15 +35,24 @@ talentos agent unlink [name] [--agent <id>]
35
35
  talentos agent logs [--agent <id>]
36
36
  talentos agent repair [--agent <id>]
37
37
  talentos agent serve --agent <id>
38
+ talentos agent connect-session [--agent <id>] [--for claude|codex|all]
39
+ talentos agent disconnect-session [--agent <id>] [--for claude|codex|all]
38
40
 
39
41
  The link command checks the provider's CLI login, mints the key locally, and
40
42
  installs one user service per agent. Only the key hash is sent to redeem.
41
43
  Config is private under ~/.talentos/agents. Never print the setup fragment.
42
- Serve is supplied by the S6 gateway release; Connected requires its heartbeat.`,
44
+ Serve is supplied by the S6 gateway release; Connected requires its heartbeat.
45
+
46
+ connect-session lets your everyday Claude Code or Codex act in the agent's rooms
47
+ as that agent. It gets a key of its own, kept in a private file under
48
+ ~/.talentos/agents (never in the client's config or arguments), and registers a
49
+ talentos-room server. disconnect-session stops the key and removes the entry
50
+ from every client (or only --for one);
51
+ unlinking the agent stops it too.`,
43
52
  init: `talentos init [--for claude|cursor|codex|all] [--no-pull] [--name <device>]
44
53
 
45
54
  One command: signs you in (skipped when your stored key still works), writes the
46
- TalentOS MCP config for every coding agent on this machine at USER level, and
55
+ TalentOS MCP config for every agent on this machine at USER level, and
47
56
  pulls the company's skills into ./.agents/skills (plus ./.claude/skills when
48
57
  Claude Code is here). Nothing else is written inside the repo. Safe to re-run.
49
58