talentos 1.4.22 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,174 @@
1
+ import { rm } from "node:fs/promises";
2
+ import { resolve } from "node:path";
3
+ import { withClient } from "../client.js";
4
+ import { emit, emitJson, renderTable, warn } from "../format.js";
5
+ import { homeDir, pullDirs } from "../install.js";
6
+ import { escapesRoot, SKILL_ENTRY, writeSkillPackage } from "../skill-files.js";
7
+ import { hashFiles, readManifest, readText, sha, writeManifest, } from "../skill-sync-state.js";
8
+ import { folderFor, mapConcurrent, PULL_LIMIT, scopeFrom, } from "./skills.js";
9
+ const FETCH_CONCURRENCY = 4;
10
+ /**
11
+ * `talentos skills sync`: bring the skill folders up to date, touching only
12
+ * what changed, and never overwrite work you did here.
13
+ *
14
+ * The rule, per skill folder:
15
+ * - Not here yet: written.
16
+ * - Written by an earlier sync and you have not touched it: updated when
17
+ * TalentOS has a newer version, otherwise not rewritten at all.
18
+ * - You edited, deleted or replaced a file the sync wrote, and TalentOS has
19
+ * since published a newer version: the whole skill is left exactly as it is
20
+ * ("kept") until you run `skills pull`. A skill you deleted stays deleted
21
+ * until then too.
22
+ * - A folder this sync did not write (yours, or from `skills pull`): left alone
23
+ * ("differs") unless every file already matches TalentOS.
24
+ * - Files you added, and skills TalentOS no longer lists: never deleted.
25
+ */
26
+ export async function runSkillsSync(parsed) {
27
+ const dirs = pullDirs({
28
+ home: homeDir(),
29
+ target: parsed.options.for,
30
+ global: parsed.options.global,
31
+ to: parsed.options.to,
32
+ });
33
+ const results = await withClient(parsed.options["api-url"], (client) => syncInto(client, dirs, scopeFrom(parsed.options)));
34
+ if (parsed.options.json) {
35
+ emitJson(results);
36
+ return;
37
+ }
38
+ const attention = results.filter((result) => result.status === "kept" || result.status === "differs");
39
+ for (const result of attention) {
40
+ warn(attentionLine(result));
41
+ }
42
+ if (parsed.options.quiet) {
43
+ return;
44
+ }
45
+ const changed = results.filter((result) => result.status === "added" || result.status === "updated");
46
+ if (changed.length === 0 && attention.length === 0) {
47
+ emit("Skills are up to date.");
48
+ return;
49
+ }
50
+ emit([
51
+ renderTable(["SKILL", "STATUS"], [...changed, ...attention].map((result) => [
52
+ result.slug,
53
+ STATUS_TEXT[result.status],
54
+ ])),
55
+ `${changed.length} changed, ${attention.length} left alone in ${dirs.map((dir) => resolve(dir)).join(", ")}`,
56
+ ].join("\n\n"));
57
+ }
58
+ const STATUS_TEXT = {
59
+ added: "added",
60
+ differs: "left alone (a different version is already here)",
61
+ kept: "kept your edits (TalentOS has a newer version)",
62
+ unchanged: "up to date",
63
+ updated: "updated",
64
+ };
65
+ function attentionLine(result) {
66
+ return `${result.slug}: ${STATUS_TEXT[result.status]}. \`talentos skills pull\` replaces it with TalentOS's version.`;
67
+ }
68
+ export async function syncInto(client, dirs, scope) {
69
+ const { data } = await client.call("list_skills", { scope, limit: PULL_LIMIT });
70
+ if (data.skills.length === PULL_LIMIT) {
71
+ warn(`Synced the first ${PULL_LIMIT} skills; there may be more. Narrow with --mine, --company or -q <query>.`);
72
+ }
73
+ const fetched = new Map();
74
+ const packageOf = (id) => {
75
+ let pending = fetched.get(id);
76
+ if (!pending) {
77
+ pending = client
78
+ .call("get_skill", { skillId: id })
79
+ .then((result) => result.data);
80
+ fetched.set(id, pending);
81
+ }
82
+ return pending;
83
+ };
84
+ const results = [];
85
+ for (const dir of dirs) {
86
+ results.push(...(await syncDir(dir, data.skills, packageOf)));
87
+ }
88
+ return results;
89
+ }
90
+ async function syncDir(dir, skills, packageOf) {
91
+ const manifest = await readManifest(dir);
92
+ const before = JSON.stringify(manifest);
93
+ const taken = new Set();
94
+ const planned = [...skills]
95
+ .sort((a, b) => a.slug.localeCompare(b.slug))
96
+ .map((skill) => ({ folder: folderFor(skill, taken), skill }));
97
+ // A skill whose id and version match the last sync is not fetched at all.
98
+ const stale = await mapConcurrent(planned, FETCH_CONCURRENCY, async (item) => {
99
+ const entry = manifest[item.folder];
100
+ const current = entry?.id === item.skill.id && entry.version === item.skill.version;
101
+ return current ? undefined : await packageOf(item.skill.id);
102
+ });
103
+ const results = [];
104
+ for (const [index, item] of planned.entries()) {
105
+ const pkg = stale[index];
106
+ results.push({
107
+ dir,
108
+ slug: item.folder,
109
+ status: pkg === undefined
110
+ ? "unchanged"
111
+ : await syncOne(dir, item.folder, pkg, manifest),
112
+ });
113
+ }
114
+ if (JSON.stringify(manifest) !== before) {
115
+ await writeManifest(dir, manifest);
116
+ }
117
+ return results;
118
+ }
119
+ async function syncOne(dir, folder, pkg, manifest) {
120
+ const root = resolve(dir, folder);
121
+ const remote = hashFiles(pkg.files);
122
+ const recorded = manifest[folder]?.id === pkg.id ? manifest[folder] : undefined;
123
+ const local = await localHashes(root, [
124
+ ...Object.keys(remote),
125
+ ...Object.keys(recorded?.files ?? {}),
126
+ ]);
127
+ const record = () => {
128
+ manifest[folder] = { files: remote, id: pkg.id, version: pkg.version };
129
+ };
130
+ if (sameHashes(local, remote, Object.keys(remote))) {
131
+ // Already exactly TalentOS's version, however it got here.
132
+ record();
133
+ return "unchanged";
134
+ }
135
+ if (recorded === undefined) {
136
+ if (local[SKILL_ENTRY] !== undefined) {
137
+ return "differs";
138
+ }
139
+ await writeSkillPackage(dir, folder, pkg.files);
140
+ record();
141
+ return "added";
142
+ }
143
+ if (!sameHashes(local, recorded.files, Object.keys(recorded.files))) {
144
+ return "kept";
145
+ }
146
+ await writeSkillPackage(dir, folder, pkg.files);
147
+ for (const path of Object.keys(recorded.files)) {
148
+ if (!(path in remote)) {
149
+ await removeInside(root, path);
150
+ }
151
+ }
152
+ record();
153
+ return "updated";
154
+ }
155
+ async function localHashes(root, paths) {
156
+ const hashes = {};
157
+ for (const path of new Set(paths)) {
158
+ if (escapesRoot(root, path)) {
159
+ continue;
160
+ }
161
+ const text = await readText(resolve(root, path));
162
+ hashes[path] = text === undefined ? undefined : sha(text);
163
+ }
164
+ return hashes;
165
+ }
166
+ function sameHashes(local, expected, paths) {
167
+ return paths.every((path) => local[path] === expected[path]);
168
+ }
169
+ /** Never follows a manifest path out of the skill folder. */
170
+ async function removeInside(root, path) {
171
+ if (!escapesRoot(root, path)) {
172
+ await rm(resolve(root, path), { force: true });
173
+ }
174
+ }
@@ -4,11 +4,12 @@ import { withClient } from "../client.js";
4
4
  import { bold, emit, emitJson, emitLink, formatDate, renderTable, truncate, warn, } from "../format.js";
