@agentsky/sky 3.48.1 → 3.49.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 (39) hide show
  1. package/dist/chunk-2H4W5ZKZ.js +34 -0
  2. package/dist/{chunk-W24YSGH4.js → chunk-2YUZZ5VG.js} +7 -856
  3. package/dist/{chunk-E7HNEQ7F.js → chunk-6LRSRXQI.js} +1 -1
  4. package/dist/{chunk-TIP2XS2L.js → chunk-7JFTEJ7B.js} +1 -1
  5. package/dist/chunk-BKNZQZZD.js +857 -0
  6. package/dist/chunk-CK7N635F.js +317 -0
  7. package/dist/{chunk-KHJRD4DR.js → chunk-HFWHVU72.js} +4 -3
  8. package/dist/{chunk-RVDXKUWH.js → chunk-HGL7TLNA.js} +20 -353
  9. package/dist/{chunk-X4DBI7R7.js → chunk-HNUY5PBQ.js} +62 -8
  10. package/dist/{chunk-OJ5ERABF.js → chunk-IO2N34S2.js} +1 -1
  11. package/dist/{chunk-LVHQILKX.js → chunk-JMGVHVOS.js} +27 -23
  12. package/dist/{chunk-H7KHMRUZ.js → chunk-QTE5OMZY.js} +7 -5
  13. package/dist/{chunk-NDVCYVW5.js → chunk-RVI7ZWR2.js} +5 -5
  14. package/dist/chunk-TGU7T4O7.js +1363 -0
  15. package/dist/{chunk-46I7RCQQ.js → chunk-UYBKORXA.js} +43 -24
  16. package/dist/chunk-YO2XUCCF.js +30 -0
  17. package/dist/{chunk-GDZSCISF.js → chunk-ZOXE2XNH.js} +4 -2
  18. package/dist/{compute-TCUMLDEK.js → compute-4MMGFJGE.js} +2 -2
  19. package/dist/compute-report-LIMMRQY3.js +43 -0
  20. package/dist/grok-bot-export-7LSTXWJW.js +57 -0
  21. package/dist/index.js +634 -1791
  22. package/dist/local-agents-O7PYSQGR.js +11 -0
  23. package/dist/{local-skills-EIUQL24E.js → local-skills-5LJST7EP.js} +9 -3
  24. package/dist/{local-skills-run-FSVTDDOW.js → local-skills-run-6SZJQSVF.js} +16 -10
  25. package/dist/mcp-register-XY4MR3ZZ.js +40 -0
  26. package/dist/mcp-serve-QROKKUJV.js +18 -0
  27. package/dist/{trace-GFC46TQC.js → trace-SJZ25T35.js} +4 -3
  28. package/dist/{trace-exclusions-JEGMUPWQ.js → trace-exclusions-IC6OA2ND.js} +3 -2
  29. package/dist/trace-handoff-CD5LOS7B.js +116 -0
  30. package/dist/{trace-library-4F57EGL7.js → trace-library-V23TEXG4.js} +14 -8
  31. package/dist/trace-privacy-DU3TL5EO.js +11 -0
  32. package/package.json +1 -1
  33. package/vendor/trace-collect/SOURCE.json +2 -1
  34. package/vendor/trace-collect/sources/_pii.mjs +56 -0
  35. package/vendor/trace-collect/sources/grok-bot.mjs +180 -0
  36. package/vendor/trace-collect/sources/index.mjs +4 -2
  37. package/vendor/trace-collect/sources/muse-agent.mjs +95 -0
  38. package/dist/compute-report-LC2OH2QJ.js +0 -39
  39. package/dist/mcp-serve-NQJZL7YP.js +0 -16
