talentos 1.4.21 → 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.
Files changed (43) hide show
  1. package/README.md +82 -7
  2. package/dist/agent/adapters.js +12 -2
  3. package/dist/agent/codex-policy.js +13 -0
  4. package/dist/agent/codex-probe.js +3 -1
  5. package/dist/agent/native/codex-fence.js +1 -1
  6. package/dist/agent/native/codex-launch.js +1 -3
  7. package/dist/agent/native/gate.js +11 -3
  8. package/dist/agent/native/hook-entry.js +8 -1
  9. package/dist/agent/native/touch.js +15 -6
  10. package/dist/agent/serve.js +4 -2
  11. package/dist/agent/talentos-content.js +33 -0
  12. package/dist/args.js +10 -1
  13. package/dist/claude-plugin.js +82 -0
  14. package/dist/client.js +17 -4
  15. package/dist/commands/doctor.js +371 -0
  16. package/dist/commands/init.js +59 -8
  17. package/dist/commands/login.js +10 -1
  18. package/dist/commands/mcp.js +16 -1
  19. package/dist/commands/skills-sync.js +174 -0
  20. package/dist/commands/skills.js +24 -4
  21. package/dist/commands/task.js +77 -0
  22. package/dist/commands/tools.js +56 -0
  23. package/dist/config.js +34 -0
  24. package/dist/download-file.js +75 -0
  25. package/dist/format.js +12 -0
  26. package/dist/index.js +102 -19
  27. package/dist/install.js +55 -36
  28. package/dist/mcp-proxy.js +18 -0
  29. package/dist/memory-wire.js +22 -0
  30. package/dist/output.js +107 -0
  31. package/dist/setup.generated.js +120 -0
  32. package/dist/skill-files.js +1 -1
  33. package/dist/skill-sync-state.js +38 -0
  34. package/dist/watch.js +39 -0
  35. package/package.json +3 -2
  36. package/plugin/.claude-plugin/marketplace.json +12 -0
  37. package/plugin/plugins/talentos/.claude-plugin/plugin.json +9 -0
  38. package/plugin/plugins/talentos/.mcp.json +8 -0
  39. package/plugin/plugins/talentos/commands/ask-talent.md +20 -0
  40. package/plugin/plugins/talentos/commands/catch-up.md +16 -0
  41. package/plugin/plugins/talentos/commands/remember.md +15 -0
  42. package/plugin/plugins/talentos/hooks/hooks.json +17 -0
  43. package/plugin/plugins/talentos/scripts/session-start.mjs +177 -0
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
  });
package/dist/install.js CHANGED
@@ -3,12 +3,13 @@ import { existsSync } from "node:fs";
3
3
  import { chmod, mkdir, readFile, writeFile } from "node:fs/promises";
4
4
  import { homedir } from "node:os";
5
5
  import { dirname, join } from "node:path";
6
+ import { mcpUrlFor } from "./config.js";
7
+ import { OAUTH_NEXT, setupEntry, setupSnippet } from "./setup.generated.js";
6
8
  export const AGENT_TARGETS = ["claude", "cursor", "codex"];
7
9
  export const MCP_INSTALL_TARGETS = [...AGENT_TARGETS, "json"];
8
10
  /** Cursor and Codex both auto-load `.agents/skills`; Claude Code reads its own. */
9
11
  const AGENTS_SKILLS_DIR = ".agents/skills";
10
12
  const CLAUDE_SKILLS_DIR = ".claude/skills";
11
- const CODEX_HEADER = "[mcp_servers.talentos]";
12
13
  const TOML_HEADER_START = "[";
13
14
  const TRAILING_NEWLINES = /\n*$/;
14
15
  export const CONFIG_MODE = 0o600;
@@ -21,7 +22,7 @@ const AGENT_SPECS = {
21
22
  label: "Claude Code",
22
23
  hint: "Run this once:",
23
24
  detect: (probe) => probe.which("claude") || probe.exists(join(probe.home, ".claude")),
24
- render: (credentials) => `claude mcp add --scope user --transport http talentos ${mcpUrl(credentials)} --header "Authorization: ${bearer(credentials)}"`,
25
+ render: (credentials, mode) => clientSnippet("claude", credentials, mode),
25
26
  skillDirs: [CLAUDE_SKILLS_DIR],
26
27
  },