5
5
  import { homeDir, pullDirs } from "../install.js";
6
6
  import { readSkillPackage, SKILL_ENTRY, writeSkillPackage, } from "../skill-files.js";
7
+ import { hashFiles, readManifest, writeManifest } from "../skill-sync-state.js";
7
8
  const SUMMARY_WIDTH = 60;
8
9
  /** Enough to hide the round-trip latency of 100 skills without flooding. */
9
10
  const PULL_CONCURRENCY = 4;
10
11
  /** The server's ceiling: asking for less silently truncates at its default 50. */
11
- const PULL_LIMIT = 100;
12
+ export const PULL_LIMIT = 100;
12
13
  const ID_SUFFIX_LENGTH = 6;
13
14
  export async function runSkills(parsed) {
14
15
  switch (parsed.action) {
@@ -20,10 +21,13 @@ export async function runSkills(parsed) {
20
21
  return await pushSkill(parsed);
21
22
  case "pull":
22
23
  return await pullSkills(parsed);
24
+ case "sync":
25
+ // Imported here, not at the top: skills-sync.ts imports this file.
26
+ return await (await import("./skills-sync.js")).runSkillsSync(parsed);
23
27
  case "share":
24
28
  return shareSkill();
25
29
  default:
26
- throw new Error("Usage: talentos skills <list|get|push|pull> — see `talentos skills --help`");
30
+ throw new Error("Usage: talentos skills <list|get|push|pull|sync> — see `talentos skills --help`");
27
31
  }
28
32
  }
29
33
  export function scopeFrom(options) {
@@ -140,6 +144,9 @@ export async function pullInto(client, dirs, scope) {
140
144
  const packages = await mapConcurrent(data.skills, PULL_CONCURRENCY, async (skill) => (await client.call("get_skill", { skillId: skill.id })).data);
141
145
  const results = [];
142
146
  const taken = new Set();
147
+ // A pull overwrites on purpose, so what it writes is what `skills sync`
148
+ // later keeps current: record it the way sync does.
149
+ const manifests = new Map(await Promise.all(dirs.map(async (dir) => [dir, await readManifest(dir)])));
143
150
  // Fetched in parallel, written in slug order, so a run is reproducible.
144
151
  for (const pkg of [...packages].sort((a, b) => a.slug.localeCompare(b.slug))) {
145
152
  const slug = folderFor(pkg, taken);
@@ -147,13 +154,26 @@ export async function pullInto(client, dirs, scope) {
147
154
  for (const dir of dirs) {
148
155
  created = created || !(await exists(join(dir, slug, SKILL_ENTRY)));
149
156
  await writeSkillPackage(dir, slug, pkg.files);
157
+ const manifest = manifests.get(dir);
158
+ if (manifest) {
159
+ manifest[slug] = {
160
+ files: hashFiles(pkg.files),
161
+ id: pkg.id,
162
+ version: pkg.version,
163
+ };
164
+ }
150
165
  }
151
166
  results.push({ slug, created });
152
167
  }
168
+ for (const [dir, manifest] of manifests) {
169
+ if (results.length > 0) {
170
+ await writeManifest(dir, manifest);
171
+ }
172
+ }
153
173
  return results;
154
174
  }
155
175
  /** Two skills may share a slug; the second keeps its own folder, not the first's. */
156
- function folderFor(pkg, taken) {
176
+ export function folderFor(pkg, taken) {
157
177
  if (!taken.has(pkg.slug)) {
158
178
  taken.add(pkg.slug);
159
179
  return pkg.slug;
@@ -164,7 +184,7 @@ function folderFor(pkg, taken) {
164
184
  return unique;
165
185
  }
166
186
  /** Runs `work` over `items` with at most `limit` in flight, keeping order. */
167
- async function mapConcurrent(items, limit, work) {
187
+ export async function mapConcurrent(items, limit, work) {
168
188
  const results = [];
169
189
  let next = 0;
170
190
  const worker = async () => {
@@ -0,0 +1,77 @@
1
+ import { withClient } from "../client.js";
2
+ import { emit, emitJson } from "../format.js";
3
+ import { CliError, cliContractEnabled, nextActions, withApiUrl, } from "../output.js";
4
+ import { watch } from "../watch.js";
5
+ const RUNNING = new Set(["queued", "working"]);
6
+ export async function runTask(parsed) {
7
+ if (!cliContractEnabled()) {
8
+ throw new CliError("FEATURE_DISABLED", "Task commands need HEADLESS_CLI_V1=true until release.");
9
+ }
10
+ const taskId = parsed.args[0];
11
+ if (!taskId ||
12
+ parsed.args.length !== 1 ||
13
+ !["status", "watch"].includes(parsed.action ?? "")) {
14
+ throw new CliError("INVALID_ARGUMENT", "Usage: talentos task <status|watch> <id> [--json]");
15
+ }
16
+ await withClient(parsed.options["api-url"], async (client) => {
17
+ const read = async (previous, waitSeconds, signal) => {
18
+ const { data } = await client.call("get_task", {
19
+ taskId,
20
+ waitSeconds,
21
+ ...(previous ? { since: previous.version } : {}),
22
+ }, { signal });
23
+ return data;
24
+ };
25
+ const task = parsed.action === "watch"
26
+ ? await watch({
27
+ read,
28
+ isRunning: (value) => RUNNING.has(value.state),
29
+ version: (value) => value.version,
30
+ onChange: (value) => {
31
+ if (RUNNING.has(value.state)) {
32
+ emit(renderTask(value));
33
+ }
34
+ },
35
+ })
36
+ : await read(undefined, 0);
37
+ nextActions(taskNext(task, parsed.options["api-url"]));
38
+ if (parsed.options.json) {
39
+ emitJson(task);
40
+ }
41
+ else {
42
+ emit(renderTask(task));
43
+ for (const action of taskNext(task, parsed.options["api-url"])) {
44
+ emit(`Next: ${action.command} — ${action.why}`);
45
+ }
46
+ }
47
+ });
48
+ }
49
+ function taskNext(task, apiUrl) {
50
+ if (["done", "failed", "cancelled"].includes(task.state)) {
51
+ return [];
52
+ }
53
+ let why = "Keep following the task without starting another run.";
54
+ if (task.state === "needs_input") {
55
+ why = `The member must ${task.question?.kind === "approval" ? "approve" : "answer"} in TalentOS${task.link ? ` (${task.link})` : ""}; follow again afterwards.`;
56
+ }
57
+ else if (task.state === "stale") {
58
+ why = "No recent progress; follow again to see whether the Talent resumes.";
59
+ }
60
+ return [
61
+ { command: withApiUrl(`talentos task watch ${task.taskId}`, apiUrl), why },
62
+ ];
63
+ }
64
+ function renderTask(task) {
65
+ return [
66
+ `Task ${task.taskId}: ${task.state}`,
67
+ ...task.progress,
68
+ ...(task.question ? [task.question.text] : []),
69
+ ...(task.result
70
+ ? [
71
+ task.result.text,
72
+ ...task.result.files.map((file) => `${file.title}${file.url ? `: ${file.url}` : ""}`),
73
+ ]
74
+ : []),
75
+ ...(task.link ? [`Open: ${task.link}`] : []),
76
+ ].join("\n");
77
+ }
@@ -0,0 +1,56 @@
1
+ import { withClient } from "../client.js";
2
+ import { emitJson } from "../format.js";
3
+ import { CliError, cliContractEnabled } from "../output.js";
4
+ export async function runTools(parsed) {
5
+ if (!cliContractEnabled()) {
6
+ throw new CliError("FEATURE_DISABLED", "Tool commands need HEADLESS_CLI_V1=true until release.");
7
+ }
8
+ if (parsed.group === "tools") {
9
+ if (parsed.args.length) {
10
+ throw new CliError("INVALID_ARGUMENT", "Usage: talentos tools [--json]");
11
+ }
12
+ await withClient(parsed.options["api-url"], async (client) => {
13
+ const tools = [];
14
+ let cursor;
15
+ do {
16
+ const page = await client.listTools(cursor);
17
+ tools.push(...page.tools);
18
+ cursor = page.nextCursor;
19
+ } while (cursor);
20
+ emitJson({ tools });
21
+ });
22
+ return;
23
+ }
24
+ const [name, raw] = parsed.args;
25
+ if (!name ||
26
+ parsed.args.length > 2 ||
27
+ (raw !== undefined && !parsed.options.json)) {
28
+ throw new CliError("INVALID_ARGUMENT", "Usage: talentos call <tool> [--json '<args>']");
29
+ }
30
+ let args = {};
31
+ if (raw !== undefined) {
32
+ try {
33
+ args = JSON.parse(raw);
34
+ }
35
+ catch {
36
+ throw new CliError("INVALID_ARGUMENT", "Tool arguments must be a valid JSON object.");
37
+ }
38
+ }
39
+ if (args === null || typeof args !== "object" || Array.isArray(args)) {
40
+ throw new CliError("INVALID_ARGUMENT", "Tool arguments must be a JSON object.");
41
+ }
42
+ await withClient(parsed.options["api-url"], async (client) => {
43
+ const result = await client.callTool({
44
+ name,
45
+ arguments: args,
46
+ });
47
+ if (result.isError) {
48
+ const message = result.content
49
+ .filter((block) => block.type === "text")
50
+ .map((block) => block.text)
51
+ .join("\n");
52
+ throw new CliError("TOOL_ERROR", message || `Tool ${name} failed.`, undefined, result);
53
+ }
54
+ emitJson(result);
55
+ });
56
+ }
package/dist/config.js CHANGED
@@ -3,6 +3,13 @@ import { homedir } from "node:os";
3
3
  import { join } from "node:path";
4
4
  const TRAILING_SLASHES = /\/+$/;
5
5
  export const DEFAULT_API_URL = "https://woozy-oyster-769.convex.site";
6
+ /**
7
+ * The remote MCP address clients are pointed at. The one place it is written:
8
+ * `plugin/plugins/talentos/.mcp.json` ships the same value (a test holds them
9
+ * equal) and `init` renders any other address into its staged copy. A branded
10
+ * MCP domain changes it here and in that file, nowhere else.
11
+ */
12
+ export const DEFAULT_MCP_URL = `${DEFAULT_API_URL}/mcp`;
6
13
  export function configDir(env = process.env) {
7
14
  // An empty XDG_CONFIG_HOME is unset per the XDG spec; taking it literally
8
15
  // would write the key into whatever directory the CLI was started from.
@@ -21,6 +28,33 @@ export function resolveApiUrl(override, fallback) {
21
28
  const chosen = override === undefined || override.trim() === "" ? fallback : override;
22
29
  return chosen.trim().replace(TRAILING_SLASHES, "");
23
30
  }
31
+ /** Validate the optional origin before printing a bearer-bearing client config. */
32
+ export function resolveMcpOrigin(apiUrl, configured = process.env.MCP_PUBLIC_ORIGIN) {
33
+ if (!configured?.trim()) {
34
+ return apiUrl;
35
+ }
36
+ // The published CLI has no dependency on the app's source-only packages.
37
+ const url = new URL(configured.trim());
38
+ if (url.protocol !== "https:" ||
39
+ url.username ||
40
+ url.password ||
41
+ url.pathname !== "/" ||
42
+ url.search ||
43
+ url.hash) {
44
+ throw new Error("MCP_PUBLIC_ORIGIN must be an HTTPS origin without credentials, path, query or fragment.");
45
+ }
46
+ return url.origin;
47
+ }
48
+ /**
49
+ * The MCP url a client is given: `MCP_PUBLIC_ORIGIN` when it is set (the
50
+ * branded address), else the default API url gets `DEFAULT_MCP_URL` and any
51
+ * other (a staging key's) keeps its own `/mcp`, so a key never reaches the
52
+ * wrong deployment. Every client config and the staged plugin use this.
53
+ */
54
+ export function mcpUrlFor(apiUrl, configured = process.env.MCP_PUBLIC_ORIGIN) {
55
+ const origin = resolveMcpOrigin(resolveApiUrl(apiUrl, DEFAULT_API_URL), configured);
56
+ return origin === DEFAULT_API_URL ? DEFAULT_MCP_URL : `${origin}/mcp`;
57
+ }
24
58
  /**
25
59
  * File values first, then env overrides. A machine with TALENTOS_API_KEY set
26
60
  * (CI, a container, `codex` launching the stdio proxy) must never fall back to
package/dist/format.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { machineOutput } from "./output.js";
1
2
  const WHITESPACE = /\s+/g;
2
3
  const ANSI = {
3
4
  bold: "",
@@ -26,6 +27,12 @@ export function renderTable(headers, rows) {
26
27
  return [dim(line(headers)), ...rows.map(line)].join("\n");
27
28
  }
28
29
  export function emit(text) {
30
+ const output = machineOutput();
31
+ if (output) {
32
+ output.message = text;
33
+ process.stderr.write(`${text}\n`);
34
+ return;
35
+ }
29
36
  process.stdout.write(`${text}\n`);
30
37
  }
31
38
  /** The app deep link a tool result carries; absent when the backend has no app url. */
@@ -39,6 +46,11 @@ export function warn(text) {
39
46
  process.stderr.write(`${dim(text)}\n`);
40
47
  }
41
48
  export function emitJson(value) {
49
+ const output = machineOutput();
50
+ if (output) {
51
+ output.data = value;
52
+ return;
53
+ }
42
54
  process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
43
55
  }
44
56
  export function truncate(text, max) {
package/dist/index.js CHANGED
@@ -2,7 +2,8 @@
2
2
  import { readFileSync } from "node:fs";
3
3
  import { redactAgentOutput } from "./agent-link.js";
4
4
  import { parseArgv } from "./args.js";
5
- import { emit } from "./format.js";
5
+ import { emit, emitJson } from "./format.js";
6
+ import { CliError, cliContractEnabled, machineOutput, runJsonCommand, } from "./output.js";
6
7
  import { ProviderBinaryError } from "./provider-binary.js";
7
8
  const USAGE = `talentos — your team's skills, memory and Talent, from any agent.
8
9
 
@@ -10,25 +11,41 @@ Usage: talentos <command> [options]
10
11
 
11
12
  Commands:
12
13
  init Connect this machine's agents to TalentOS
14
+ doctor Check what is connected and how to fix what is not
13
15
  agent <link|repair|status|list|unlink|logs|connect-session> Bring your own agent into Rooms
14
16
  login Authorize this machine
15
17
  logout Forget the key stored on this machine
16
18
  whoami Show the member and org this key acts as
17
19
  mcp Run the stdio MCP proxy (for stdio-only clients)
18
20
  mcp install <target> [--apply] Configure one client, or print its snippet
19
- skills <list|get|push|pull|share> Move skills; sharing stays in TalentOS
21
+ skills <list|get|push|pull|sync|share> Move skills; sharing stays in TalentOS
20
22
  memory <search|add> Read and write personal and company memory
21
23
  ask "<message>" Delegate work to your Talent
22
24
  routines <list|run> See and run your routines
25
+ tools List the tools this member can use with input schemas
26
+ call <tool> [--json '<args>'] Call any visible MCP tool
27
+ task <status|watch> <id> Follow a delegated task without starting work
23
28
 
24
29
  Options:
25
- --json Print the raw JSON result
30
+ --json Print one JSON result (HEADLESS_CLI_V1=true); progress goes to stderr
26
31
  --api-url <url> Override the TalentOS API url
27
32
  -h, --help Show help
28
33
  -v, --version Show the version
29
34
 
30
35
  Run \`talentos <command> --help\` for command options.`;
31
36
  const GROUP_USAGE = {
37
+ tools: "talentos tools [--json]\n\nLists the remote MCP tools and their input schemas, under this connection's permissions.",
38
+ call: `talentos call <tool> [--json '<args>']
39
+
40
+ Forwards one tool call with a JSON object (default {}). The MCP server owns
41
+ validation, visibility, permissions and approvals. Returns the full MCP result;
42
+ a tool error exits nonzero. Calls are never retried.`,
43
+ task: `talentos task status <id> [--json]
44
+ talentos task watch <id> [--json]
45
+
46
+ Read a delegate_task result through get_task. Watch waits for changes on the
47
+ server, stopping on completion, stale work, or a question for the member.
48
+ After ten minutes it returns the latest state with a continuation command.`,
32
49
  agent: `talentos agent link --url <setup-url-with-#token> [--yes] [--name <device>]
33
50
  talentos agent status | list [--json] [--agent <id>]
34
51
  talentos agent unlink [name] [--agent <id>]
@@ -49,7 +66,13 @@ as that agent. It gets a key of its own, kept in a private file under
49
66
  talentos-room server. disconnect-session stops the key and removes the entry
50
67
  from every client (or only --for one);
51
68
  unlinking the agent stops it too.`,
52
- init: `talentos init [--for claude|cursor|codex|all] [--no-pull] [--name <device>]
69
+ doctor: `talentos doctor [--json] [--api-url <url>]
70
+
71
+ Says in plain words whether TalentOS answers with the key on this machine and
72
+ whether Claude Code, Cursor and Codex are set up, with the one fix for each
73
+ problem. Changes nothing and never prints a key. Exits 1 when something needs a
74
+ fix.`,
75
+ init: `talentos init [--for claude|cursor|codex|all] [--no-pull] [--oauth] [--name <device>]
53
76
 
54
77
  One command: signs you in (skipped when your stored key still works), writes the
55
78
  TalentOS MCP config for every agent on this machine at USER level, and
@@ -58,6 +81,11 @@ Claude Code is here). Nothing else is written inside the repo. Safe to re-run.
58
81
 
59
82
  --for <agent> Configure these agents instead of the detected ones
60
83
  --no-pull Configure the agents but do not write any skills
84
+ --oauth Sign in through the browser instead of a key in each agent's
85
+ config: installs the Claude Code plugin (primer, /talentos
86
+ commands) and writes a keyless Codex entry; Cursor keeps its key. Also
87
+ on with HEADLESS_SETUP_V1=true. Needs a server that accepts
88
+ these clients.
61
89
  --name <device> Device name shown on the approval screen`,
62
90
  login: `talentos login [--key <key>] [--api-url <url>] [--name <device>]
63
91
 
@@ -78,11 +106,16 @@ that client's user-level config (claude, cursor or codex).`,
78
106
  talentos skills get <id|slug> [--out <dir>]
79
107
  talentos skills push <SKILL.md|dir> [--id <skillId>]
80
108
  talentos skills pull [--for claude|cursor|codex|all] [--global] [--to <dir>] [--mine|--company]
109
+ talentos skills sync [--for claude|cursor|codex|all] [--global] [--to <dir>] [--mine|--company] [--quiet]
81
110
  talentos skills share <id> Refuses: Share this Skill from TalentOS.
82
111
 
83
112
  \`pull\` writes to ./.agents/skills by default; \`--for claude\` writes to
84
113
  ./.claude/skills, \`--for all\` writes both, and \`--global\` puts them under your
85
- home directory. An explicit \`--to\` wins.`,
114
+ home directory. An explicit \`--to\` wins.
115
+
116
+ \`sync\` rewrites only skills TalentOS changed, and never overwrites work you did
117
+ here: a skill you edited stays as it is (and is reported) until you run \`pull\`,
118
+ a folder it did not write is left alone, and it never deletes files you added.`,
86
119
  memory: `talentos memory search "<query>" [--personal|--company]
87
120
  talentos memory add "<fact>" [--company]`,
88
121
  ask: `talentos ask "<message>" [--thread <id>] [--no-wait]
@@ -93,16 +126,45 @@ talentos routines run <id>`,
93
126
  };
94
127
  async function main(argv) {
95
128
  const parsed = parseArgv(argv);
129
+ const output = machineOutput();
130
+ if (output) {
131
+ output.apiUrl = parsed.options["api-url"];
132
+ }
96
133
  if (parsed.options.version) {
97
- emit(version());
134
+ if (machineOutput()) {
135
+ emitJson({ version: version() });
136
+ }
137
+ else {
138
+ emit(version());
139
+ }
98
140
  return;
99
141
  }
100
142
  if (parsed.group === undefined || parsed.options.help) {
101
- emit(helpFor(parsed.group));
143
+ showHelp(parsed.group);
102
144
  return;
103
145
  }
146
+ if (machineOutput() &&
147
+ ((parsed.group === "mcp" && !parsed.action) ||
148
+ (parsed.group === "agent" &&
149
+ ["serve", "mcp"].includes(parsed.action ?? "")))) {
150
+ throw new CliError("INVALID_ARGUMENT", "--json is for command results. Start the MCP protocol or agent service without --json.");
151
+ }
152
+ if (machineOutput() &&
153
+ parsed.group === "agent" &&
154
+ parsed.action === "link" &&
155
+ !parsed.options.yes) {
156
+ throw new CliError("INVALID_ARGUMENT", "Use --yes only after the member approves installing the user service.");
157
+ }
104
158
  await dispatch(parsed);
105
159
  }
160
+ function showHelp(group) {
161
+ if (machineOutput()) {
162
+ emitJson({ help: helpFor(group) });
163
+ }
164
+ else {
165
+ emit(helpFor(group));
166
+ }
167
+ }
106
168
  function helpFor(group) {
107
169
  if (group === undefined) {
108
170
  return USAGE;
@@ -115,6 +177,8 @@ async function dispatch(parsed) {
115
177
  return await (await import("./commands/agent.js")).runAgent(parsed);
116
178
  case "init":
117
179
  return await (await import("./commands/init.js")).runInit(parsed);
180
+ case "doctor":
181
+ return await (await import("./commands/doctor.js")).runDoctor(parsed);
118
182
  case "login":
119
183
  return await (await import("./commands/login.js")).runLogin(parsed);
120
184
  case "logout":
@@ -131,8 +195,13 @@ async function dispatch(parsed) {
131
195
  return await (await import("./commands/ask.js")).runAsk(parsed);
132
196
  case "routines":
133
197
  return await (await import("./commands/routines.js")).runRoutines(parsed);
198
+ case "tools":
199
+ case "call":
200
+ return await (await import("./commands/tools.js")).runTools(parsed);
201
+ case "task":
202
+ return await (await import("./commands/task.js")).runTask(parsed);
134
203
  case "help": {
135
- emit(helpFor(parsed.args[0]));
204
+ showHelp(parsed.args[0]);
136
205
  return;
137
206
  }
138
207
  default:
@@ -143,16 +212,30 @@ function version() {
143
212
  const manifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
144
213
  return manifest.version;
145
214
  }
146
- main(process.argv.slice(2)).catch((error) => {
215
+ const argv = process.argv.slice(2);
216
+ const fragments = argv.flatMap((arg) => {
217
+ try {
218
+ return new URLSearchParams(new URL(arg).hash.slice(1)).getAll("token");
219
+ }
220
+ catch {
221
+ return [];
222
+ }
223
+ });
224
+ const keyOption = argv.indexOf("--key");
225
+ const secrets = [
226
+ ...fragments,
227
+ process.env.TALENTOS_API_KEY ?? "",
228
+ ...(keyOption < 0 ? [] : [argv[keyOption + 1] ?? ""]),
229
+ ].filter(Boolean);
230
+ const optionArgs = argv.includes("--")
231
+ ? argv.slice(0, argv.indexOf("--"))
232
+ : argv;
233
+ const execution = cliContractEnabled() &&
234
+ optionArgs.some((arg) => arg === "--json" || arg.startsWith("--json="))
235
+ ? runJsonCommand(() => main(argv), secrets)
236
+ : main(argv);
237
+ execution.catch((error) => {
147
238
  const message = error instanceof Error ? error.message : String(error);
148
- const fragments = process.argv.flatMap((arg) => {
149
- try {
150
- return new URLSearchParams(new URL(arg).hash.slice(1)).getAll("token");
151
- }
152
- catch {
153
- return [];
154
- }
155
- });
156
- process.stderr.write(`${redactAgentOutput(message, fragments).split("\n")[0]}\n`);
157
- process.exit(error instanceof ProviderBinaryError ? error.exitCode : 1);
239
+ process.stderr.write(`${redactAgentOutput(message, secrets).split("\n")[0]}\n`);
240
+ process.exitCode = error instanceof ProviderBinaryError ? error.exitCode : 1;
158
241
  });