@@ -0,0 +1,317 @@
1
+ import {
2
+ detectLocalAgents
3
+ } from "./chunk-2H4W5ZKZ.js";
4
+ import {
5
+ SKILL_NAME
6
+ } from "./chunk-7JFTEJ7B.js";
7
+
8
+ // src/mcp-register.ts
9
+ import { existsSync, readFileSync, writeFileSync } from "fs";
10
+ import { spawnSync } from "child_process";
11
+ import { homedir } from "os";
12
+ import { join } from "path";
13
+ import { parse as parseToml } from "smol-toml";
14
+ import { isMap, parseDocument } from "yaml";
15
+
16
+ // ../../packages/spec/src/mcp-tool-list.ts
17
+ var MCP_TOOL_LIST_PARAM = "tools";
18
+ function mcpUrlWithToolList(mcpUrl, list) {
19
+ const url = new URL(mcpUrl);
20
+ if (list === "short") url.searchParams.set(MCP_TOOL_LIST_PARAM, "short");
21
+ else url.searchParams.delete(MCP_TOOL_LIST_PARAM);
22
+ return url.toString();
23
+ }
24
+ function mcpToolListOf(mcpUrl) {
25
+ const value = (typeof mcpUrl === "string" ? new URL(mcpUrl) : mcpUrl).searchParams.get(MCP_TOOL_LIST_PARAM);
26
+ if (value === null) return "every";
27
+ return value === "short" || value === "every" ? value : null;
28
+ }
29
+
30
+ // src/mcp-register.ts
31
+ var MCP_SERVER_NAME = SKILL_NAME;
32
+ function detectHermes(env = process.env, home = homedir()) {
33
+ const root = env.HERMES_HOME || join(home, ".hermes");
34
+ return existsSync(root) ? { id: "hermes", name: "Hermes", root } : null;
35
+ }
36
+ function claudeAppRoot(env = process.env, home = homedir(), platform = process.platform) {
37
+ if (platform === "darwin") return join(home, "Library", "Application Support", "Claude");
38
+ if (platform === "win32") return join(env.APPDATA || join(home, "AppData", "Roaming"), "Claude");
39
+ return join(env.XDG_CONFIG_HOME || join(home, ".config"), "Claude");
40
+ }
41
+ function detectClaudeApp(env = process.env, home = homedir(), platform = process.platform) {
42
+ const root = claudeAppRoot(env, home, platform);
43
+ return existsSync(root) ? { id: "claude_app", name: "Claude app", root } : null;
44
+ }
45
+ function detectMcpClients(env = process.env, home = homedir(), platform = process.platform) {
46
+ const hermes = detectHermes(env, home);
47
+ const claudeApp = detectClaudeApp(env, home, platform);
48
+ return [...detectLocalAgents(env, home), ...hermes ? [hermes] : [], ...claudeApp ? [claudeApp] : []];
49
+ }
50
+ function systemCommandRunner() {
51
+ return {
52
+ has: (command) => spawnSync(command, ["--version"], { stdio: "ignore" }).status === 0,
53
+ run: (command, args) => {
54
+ const result = spawnSync(command, args, { encoding: "utf8" });
55
+ return { status: result.status, stderr: result.stderr ?? "", stdout: result.stdout ?? "" };
56
+ }
57
+ };
58
+ }
59
+ function mcpUrlFor(apiBase, list = "every") {
60
+ return mcpUrlWithToolList(`${apiBase.replace(/\/$/, "")}/mcp`, list);
61
+ }
62
+ function mcpCommands(agent, opts) {
63
+ if (agent === "grok") {
64
+ return {
65
+ command: "grok",
66
+ remove: ["mcp", "remove", MCP_SERVER_NAME],
67
+ add: ["mcp", "add", "--scope", "user", "--transport", "http", "--header", `Authorization: Bearer ${opts.token}`, MCP_SERVER_NAME, opts.mcpUrl]
68
+ };
69
+ }
70
+ return null;
71
+ }
72
+ var NO_TOOLS = "this sign-in gets no AgentSky tools (a workspace's own key has none); sign in as yourself with `sky auth login` and run setup again";
73
+ function redact(text, token) {
74
+ return text.split(token).join(`${token.slice(0, 10)}\u2026`);
75
+ }
76
+ function registerMcpServer(client, opts, runner = systemCommandRunner(), env = process.env, home = homedir()) {
77
+ if (client.id === "claude_code") return registerClaudeCode(client, opts, mcpConfigPath(client, env, home));
78
+ if (client.id === "codex") return registerCodex(client, opts);
79
+ if (client.id === "cursor") return registerCursor(client, opts);
80
+ if (client.id === "hermes") return registerHermes(client, opts);
81
+ if (client.id === "claude_app") return registerClaudeApp(client, opts);
82
+ const commands = mcpCommands(client.id, opts);
83
+ if (!commands) return { agent: client.id, outcome: "unsupported" };
84
+ if (!runner.has(commands.command)) return { agent: client.id, outcome: "no_command", detail: `${commands.command} is not on PATH` };
85
+ if (opts.dryRun) return { agent: client.id, outcome: "planned", detail: redact(`run ${[commands.command, ...commands.add].join(" ")}`, opts.token) };
86
+ runner.run(commands.command, commands.remove);
87
+ const added = runner.run(commands.command, commands.add);
88
+ if (added.status !== 0) return { agent: client.id, outcome: "failed", detail: redact(added.stderr.trim() || `exit ${added.status}`, opts.token) };
89
+ return { agent: client.id, outcome: "registered" };
90
+ }
91
+ function mcpConfigPath(client, env = process.env, home = homedir()) {
92
+ switch (client.id) {
93
+ case "claude_code":
94
+ return join(env.CLAUDE_CONFIG_DIR || home, ".claude.json");
95
+ case "codex":
96
+ case "grok":
97
+ return join(client.root, "config.toml");
98
+ case "cursor":
99
+ return join(client.root, "mcp.json");
100
+ case "hermes":
101
+ return join(client.root, "config.yaml");
102
+ case "claude_app":
103
+ return join(client.root, "claude_desktop_config.json");
104
+ }
105
+ }
106
+ function readText(path) {
107
+ try {
108
+ return readFileSync(path, "utf8");
109
+ } catch {
110
+ return null;
111
+ }
112
+ }
113
+ function registeredMcpUrl(client, env = process.env, home = homedir()) {
114
+ const raw = readText(mcpConfigPath(client, env, home));
115
+ if (raw === null) return null;
116
+ try {
117
+ let entry;
118
+ if (client.id === "codex" || client.id === "grok") entry = parseToml(raw).mcp_servers?.[MCP_SERVER_NAME];
119
+ else if (client.id === "hermes") entry = parseDocument(raw).toJS()?.mcp_servers?.[MCP_SERVER_NAME];
120
+ else entry = JSON.parse(raw).mcpServers?.[MCP_SERVER_NAME];
121
+ const url = entry?.url;
122
+ return typeof url === "string" ? url : null;
123
+ } catch {
124
+ return null;
125
+ }
126
+ }
127
+ function registeredToolList(client, env = process.env, home = homedir()) {
128
+ const url = registeredMcpUrl(client, env, home);
129
+ if (url === null) return "every";
130
+ try {
131
+ return mcpToolListOf(url) === "short" ? "short" : "every";
132
+ } catch {
133
+ return "every";
134
+ }
135
+ }
136
+ function hasMcpServer(client, env = process.env, home = homedir()) {
137
+ const raw = readText(mcpConfigPath(client, env, home));
138
+ if (raw === null) return false;
139
+ try {
140
+ if (client.id === "codex" || client.id === "grok") return Boolean(parseToml(raw).mcp_servers?.[MCP_SERVER_NAME]);
141
+ if (client.id === "hermes") return parseDocument(raw).hasIn(["mcp_servers", MCP_SERVER_NAME]);
142
+ return Boolean(JSON.parse(raw).mcpServers?.[MCP_SERVER_NAME]);
143
+ } catch {
144
+ return false;
145
+ }
146
+ }
147
+ function planned(client, path, entry, opts) {
148
+ return { agent: client.id, outcome: "planned", detail: `write to ${path}: ${redact(entry, opts.token)}` };
149
+ }
150
+ function written(client, path, text) {
151
+ try {
152
+ writeFileSync(path, text, { encoding: "utf8", mode: 384 });
153
+ } catch (err) {
154
+ return { agent: client.id, outcome: "failed", detail: String(err) };
155
+ }
156
+ return { agent: client.id, outcome: "registered" };
157
+ }
158
+ function tomlTableKey(name) {
159
+ const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
160
+ return `(?:${escaped}|"${escaped}"|'${escaped}')`;
161
+ }
162
+ function withoutTomlServer(text, name) {
163
+ return withTomlServer(text, name, null);
164
+ }
165
+ function withTomlServer(text, name, block) {
166
+ const ours = new RegExp(`^\\s*\\[\\s*mcp_servers\\s*\\.\\s*${tomlTableKey(name)}\\s*(?:\\.[^\\]]*)?\\]\\s*(?:#.*)?$`);
167
+ let skipping = false;
168
+ let placed = false;
169
+ const kept = [];
170
+ for (const line of text.split(/\r?\n/)) {
171
+ if (/^\s*\[/.test(line)) {
172
+ const was = skipping;
173
+ skipping = ours.test(line);
174
+ if (was && !skipping && block !== null) kept.push("");
175
+ }
176
+ if (skipping && !placed && block !== null) {
177
+ kept.push(block);
178
+ placed = true;
179
+ }
180
+ if (!skipping) kept.push(line);
181
+ }
182
+ const rest = kept.join("\n").replace(/\n+$/, "");
183
+ if (block === null || placed) return rest;
184
+ return rest ? `${rest}
185
+
186
+ ${block}` : block;
187
+ }
188
+ function registerCodex(client, opts) {
189
+ const path = mcpConfigPath(client);
190
+ const block = [
191
+ `[mcp_servers.${MCP_SERVER_NAME}]`,
192
+ `url = ${JSON.stringify(opts.mcpUrl)}`,
193
+ `http_headers = { Authorization = ${JSON.stringify(`Bearer ${opts.token}`)} }`
194
+ ].join("\n");
195
+ if (opts.dryRun) return planned(client, path, block, opts);
196
+ const raw = readText(path) ?? "";
197
+ let before;
198
+ try {
199
+ before = parseToml(raw);
200
+ } catch (err) {
201
+ return { agent: client.id, outcome: "failed", detail: `${path} is not valid TOML, left as it was (${String(err).split("\n")[0]})` };
202
+ }
203
+ const text = `${withTomlServer(raw, MCP_SERVER_NAME, block)}
204
+ `;
205
+ if (text === raw) return { agent: client.id, outcome: "registered", detail: "already registered" };
206
+ try {
207
+ const after = parseToml(text);
208
+ const others = Object.keys(before.mcp_servers ?? {}).filter((name) => name !== MCP_SERVER_NAME);
209
+ if (after.mcp_servers?.[MCP_SERVER_NAME]?.url !== opts.mcpUrl || others.some((name) => !after.mcp_servers?.[name])) throw new Error("the edited file lost an entry");
210
+ } catch (err) {
211
+ return { agent: client.id, outcome: "failed", detail: `could not edit ${path} safely, left as it was (${String(err).split("\n")[0]})` };
212
+ }
213
+ return written(client, path, text);
214
+ }
215
+ function registerClaudeCode(client, opts, path) {
216
+ const entry = { type: "http", url: opts.mcpUrl, headers: { Authorization: `Bearer ${opts.token}` } };
217
+ if (opts.dryRun) return planned(client, path, JSON.stringify({ [MCP_SERVER_NAME]: entry }, null, 2), opts);
218
+ const raw = readText(path);
219
+ let existing = {};
220
+ if (raw !== null && raw.trim()) {
221
+ try {
222
+ const parsed = JSON.parse(raw);
223
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("not an object");
224
+ existing = parsed;
225
+ } catch (err) {
226
+ return { agent: client.id, outcome: "failed", detail: `${path} is not valid JSON, left as it was (${String(err).split("\n")[0]})` };
227
+ }
228
+ }
229
+ if (JSON.stringify(existing.mcpServers?.[MCP_SERVER_NAME]) === JSON.stringify(entry)) return { agent: client.id, outcome: "registered", detail: "already registered" };
230
+ const indent = raw ? /^[{[]\r?\n([ \t]+)/.exec(raw)?.[1] ?? 2 : 2;
231
+ const ending = raw === null || raw.endsWith("\n") ? "\n" : "";
232
+ const updated = { ...existing, mcpServers: { ...existing.mcpServers ?? {}, [MCP_SERVER_NAME]: entry } };
233
+ return written(client, path, `${JSON.stringify(updated, null, indent)}${ending}`);
234
+ }
235
+ function registerCursor(client, opts) {
236
+ const path = mcpConfigPath(client);
237
+ const entry = { url: opts.mcpUrl, headers: { Authorization: `Bearer ${opts.token}` } };
238
+ if (opts.dryRun) return planned(client, path, JSON.stringify({ [MCP_SERVER_NAME]: entry }, null, 2), opts);
239
+ let existing = {};
240
+ try {
241
+ const parsed = JSON.parse(readText(path) ?? "");
242
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) existing = parsed;
243
+ } catch {
244
+ existing = {};
245
+ }
246
+ const updated = { ...existing, mcpServers: { ...existing.mcpServers ?? {}, [MCP_SERVER_NAME]: entry } };
247
+ return written(client, path, `${JSON.stringify(updated, null, 2)}
248
+ `);
249
+ }
250
+ function registerClaudeApp(client, opts) {
251
+ if (!opts.sky?.length) return { agent: client.id, outcome: "unsupported", detail: "no sky command to start" };
252
+ const path = mcpConfigPath(client);
253
+ const [command, ...args] = opts.sky;
254
+ const entry = { command, args: [...args, "mcp", "serve"] };
255
+ if (opts.dryRun) return planned(client, path, JSON.stringify({ [MCP_SERVER_NAME]: entry }, null, 2), opts);
256
+ let existing = {};
257
+ const raw = readText(path);
258
+ if (raw !== null && raw.trim()) {
259
+ try {
260
+ const parsed = JSON.parse(raw);
261
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("not an object");
262
+ existing = parsed;
263
+ } catch (err) {
264
+ return { agent: client.id, outcome: "failed", detail: `${path} is not valid JSON, left as it was (${String(err).split("\n")[0]})` };
265
+ }
266
+ }
267
+ const current = existing.mcpServers?.[MCP_SERVER_NAME];
268
+ if (JSON.stringify(current) === JSON.stringify(entry)) return { agent: client.id, outcome: "registered", detail: "already registered" };
269
+ const updated = { ...existing, mcpServers: { ...existing.mcpServers ?? {}, [MCP_SERVER_NAME]: entry } };
270
+ return written(client, path, `${JSON.stringify(updated, null, 2)}
271
+ `);
272
+ }
273
+ function registerHermes(client, opts) {
274
+ const path = mcpConfigPath(client);
275
+ const entry = { url: opts.mcpUrl, headers: { Authorization: `Bearer ${opts.token}` } };
276
+ if (opts.dryRun) return planned(client, path, `mcp_servers.${MCP_SERVER_NAME}: ${JSON.stringify(entry)}`, opts);
277
+ const doc = parseDocument(readText(path) ?? "");
278
+ if (doc.errors.length) return { agent: client.id, outcome: "failed", detail: `${path} is not valid YAML, left as it was (${doc.errors[0].message.split("\n")[0]})` };
279
+ if (doc.contents !== null && !isMap(doc.contents)) {
280
+ return { agent: client.id, outcome: "failed", detail: `${path} is not a YAML mapping, left as it was` };
281
+ }
282
+ doc.setIn(["mcp_servers", MCP_SERVER_NAME], doc.createNode(entry));
283
+ return written(client, path, doc.toString());
284
+ }
285
+ async function refreshMcpRegistrations(opts, clients = detectMcpClients(), runner = systemCommandRunner(), env = process.env, home = homedir()) {
286
+ const registrations = [];
287
+ for (const client of clients.filter((candidate) => candidate.id !== "claude_app" && hasMcpServer(candidate, env, home))) {
288
+ let token;
289
+ try {
290
+ token = await opts.token(client);
291
+ } catch (error) {
292
+ registrations.push({ agent: client.id, outcome: "failed", detail: `no key of its own could be made (${(error instanceof Error ? error.message : String(error)).split("\n")[0]})` });
293
+ continue;
294
+ }
295
+ registrations.push(registerMcpServer(client, { token, mcpUrl: mcpUrlFor(opts.apiBase, registeredToolList(client, env, home)) }, runner, env, home));
296
+ }
297
+ return registrations;
298
+ }
299
+
300
+ export {
301
+ MCP_SERVER_NAME,
302
+ detectHermes,
303
+ claudeAppRoot,
304
+ detectClaudeApp,
305
+ detectMcpClients,
306
+ systemCommandRunner,
307
+ mcpUrlFor,
308
+ mcpCommands,
309
+ NO_TOOLS,
310
+ registerMcpServer,
311
+ mcpConfigPath,
312
+ registeredMcpUrl,
313
+ registeredToolList,
314
+ hasMcpServer,
315
+ withoutTomlServer,
316
+ refreshMcpRegistrations
317
+ };
@@ -1,11 +1,11 @@
1
- import {
2
- USER_AGENT
3
- } from "./chunk-E7HNEQ7F.js";
4
1
  import {
5
2
  apiBase,
6
3
  apiToken,
7
4
  currentUniverse
8
5
  } from "./chunk-XHZJG3QT.js";
6
+ import {
7
+ USER_AGENT
8
+ } from "./chunk-6LRSRXQI.js";
9
9
 
10
10
  // src/api.ts
11
11
  import { createWriteStream, writeFileSync } from "fs";
@@ -55,6 +55,7 @@ async function api(method, path, body, opts = {}) {
55
55
  ...opts.signal ? { signal: opts.signal } : {},
56
56
  headers: {
57
57
  "user-agent": USER_AGENT,
58
+ ...opts.headers ?? {},
58
59
  ...opts.auth === false ? {} : authHeaders(),
59
60
  ...body !== void 0 ? { "content-type": "application/json" } : {},
60
61
  ...opts.idempotencyKey ? { "idempotency-key": opts.idempotencyKey } : {},