27
28
  cursor: {
@@ -30,7 +31,9 @@ const AGENT_SPECS = {
30
31
  detect: (probe) => probe.exists(join(probe.home, ".cursor")) ||
31
32
  probe.exists(join(probe.cwd, ".cursor")),
32
33
  configPath: (home) => join(home, ".cursor", "mcp.json"),
33
- render: (credentials) => JSON.stringify(cursorEntry(credentials), null, 2),
34
+ // Cursor stays on the key in every mode: the server has no OAuth join rule
35
+ // for it yet (#15810).
36
+ render: (credentials) => clientSnippet("cursor", credentials, "key"),
34
37
  merge: (existing, credentials) => mergeCursorConfig(existing, credentials),
35
38
  skillDirs: [AGENTS_SKILLS_DIR],
36
39
  },
@@ -39,15 +42,12 @@ const AGENT_SPECS = {
39
42
  hint: "Add to ~/.codex/config.toml:",
40
43
  detect: (probe) => probe.exists(join(probe.home, ".codex")),
41
44
  configPath: (home) => join(home, ".codex", "config.toml"),
42
- // Codex speaks stdio only, so it launches this CLI as a proxy. The url
43
- // travels with the key: a staging key must not reach production.
44
- render: (credentials) => [
45
- CODEX_HEADER,
46
- 'command = "npx"',
47
- 'args = ["-y", "talentos@1", "mcp"]',
48
- `env = { TALENTOS_API_KEY = "${credentials.apiKey}", TALENTOS_API_URL = "${credentials.apiUrl}" }`,
49
- ].join("\n"),
50
- merge: (existing, credentials) => upsertCodexBlock(existing, credentials),
45
+ // `key`: Codex launches this CLI as a stdio proxy; the url travels with the
46
+ // key, because a staging key must not reach production. `oauth`: Codex
47
+ // speaks to the remote server itself and `codex mcp login talentos` signs
48
+ // the member in.
49
+ render: (credentials, mode) => clientSnippet("codex", credentials, mode),
50
+ merge: (existing, credentials, mode) => upsertCodexBlock(existing, credentials, mode),
51
51
  skillDirs: [AGENTS_SKILLS_DIR],
52
52
  },
53
53
  };
@@ -73,11 +73,20 @@ export function agentTargetsFor(value) {
73
73
  export function installHint(target) {
74
74
  return isAgentTarget(target) ? AGENT_SPECS[target].hint : GENERIC_HINT;
75
75
  }
76
- export function buildInstallSnippet(target, credentials) {
76
+ export function buildInstallSnippet(target, credentials, mode = "key") {
77
77
  return isAgentTarget(target)
78
- ? AGENT_SPECS[target].render(credentials)
78
+ ? AGENT_SPECS[target].render(credentials, mode)
79
79
  : JSON.stringify(cursorEntry(credentials), null, 2);
80
80
  }
81
+ /**
82
+ * The OAuth-first setup is dark: `--oauth` or `HEADLESS_SETUP_V1=true` turns it
83
+ * on. Until the server accepts these clients' loopback sign-in (see the
84
+ * agent-access doc), the default stays the key every client uses today.
85
+ */
86
+ export function setupModeFrom(options, env = process.env) {
87
+ const flag = env.HEADLESS_SETUP_V1?.trim().toLowerCase();
88
+ return options.oauth || flag === "true" || flag === "1" ? "oauth" : "key";
89
+ }
81
90
  /** Where Codex keeps its user-level MCP servers. */
82
91
  export function codexConfigPath(home) {
83
92
  return (AGENT_SPECS.codex.configPath?.(home) ?? join(home, ".codex", "config.toml"));
@@ -120,8 +129,8 @@ export function mergeCursorConfig(existing, credentials) {
120
129
  };
121
130
  return `${JSON.stringify(next, null, 2)}\n`;
122
131
  }
123
- export function upsertCodexBlock(existing, credentials) {
124
- return upsertCodexSection(existing, "talentos", AGENT_SPECS.codex.render(credentials));
132
+ export function upsertCodexBlock(existing, credentials, mode = "key") {
133
+ return upsertCodexSection(existing, "talentos", AGENT_SPECS.codex.render(credentials, mode));
125
134
  }
126
135
  /** Replaces or appends the `[mcp_servers.<server>]` block, leaving the rest. */
127
136
  export function upsertCodexSection(existing, server, block) {
@@ -146,6 +155,14 @@ export function removeCodexSection(existing, server) {
146
155
  const rest = [...lines.slice(0, bounds.start), ...lines.slice(bounds.end)];
147
156
  return `${rest.join("\n").replace(TRAILING_NEWLINES, "")}\n`;
148
157
  }
158
+ /** The lines of the `[mcp_servers.<server>]` block (header excluded), if any. */
159
+ export function readCodexSection(existing, server) {
160
+ const lines = existing.split("\n");
161
+ const bounds = codexSectionBounds(lines, server);
162
+ return bounds === undefined
163
+ ? undefined
164
+ : lines.slice(bounds.start + 1, bounds.end).join("\n");
165
+ }
149
166
  function codexSectionBounds(lines, server) {
150
167
  const header = `[mcp_servers.${server}]`;
151
168
  const start = lines.findIndex((line) => line.trim() === header);
@@ -161,17 +178,17 @@ function codexSectionBounds(lines, server) {
161
178
  * Writes the MCP config for one agent at USER level. Nothing lands inside the
162
179
  * repo: a checked-in config would leak the member's key to the whole team.
163
180
  */
164
- export async function applyInstall(target, credentials, home = defaultProbe().home) {
181
+ export async function applyInstall(target, credentials, home = defaultProbe().home, mode = "key") {
165
182
  const spec = AGENT_SPECS[target];
166
183
  const path = spec.configPath?.(home);
167
184
  if (path === undefined || spec.merge === undefined) {
168
- return applyClaudeInstall(credentials);
185
+ return applyClaudeInstall(credentials, mode);
169
186
  }
170
- const next = spec.merge(await readIfPresent(path), credentials);
187
+ const next = spec.merge(await readIfPresent(path), credentials, mode);
171
188
  await mkdir(dirname(path), { recursive: true, mode: 0o700 });
172
189
  await writeFile(path, next, { mode: CONFIG_MODE });
173
- // writeFile's mode only applies when it creates the file, and this one holds
174
- // the member's API key.
190
+ // writeFile's mode only applies when it creates the file, and in `key` mode
191
+ // this one holds the member's API key.
175
192
  await chmod(path, CONFIG_MODE);
176
193
  return { applied: true, detail: path };
177
194
  }
@@ -182,7 +199,7 @@ export async function applyInstall(target, credentials, home = defaultProbe().ho
182
199
  export function shellArgs(args, platform = process.platform) {
183
200
  return platform === "win32" ? args.map((arg) => `"${arg}"`) : args;
184
201
  }
185
- function applyClaudeInstall(credentials) {
202
+ function applyClaudeInstall(credentials, mode) {
186
203
  if (!onPath("claude")) {
187
204
  return { applied: false, detail: "the `claude` command is not on PATH" };
188
205
  }
@@ -203,8 +220,9 @@ function applyClaudeInstall(credentials) {
203
220
  "http",
204
221
  "talentos",
205
222
  mcpUrl(credentials),
206
- "--header",
207
- `Authorization: ${bearer(credentials)}`,
223
+ ...(mode === "oauth"
224
+ ? []
225
+ : ["--header", `Authorization: Bearer ${credentials.apiKey}`]),
208
226
  ]);
209
227
  if (added.status !== 0) {
210
228
  throw new Error(firstLine(added.stderr) || "`claude mcp add` failed");
@@ -242,14 +260,7 @@ function parseCursorConfig(existing) {
242
260
  }
243
261
  }
244
262
  function cursorEntry(credentials) {
245
- return {
246
- mcpServers: {
247
- talentos: {
248
- url: mcpUrl(credentials),
249
- headers: { Authorization: bearer(credentials) },
250
- },
251
- },
252
- };
263
+ return setupEntry(mcpUrl(credentials), credentials.apiKey);
253
264
  }
254
265
  export async function readIfPresent(path) {
255
266
  try {
@@ -267,12 +278,20 @@ export function onPath(command) {
267
278
  });
268
279
  return probe.error === undefined && probe.status === 0;
269
280
  }
270
- function mcpUrl(credentials) {
271
- return `${credentials.apiUrl}/mcp`;
281
+ /** The MCP address written into client configs for this API url. */
282
+ export function mcpUrl(credentials) {
283
+ return mcpUrlFor(credentials.apiUrl);
272
284
  }
273
- function bearer(credentials) {
274
- return `Bearer ${credentials.apiKey}`;
285
+ function clientSnippet(target, credentials, mode) {
286
+ return setupSnippet(target, mode, {
287
+ apiUrl: credentials.apiUrl,
288
+ key: credentials.apiKey,
289
+ url: mcpUrl(credentials),
290
+ });
275
291
  }
276
292
  function firstLine(text) {
277
293
  return text?.trim().split("\n")[0] ?? "";
278
294
  }
295
+ export function oauthNext(target) {
296
+ return OAUTH_NEXT[target];
297
+ }
package/dist/mcp-proxy.js CHANGED
@@ -3,6 +3,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
3
3
  import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
4
4
  import { handleRunCommand, RUN_COMMAND_TOOL, stopAllRunCommands, wireShutdown, } from "./agent/native/codex-run-command.js";
5
5
  import { ownerPictureRoot } from "./agent/native/owner-pictures.js";
6
+ import { downloadFile } from "./download-file.js";
6
7
  import { UploadRefusal, uploadFile } from "./upload-file.js";
7
8
  // The two server steps behind upload_file. The model sees only upload_file.
8
9
  const UPLOAD_STEP_TOOLS = new Set(["prepare_upload", "commit_upload"]);
@@ -132,6 +133,23 @@ scratch = false) {
132
133
  signal: shutdownSignal,
133
134
  });
134
135
  }
136
+ if ((name === "read_attachment" || name === "read_file") &&
137
+ args.download === true) {
138
+ try {
139
+ return await downloadFile(client, { name, arguments: args }, root, shutdownSignal);
140
+ }
141
+ catch {
142
+ return {
143
+ content: [
144
+ {
145
+ type: "text",
146
+ text: "The original file could not be opened in this workspace. Check that the room and file remain accessible, then retry. If this client has no file workspace, ask a Talent with a computer to inspect it. Do not guess its contents or duration.",
147
+ },
148
+ ],
149
+ isError: true,
150
+ };
151
+ }
152
+ }
135
153
  if (name === "upload_file") {
136
154
  // A picture this owner job's own image call made sits in Codex's folder
137
155
  // (owner-pictures.ts), read with the scratch rules, as a fenced job's is.
@@ -0,0 +1,22 @@
1
+ // Standalone npm package: keep this decoder aligned with the v1 wire spec in
2
+ // docs/features/agent-access/memory-wire-format.md, without Convex imports.
3
+ export function unescapeMemoryText(text) {
4
+ return text.replace(/\\(\\|u[\da-f]{4})/giu, (_, encoded) => encoded === "\\"
5
+ ? "\\"
6
+ : String.fromCharCode(Number.parseInt(encoded.slice(1), 16)));
7
+ }
8
+ export function decodeMemoryRead(text, data) {
9
+ const open = "<teammate_message>\n";
10
+ const close = "\n</teammate_message>";
11
+ if (data.bodyEncoding !== "talentos-memory-v1" ||
12
+ !text.startsWith(open) ||
13
+ !text.endsWith(close) ||
14
+ !Number.isSafeInteger(data.bodyStart) ||
15
+ !Number.isSafeInteger(data.bodyLength) ||
16
+ data.bodyStart < open.length ||
17
+ data.bodyLength < 0 ||
18
+ data.bodyStart + data.bodyLength !== text.length - close.length) {
19
+ throw new Error("Unsupported or incomplete Memory read. Refresh memory_read.");
20
+ }
21
+ return unescapeMemoryText(text.slice(data.bodyStart, data.bodyStart + data.bodyLength));
22
+ }
package/dist/output.js ADDED
@@ -0,0 +1,107 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { redactAgentOutput } from "./agent-link.js";
3
+ export class CliError extends Error {
4
+ code;
5
+ next;
6
+ details;
7
+ constructor(code, message, next, details) {
8
+ super(message);
9
+ this.code = code;
10
+ this.next = next;
11
+ this.details = details;
12
+ }
13
+ }
14
+ const output = new AsyncLocalStorage();
15
+ const AUTH_ERROR = /not logged in|key revoked|rejected that key|unauthorized|\b401\b/iu;
16
+ const ARGUMENT_ERROR = /usage:|unknown (command|option)|argument|--help/iu;
17
+ const TALENTOS_COMMAND = /^(?:talentos|npx(?: -y)? talentos(?:@\S+)?)(?:\s|$)/u;
18
+ const NETWORK_ERROR = /cannot reach|fetch failed|ECONNREFUSED|ENOTFOUND/iu;
19
+ export function cliContractEnabled() {
20
+ return process.env.HEADLESS_CLI_V1 === "true";
21
+ }
22
+ export function machineOutput() {
23
+ return output.getStore();
24
+ }
25
+ export function nextActions(next) {
26
+ const current = machineOutput();
27
+ if (current) {
28
+ current.next = next;
29
+ }
30
+ }
31
+ export function withApiUrl(command, apiUrl) {
32
+ if (!(apiUrl && TALENTOS_COMMAND.test(command)) ||
33
+ command.includes(" --api-url ")) {
34
+ return command;
35
+ }
36
+ return `${command} --api-url '${apiUrl.replaceAll("'", "'\\''")}'`;
37
+ }
38
+ function contextualNext(next, apiUrl) {
39
+ return next?.map((action) => ({
40
+ ...action,
41
+ command: withApiUrl(action.command, apiUrl),
42
+ }));
43
+ }
44
+ /** One envelope after the command settles; nested progress goes to stderr. */
45
+ export async function runJsonCommand(run, secrets) {
46
+ const result = {};
47
+ await output.run(result, async () => {
48
+ try {
49
+ await run();
50
+ if (process.exitCode) {
51
+ throw new CliError("COMMAND_FAILED", result.message ?? "The command needs attention.", result.next);
52
+ }
53
+ writeEnvelope({
54
+ ok: true,
55
+ data: result.data ?? (result.message ? { message: result.message } : null),
56
+ ...(result.next?.length
57
+ ? { next: contextualNext(result.next, result.apiUrl) }
58
+ : {}),
59
+ });
60
+ }
61
+ catch (error) {
62
+ const message = redactAgentOutput(error instanceof Error ? error.message : String(error), secrets);
63
+ const failure = error instanceof CliError ? error : classifyError(message);
64
+ writeEnvelope({
65
+ ok: false,
66
+ error: {
67
+ code: failure.code,
68
+ message,
69
+ ...(failure.details === undefined
70
+ ? {}
71
+ : { details: failure.details }),
72
+ },
73
+ ...(failure.next?.length
74
+ ? { next: contextualNext(failure.next, result.apiUrl) }
75
+ : {}),
76
+ });
77
+ process.exitCode ||= 1;
78
+ }
79
+ });
80
+ }
81
+ function classifyError(message) {
82
+ if (AUTH_ERROR.test(message)) {
83
+ return new CliError("UNAUTHENTICATED", message, [
84
+ {
85
+ command: "talentos login",
86
+ why: "Sign in with the member's current key.",
87
+ },
88
+ ]);
89
+ }
90
+ if (ARGUMENT_ERROR.test(message)) {
91
+ return new CliError("INVALID_ARGUMENT", message, [
92
+ { command: "talentos --help", why: "Check the command and its options." },
93
+ ]);
94
+ }
95
+ if (NETWORK_ERROR.test(message)) {
96
+ return new CliError("UNAVAILABLE", message, [
97
+ {
98
+ command: "talentos doctor",
99
+ why: "Check the connection before trying again.",
100
+ },
101
+ ]);
102
+ }
103
+ return new CliError("COMMAND_FAILED", message);
104
+ }
105
+ function writeEnvelope(value) {
106
+ process.stdout.write(`${JSON.stringify(value)}\n`);
107
+ }