@agentsky/sky 3.43.0 → 3.45.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.
@@ -1,289 +1,46 @@
1
+ import {
2
+ MCP_SERVER_NAME,
3
+ withoutSettingsBlock,
4
+ withoutTomlServer
5
+ } from "./chunk-OYSSK6GS.js";
1
6
  import {
2
7
  ApiError,
3
8
  api
4
- } from "./chunk-44XF4EGE.js";
5
- import {
6
- SKILL_NAME
7
- } from "./chunk-J3KIEZXM.js";
9
+ } from "./chunk-WLTOVOTW.js";
8
10
  import {
9
11
  configPath,
10
12
  currentUniverse
11
13
  } from "./chunk-XHZJG3QT.js";
12
14
 
13
- // src/local-agents.ts
14
- import { existsSync } from "fs";
15
- import { homedir } from "os";
16
- import { join } from "path";
17
- function localAgents(env = process.env, home = homedir()) {
18
- const claude = env.CLAUDE_CONFIG_DIR || join(home, ".claude");
19
- const codex = env.CODEX_HOME || join(home, ".codex");
20
- const cursor = join(home, ".cursor");
21
- const grok = env.GROK_HOME || join(home, ".grok");
22
- return [
23
- { id: "claude_code", name: "Claude Code", root: claude, skillsDir: join(claude, "skills") },
24
- { id: "codex", name: "Codex", root: codex, skillsDir: join(codex, "skills") },
25
- { id: "cursor", name: "Cursor", root: cursor, skillsDir: join(cursor, "skills") },
26
- { id: "grok", name: "Grok", root: grok, skillsDir: join(grok, "skills") }
27
- ];
28
- }
29
- function detectLocalAgents(env = process.env, home = homedir()) {
30
- return localAgents(env, home).filter((agent) => existsSync(agent.root));
31
- }
32
- function selectLocalAgents(ids, env = process.env, home = homedir()) {
33
- if (!ids?.length) return detectLocalAgents(env, home);
34
- const known = localAgents(env, home);
35
- return ids.map((id) => {
36
- const agent = known.find((candidate) => candidate.id === id);
37
- if (!agent) throw new Error(`unknown agent ${id} \u2014 expected ${known.map((candidate) => candidate.id).join(" | ")}`);
38
- return agent;
39
- });
40
- }
41
-
42
- // src/mcp-register.ts
43
- import { existsSync as existsSync2, readFileSync, writeFileSync } from "fs";
44
- import { spawnSync } from "child_process";
45
- import { homedir as homedir2 } from "os";
46
- import { join as join2 } from "path";
47
- import { parse as parseToml } from "smol-toml";
48
- import { isMap, parseDocument } from "yaml";
49
-
50
- // ../../packages/spec/src/mcp-tool-list.ts
51
- var MCP_TOOL_LIST_PARAM = "tools";
52
- function mcpUrlWithToolList(mcpUrl, list) {
53
- const url = new URL(mcpUrl);
54
- if (list === "short") url.searchParams.set(MCP_TOOL_LIST_PARAM, "short");
55
- else url.searchParams.delete(MCP_TOOL_LIST_PARAM);
56
- return url.toString();
57
- }
58
- function mcpToolListOf(mcpUrl) {
59
- const value = (typeof mcpUrl === "string" ? new URL(mcpUrl) : mcpUrl).searchParams.get(MCP_TOOL_LIST_PARAM);
60
- if (value === null) return "every";
61
- return value === "short" || value === "every" ? value : null;
62
- }
63
-
64
- // src/mcp-register.ts
65
- var MCP_SERVER_NAME = SKILL_NAME;
66
- function detectHermes(env = process.env, home = homedir2()) {
67
- const root = env.HERMES_HOME || join2(home, ".hermes");
68
- return existsSync2(root) ? { id: "hermes", name: "Hermes", root } : null;
69
- }
70
- function detectMcpClients(env = process.env, home = homedir2()) {
71
- const hermes = detectHermes(env, home);
72
- return [...detectLocalAgents(env, home), ...hermes ? [hermes] : []];
73
- }
74
- function systemCommandRunner() {
75
- return {
76
- has: (command) => spawnSync(command, ["--version"], { stdio: "ignore" }).status === 0,
77
- run: (command, args) => {
78
- const result = spawnSync(command, args, { encoding: "utf8" });
79
- return { status: result.status, stderr: result.stderr ?? "", stdout: result.stdout ?? "" };
80
- }
81
- };
82
- }
83
- function mcpUrlFor(apiBase, list = "every") {
84
- return mcpUrlWithToolList(`${apiBase.replace(/\/$/, "")}/mcp`, list);
85
- }
86
- function mcpCommands(agent, opts) {
87
- if (agent === "claude_code") {
88
- return {
89
- command: "claude",
90
- remove: ["mcp", "remove", "--scope", "user", MCP_SERVER_NAME],
91
- add: ["mcp", "add", "--scope", "user", "--transport", "http", MCP_SERVER_NAME, opts.mcpUrl, "--header", `Authorization: Bearer ${opts.token}`]
92
- };
93
- }
94
- if (agent === "grok") {
95
- return {
96
- command: "grok",
97
- remove: ["mcp", "remove", MCP_SERVER_NAME],
98
- add: ["mcp", "add", "--scope", "user", "--transport", "http", "--header", `Authorization: Bearer ${opts.token}`, MCP_SERVER_NAME, opts.mcpUrl]
99
- };
100
- }
101
- return null;
102
- }
103
- function redact(text, token) {
104
- return text.split(token).join(`${token.slice(0, 10)}\u2026`);
105
- }
106
- function registerMcpServer(client, opts, runner = systemCommandRunner()) {
107
- if (client.id === "codex") return registerCodex(client, opts);
108
- if (client.id === "cursor") return registerCursor(client, opts);
109
- if (client.id === "hermes") return registerHermes(client, opts);
110
- const commands = mcpCommands(client.id, opts);
111
- if (!commands) return { agent: client.id, outcome: "unsupported" };
112
- if (!runner.has(commands.command)) return { agent: client.id, outcome: "no_command", detail: `${commands.command} is not on PATH` };
113
- if (opts.dryRun) return { agent: client.id, outcome: "planned", detail: redact(`run ${[commands.command, ...commands.add].join(" ")}`, opts.token) };
114
- runner.run(commands.command, commands.remove);
115
- const added = runner.run(commands.command, commands.add);
116
- if (added.status !== 0) return { agent: client.id, outcome: "failed", detail: redact(added.stderr.trim() || `exit ${added.status}`, opts.token) };
117
- return { agent: client.id, outcome: "registered" };
118
- }
119
- function mcpConfigPath(client, env = process.env, home = homedir2()) {
120
- switch (client.id) {
121
- case "claude_code":
122
- return join2(env.CLAUDE_CONFIG_DIR || home, ".claude.json");
123
- case "codex":
124
- case "grok":
125
- return join2(client.root, "config.toml");
126
- case "cursor":
127
- return join2(client.root, "mcp.json");
128
- case "hermes":
129
- return join2(client.root, "config.yaml");
130
- }
131
- }
132
- function readText(path) {
133
- try {
134
- return readFileSync(path, "utf8");
135
- } catch {
136
- return null;
137
- }
138
- }
139
- function registeredMcpUrl(client, env = process.env, home = homedir2()) {
140
- const raw = readText(mcpConfigPath(client, env, home));
141
- if (raw === null) return null;
142
- try {
143
- let entry;
144
- if (client.id === "codex" || client.id === "grok") entry = parseToml(raw).mcp_servers?.[MCP_SERVER_NAME];
145
- else if (client.id === "hermes") entry = parseDocument(raw).toJS()?.mcp_servers?.[MCP_SERVER_NAME];
146
- else entry = JSON.parse(raw).mcpServers?.[MCP_SERVER_NAME];
147
- const url = entry?.url;
148
- return typeof url === "string" ? url : null;
149
- } catch {
150
- return null;
151
- }
152
- }
153
- function registeredToolList(client, env = process.env, home = homedir2()) {
154
- const url = registeredMcpUrl(client, env, home);
155
- if (url === null) return "every";
156
- try {
157
- return mcpToolListOf(url) === "short" ? "short" : "every";
158
- } catch {
159
- return "every";
160
- }
161
- }
162
- function hasMcpServer(client, env = process.env, home = homedir2()) {
163
- const raw = readText(mcpConfigPath(client, env, home));
164
- if (raw === null) return false;
165
- try {
166
- if (client.id === "codex" || client.id === "grok") return Boolean(parseToml(raw).mcp_servers?.[MCP_SERVER_NAME]);
167
- if (client.id === "hermes") return parseDocument(raw).hasIn(["mcp_servers", MCP_SERVER_NAME]);
168
- return Boolean(JSON.parse(raw).mcpServers?.[MCP_SERVER_NAME]);
169
- } catch {
170
- return false;
171
- }
172
- }
173
- function planned(client, path, entry, opts) {
174
- return { agent: client.id, outcome: "planned", detail: `write to ${path}: ${redact(entry, opts.token)}` };
175
- }
176
- function written(client, path, text) {
177
- try {
178
- writeFileSync(path, text, { encoding: "utf8", mode: 384 });
179
- } catch (err) {
180
- return { agent: client.id, outcome: "failed", detail: String(err) };
181
- }
182
- return { agent: client.id, outcome: "registered" };
183
- }
184
- function tomlTableKey(name) {
185
- const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
186
- return `(?:${escaped}|"${escaped}"|'${escaped}')`;
187
- }
188
- function withoutTomlServer(text, name) {
189
- const ours = new RegExp(`^\\s*\\[\\s*mcp_servers\\s*\\.\\s*${tomlTableKey(name)}\\s*(?:\\.[^\\]]*)?\\]\\s*(?:#.*)?$`);
190
- let skipping = false;
191
- const kept = [];
192
- for (const line of text.split(/\r?\n/)) {
193
- if (/^\s*\[/.test(line)) skipping = ours.test(line);
194
- if (!skipping) kept.push(line);
195
- }
196
- return kept.join("\n").replace(/\n+$/, "");
197
- }
198
- function registerCodex(client, opts) {
199
- const path = mcpConfigPath(client);
200
- const block = [
201
- `[mcp_servers.${MCP_SERVER_NAME}]`,
202
- `url = ${JSON.stringify(opts.mcpUrl)}`,
203
- `http_headers = { Authorization = ${JSON.stringify(`Bearer ${opts.token}`)} }`
204
- ].join("\n");
205
- if (opts.dryRun) return planned(client, path, block, opts);
206
- const raw = readText(path) ?? "";
207
- let before;
208
- try {
209
- before = parseToml(raw);
210
- } catch (err) {
211
- return { agent: client.id, outcome: "failed", detail: `${path} is not valid TOML, left as it was (${String(err).split("\n")[0]})` };
212
- }
213
- const rest = withoutTomlServer(raw, MCP_SERVER_NAME);
214
- const text = `${rest ? `${rest}
215
-
216
- ` : ""}${block}
217
- `;
218
- try {
219
- const after = parseToml(text);
220
- const others = Object.keys(before.mcp_servers ?? {}).filter((name) => name !== MCP_SERVER_NAME);
221
- 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");
222
- } catch (err) {
223
- return { agent: client.id, outcome: "failed", detail: `could not edit ${path} safely, left as it was (${String(err).split("\n")[0]})` };
224
- }
225
- return written(client, path, text);
226
- }
227
- function registerCursor(client, opts) {
228
- const path = mcpConfigPath(client);
229
- const entry = { url: opts.mcpUrl, headers: { Authorization: `Bearer ${opts.token}` } };
230
- if (opts.dryRun) return planned(client, path, JSON.stringify({ [MCP_SERVER_NAME]: entry }, null, 2), opts);
231
- let existing = {};
232
- try {
233
- const parsed = JSON.parse(readText(path) ?? "");
234
- if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) existing = parsed;
235
- } catch {
236
- existing = {};
237
- }
238
- const updated = { ...existing, mcpServers: { ...existing.mcpServers ?? {}, [MCP_SERVER_NAME]: entry } };
239
- return written(client, path, `${JSON.stringify(updated, null, 2)}
240
- `);
241
- }
242
- function registerHermes(client, opts) {
243
- const path = mcpConfigPath(client);
244
- const entry = { url: opts.mcpUrl, headers: { Authorization: `Bearer ${opts.token}` } };
245
- if (opts.dryRun) return planned(client, path, `mcp_servers.${MCP_SERVER_NAME}: ${JSON.stringify(entry)}`, opts);
246
- const doc = parseDocument(readText(path) ?? "");
247
- 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]})` };
248
- if (doc.contents !== null && !isMap(doc.contents)) {
249
- return { agent: client.id, outcome: "failed", detail: `${path} is not a YAML mapping, left as it was` };
250
- }
251
- doc.setIn(["mcp_servers", MCP_SERVER_NAME], doc.createNode(entry));
252
- return written(client, path, doc.toString());
253
- }
254
- function refreshMcpRegistrations(opts, clients = detectMcpClients(), runner = systemCommandRunner(), env = process.env, home = homedir2()) {
255
- return clients.filter((client) => hasMcpServer(client, env, home)).map((client) => registerMcpServer(client, { token: opts.token, mcpUrl: mcpUrlFor(opts.apiBase, registeredToolList(client, env, home)) }, runner));
256
- }
257
-
258
15
  // src/setup-journal.ts
259
16
  import { createHash } from "crypto";
260
- import { chmodSync, existsSync as existsSync4, lstatSync, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync3, rmdirSync, rmSync, statSync, unlinkSync, writeFileSync as writeFileSync3 } from "fs";
261
- import { dirname as dirname2, join as join4, sep } from "path";
17
+ import { chmodSync, existsSync as existsSync2, lstatSync, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync2, rmdirSync, rmSync, statSync, unlinkSync, writeFileSync as writeFileSync2 } from "fs";
18
+ import { dirname as dirname2, join as join2, sep } from "path";
262
19
 
263
20
  // src/shell-env.ts
264
- import { appendFileSync, existsSync as existsSync3, mkdirSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
265
- import { homedir as homedir3 } from "os";
266
- import { basename, dirname, join as join3 } from "path";
21
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
22
+ import { homedir } from "os";
23
+ import { basename, dirname, join } from "path";
267
24
  var TOKEN_ENV = "AGENTSKY_API_KEY";
268
25
  var SHELL_HOOK_MARK = "# AgentSky API token, kept current by sky";
269
26
  function shellEnvFiles() {
270
27
  const dir = dirname(configPath());
271
- return { sh: join3(dir, "env.sh"), fish: join3(dir, "env.fish") };
28
+ return { sh: join(dir, "env.sh"), fish: join(dir, "env.fish") };
272
29
  }
273
30
  function quoted(value) {
274
31
  return `'${value.replace(/'/g, `'\\''`)}'`;
275
32
  }
276
- function shellStartupFiles(env = process.env, home = homedir3(), platform = process.platform) {
33
+ function shellStartupFiles(env = process.env, home = homedir(), platform = process.platform) {
277
34
  const shell = basename(env.SHELL ?? "");
278
35
  const files = [];
279
- const zshenv = join3(env.ZDOTDIR || home, ".zshenv");
280
- if (shell === "zsh" || platform === "darwin" || existsSync3(zshenv)) files.push({ path: zshenv, kind: "sh" });
281
- const bashrc = join3(home, ".bashrc");
282
- if (shell === "bash" || existsSync3(bashrc)) files.push({ path: bashrc, kind: "sh" });
283
- const bashProfile = join3(home, ".bash_profile");
284
- if (existsSync3(bashProfile)) files.push({ path: bashProfile, kind: "sh" });
285
- const fish = join3(env.XDG_CONFIG_HOME || join3(home, ".config"), "fish");
286
- if (shell === "fish" || existsSync3(fish)) files.push({ path: join3(fish, "conf.d", "agentsky.fish"), kind: "fish" });
36
+ const zshenv = join(env.ZDOTDIR || home, ".zshenv");
37
+ if (shell === "zsh" || platform === "darwin" || existsSync(zshenv)) files.push({ path: zshenv, kind: "sh" });
38
+ const bashrc = join(home, ".bashrc");
39
+ if (shell === "bash" || existsSync(bashrc)) files.push({ path: bashrc, kind: "sh" });
40
+ const bashProfile = join(home, ".bash_profile");
41
+ if (existsSync(bashProfile)) files.push({ path: bashProfile, kind: "sh" });
42
+ const fish = join(env.XDG_CONFIG_HOME || join(home, ".config"), "fish");
43
+ if (shell === "fish" || existsSync(fish)) files.push({ path: join(fish, "conf.d", "agentsky.fish"), kind: "fish" });
287
44
  return files;
288
45
  }
289
46
  function writeShellEnv(token, opts = {}) {
@@ -294,12 +51,12 @@ function writeShellEnv(token, opts = {}) {
294
51
  const hooked = [];
295
52
  try {
296
53
  mkdirSync(dirname(sh), { recursive: true });
297
- writeFileSync2(sh, `${header}${token ? `export ${TOKEN_ENV}=${quoted(token)}` : `unset ${TOKEN_ENV}`}
54
+ writeFileSync(sh, `${header}${token ? `export ${TOKEN_ENV}=${quoted(token)}` : `unset ${TOKEN_ENV}`}
298
55
  `, { mode: 384 });
299
- writeFileSync2(fish, `${header}${token ? `set -gx ${TOKEN_ENV} ${quoted(token)}` : `set -e ${TOKEN_ENV}`}
56
+ writeFileSync(fish, `${header}${token ? `set -gx ${TOKEN_ENV} ${quoted(token)}` : `set -e ${TOKEN_ENV}`}
300
57
  `, { mode: 384 });
301
58
  for (const file of startup) {
302
- const existing = existsSync3(file.path) ? readFileSync2(file.path, "utf8") : "";
59
+ const existing = existsSync(file.path) ? readFileSync(file.path, "utf8") : "";
303
60
  if (existing.includes(SHELL_HOOK_MARK)) continue;
304
61
  const line = file.kind === "fish" ? `${SHELL_HOOK_MARK}
305
62
  test -f ${quoted(fish)}; and source ${quoted(fish)}
@@ -320,20 +77,20 @@ test -f ${quoted(fish)}; and source ${quoted(fish)}
320
77
  var sha = (bytes) => bytes ? createHash("sha256").update(bytes).digest("hex") : null;
321
78
  function readBytes(path) {
322
79
  try {
323
- return readFileSync3(path);
80
+ return readFileSync2(path);
324
81
  } catch {
325
82
  return null;
326
83
  }
327
84
  }
328
85
  function journalPath() {
329
- return join4(dirname2(configPath()), "setup-journal.json");
86
+ return join2(dirname2(configPath()), "setup-journal.json");
330
87
  }
331
88
  var SetupJournal = class {
332
89
  constructor(path = journalPath()) {
333
90
  this.path = path;
334
91
  let loaded = {};
335
92
  try {
336
- loaded = JSON.parse(readFileSync3(path, "utf8"));
93
+ loaded = JSON.parse(readFileSync2(path, "utf8"));
337
94
  } catch {
338
95
  loaded = {};
339
96
  }
@@ -348,7 +105,7 @@ var SetupJournal = class {
348
105
  }
349
106
  createdDirs(path) {
350
107
  const missing = [];
351
- for (let dir = dirname2(path); !existsSync4(dir) && dirname2(dir) !== dir; dir = dirname2(dir)) missing.push(dir);
108
+ for (let dir = dirname2(path); !existsSync2(dir) && dirname2(dir) !== dir; dir = dirname2(dir)) missing.push(dir);
352
109
  for (const dir of missing.reverse()) if (!this.data.dirs.includes(dir)) this.data.dirs.push(dir);
353
110
  }
354
111
  /** Call before setup writes `path`: keeps its bytes the first time, and notes the entries setup puts in it. */
@@ -371,9 +128,13 @@ var SetupJournal = class {
371
128
  }
372
129
  this.touched.add(path);
373
130
  }
131
+ /** Whether setup has written `path` before, so a change to it since is someone else's. */
132
+ tracks(path) {
133
+ return Boolean(this.data.files[path]) || this.owns(path);
134
+ }
374
135
  /** Call before setup creates a path it owns outright (its own state, a CLI it installs); one that already existed is left to its owner. */
375
136
  own(path) {
376
- if (existsSync4(path) || this.owns(path) || this.data.files[path]) return;
137
+ if (existsSync2(path) || this.owns(path) || this.data.files[path]) return;
377
138
  this.createdDirs(path);
378
139
  this.data.owned.push(path);
379
140
  }
@@ -397,7 +158,7 @@ var SetupJournal = class {
397
158
  return;
398
159
  }
399
160
  mkdirSync2(dirname2(this.path), { recursive: true });
400
- writeFileSync3(this.path, `${JSON.stringify(this.data, null, 2)}
161
+ writeFileSync2(this.path, `${JSON.stringify(this.data, null, 2)}
401
162
  `, { mode: 384 });
402
163
  }
403
164
  /**
@@ -415,7 +176,7 @@ var SetupJournal = class {
415
176
  }
416
177
  for (const [path, record] of Object.entries(this.data.files)) results.push(restoreFile(path, record));
417
178
  for (const path of this.data.owned) {
418
- if (!existsSync4(path) && !isLink(path)) continue;
179
+ if (!existsSync2(path) && !isLink(path)) continue;
419
180
  rmSync(path, { recursive: true, force: true });
420
181
  results.push({ path, outcome: "removed" });
421
182
  }
@@ -450,7 +211,7 @@ function restoreFile(path, record) {
450
211
  return { path, outcome: "removed" };
451
212
  }
452
213
  mkdirSync2(dirname2(path), { recursive: true });
453
- writeFileSync3(path, original);
214
+ writeFileSync2(path, original);
454
215
  if (record.mode !== null) chmodSync(path, record.mode);
455
216
  return { path, outcome: "restored" };
456
217
  }
@@ -463,7 +224,7 @@ function restoreFile(path, record) {
463
224
  text = remove(text);
464
225
  }
465
226
  if (text === current.toString("utf8")) return { path, outcome: "left", detail: "changed since setup; nothing of setup's is left in it" };
466
- writeFileSync3(path, text);
227
+ writeFileSync2(path, text);
467
228
  return { path, outcome: "entries_removed", detail: "changed since setup, so only setup's entries were taken out" };
468
229
  }
469
230
  var CAPTURE_HOOK_ARGS = ["trace", "sync", "--hook"];
@@ -554,7 +315,8 @@ var ENTRY_REMOVERS = {
554
315
  mcp_toml: withoutTomlServerText,
555
316
  mcp_yaml: withoutYamlServer,
556
317
  shell_line: withoutShellLine,
557
- sync_config: withCaptureOff
318
+ sync_config: withCaptureOff,
319
+ settings_block: withoutSettingsBlock
558
320
  };
559
321
 
560
322
  // src/workspace.ts
@@ -707,16 +469,6 @@ function typedConfirmation(slug) {
707
469
  }
708
470
 
709
471
  export {
710
- detectLocalAgents,
711
- selectLocalAgents,
712
- detectHermes,
713
- detectMcpClients,
714
- systemCommandRunner,
715
- mcpUrlFor,
716
- registerMcpServer,
717
- mcpConfigPath,
718
- hasMcpServer,
719
- refreshMcpRegistrations,
720
472
  TOKEN_ENV,
721
473
  shellEnvFiles,
722
474
  shellStartupFiles,
@@ -1,13 +1,6 @@
1
1
  import {
2
2
  CLI_VERSION
3
- } from "./chunk-4A4PDUT5.js";
4
- import {
5
- configPath
6
- } from "./chunk-XHZJG3QT.js";
7
-
8
- // src/local-skills.ts
9
- import { existsSync, mkdirSync as mkdirSync2, readFileSync as readFileSync2, renameSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
10
- import { dirname, join as join2, resolve, sep } from "path";
3
+ } from "./chunk-7DFFA6GA.js";
11
4
 
12
5
  // src/skill.ts
13
6
  import { mkdirSync, readFileSync, writeFileSync } from "fs";
@@ -131,8 +124,10 @@ Details: \`${REFERENCES_DIR}/workspaces.md\` in this skill's folder.
131
124
  - Anything else the person can do on agentsky.dev or in the Mac app (rename or
132
125
  archive a thread, edit a Library file or skill, change an agent's model, invite
133
126
  a member, \u2026) is an API operation: find it with \`search_api\`, read its
134
- parameters with \`describe_api\`, and run it with \`call_api\`. It acts as the
135
- person with their own key, so make only the change they asked for. Where MCP
127
+ parameters with \`search_api\` given its method and path, and run it with \`call_api\`. It acts as the
128
+ person with their own key, so make only the change they asked for. The
129
+ workspace's files have their own tools: \`search_files\`, \`read_file\` and
130
+ \`write_file\`. Where MCP
136
131
  is missing, \`sky api search <words>\` and \`sky api <METHOD> <path>\` do the same.
137
132
 
138
133
  ## How to pick
@@ -201,7 +196,8 @@ it, and name its path in the brief.
201
196
  \`update_artifact\` renames one and \`copy_artifact\` copies one version of it.
202
197
  \`export_artifact\` hands a result over in any format its \`export_formats\`
203
198
  lists, and \`import_artifact\` brings in a file or a public page as a result.
204
- 5. \`stop_session\` every agent you no longer need.
199
+ 5. Archive every agent you no longer need: \`stop_session\`, or \`call_api\`
200
+ \`POST /sessions/{id}/archive\` where your tool list has no \`stop_session\`.
205
201
  6. Tell the person what was done, which agent did which part, and what it cost
206
202
  (\`get_session_status\` reports the task's cost).
207
203
 
@@ -531,6 +527,10 @@ function installedVersion(dir) {
531
527
  return null;
532
528
  }
533
529
  }
530
+ function skillState(agent) {
531
+ const version = installedVersion(join(agent.skillsDir, SKILL_NAME));
532
+ return version === null ? "missing" : version === CLI_VERSION ? "current" : "behind";
533
+ }
534
534
  function isInstalledSkill(dir) {
535
535
  return installedVersion(dir) !== null;
536
536
  }
@@ -575,187 +575,11 @@ function skillReferenceFiles() {
575
575
  };
576
576
  }
577
577
 
578
- // src/local-skills.ts
579
- var HISTORY = 20;
580
- var SAFE_NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
581
- function localSkillStatePath() {
582
- return join2(dirname(configPath()), "local-skills.json");
583
- }
584
- function loadLocalSkillState(path = localSkillStatePath()) {
585
- try {
586
- const parsed = JSON.parse(readFileSync2(path, "utf8"));
587
- return { version: 1, workspace: parsed.workspace, checkedAt: parsed.checkedAt, pins: parsed.pins ?? {}, skills: parsed.skills ?? {} };
588
- } catch {
589
- return { version: 1, pins: {}, skills: {} };
590
- }
591
- }
592
- function saveLocalSkillState(state, path = localSkillStatePath()) {
593
- mkdirSync2(dirname(path), { recursive: true });
594
- writeFileSync2(path, `${JSON.stringify(state, null, 2)}
595
- `, { mode: 384 });
596
- }
597
- function installedMarker(dir) {
598
- try {
599
- const marker = JSON.parse(readFileSync2(join2(dir, SKILL_MARKER), "utf8"));
600
- if (typeof marker.version !== "string") return null;
601
- return {
602
- version: marker.version,
603
- ...typeof marker.skill_id === "string" ? { skill_id: marker.skill_id } : {},
604
- ...typeof marker.revision_id === "string" ? { revision_id: marker.revision_id } : {},
605
- ...typeof marker.fingerprint === "string" ? { fingerprint: marker.fingerprint } : {}
606
- };
607
- } catch {
608
- return null;
609
- }
610
- }
611
- var deliveredHere = (dir) => installedMarker(dir)?.fingerprint !== void 0;
612
- function currentEverywhere(targets, name, fingerprint) {
613
- return targets.every((target) => installedMarker(join2(target.skillsDir, name))?.fingerprint === fingerprint);
614
- }
615
- function writeSkillDir(dir, skill, journal) {
616
- const root = resolve(dir);
617
- const staging = `${root}.sky-staging`;
618
- rmSync(staging, { recursive: true, force: true });
619
- for (const file of skill.files ?? []) {
620
- const target = resolve(staging, file.path);
621
- if (!target.startsWith(`${staging}${sep}`) || file.path === SKILL_MARKER) throw new Error(`${skill.name}: refused the file ${file.path}`);
622
- mkdirSync2(dirname(target), { recursive: true });
623
- writeFileSync2(target, Buffer.from(file.contentBase64, "base64"), { mode: file.executable ? 493 : 420 });
624
- }
625
- writeFileSync2(join2(staging, SKILL_MARKER), `${JSON.stringify({ version: CLI_VERSION, skill_id: skill.skill_id, revision_id: skill.revision_id, fingerprint: skill.fingerprint, layer: skill.layer }, null, 2)}
626
- `);
627
- journal?.own(root);
628
- rmSync(root, { recursive: true, force: true });
629
- renameSync(staging, root);
630
- }
631
- function installedFingerprints(state, targets) {
632
- return Object.entries(state.skills).flatMap(([name, entry2]) => {
633
- const latest = entry2.installs.at(-1);
634
- return latest && currentEverywhere(targets, name, latest.fingerprint) ? [latest.fingerprint] : [];
635
- });
636
- }
637
- async function syncLocalSkills(opts) {
638
- const now = (opts.now ?? (() => /* @__PURE__ */ new Date()))().toISOString();
639
- const statePath = opts.statePath ?? localSkillStatePath();
640
- const state = loadLocalSkillState(statePath);
641
- const before = JSON.stringify({ pins: state.pins, skills: state.skills });
642
- const have = installedFingerprints(state, opts.targets);
643
- const answer = await opts.request("GET", `/skills/local${have.length ? `?have=${encodeURIComponent(have.join(","))}` : ""}`, opts.workspace);
644
- const outcomes = [];
645
- const named = /* @__PURE__ */ new Set();
646
- for (const skill of answer.skills ?? []) {
647
- if (!SAFE_NAME.test(skill.name) || skill.name === SKILL_NAME) {
648
- outcomes.push({ name: skill.name, outcome: "failed", detail: "not a folder name sky writes" });
649
- continue;
650
- }
651
- named.add(skill.name);
652
- const base = { name: skill.name, revision_id: skill.revision_id, layer: skill.layer, ...skill.hides ? { hides: skill.hides.skill_id } : {} };
653
- const pinned = state.pins[skill.name];
654
- if (pinned && pinned !== skill.fingerprint && state.skills[skill.name]) {
655
- outcomes.push({ ...base, revision_id: state.skills[skill.name].installs.at(-1)?.revision_id, outcome: "pinned" });
656
- continue;
657
- }
658
- if (currentEverywhere(opts.targets, skill.name, skill.fingerprint)) {
659
- outcomes.push({ ...base, outcome: "current" });
660
- recordInstall(state, skill, now);
661
- continue;
662
- }
663
- if (!skill.files) {
664
- outcomes.push({ ...base, outcome: "failed", detail: "the files were not sent; the next sync fetches them" });
665
- continue;
666
- }
667
- if (opts.dryRun) {
668
- outcomes.push({ ...base, outcome: "planned" });
669
- continue;
670
- }
671
- let wrote = false;
672
- let kept;
673
- try {
674
- for (const target of opts.targets) {
675
- const dir = join2(target.skillsDir, skill.name);
676
- if (existsSync(dir) && !deliveredHere(dir)) {
677
- kept = dir;
678
- continue;
679
- }
680
- if (installedMarker(dir)?.fingerprint === skill.fingerprint) continue;
681
- writeSkillDir(dir, skill, opts.journal);
682
- wrote = true;
683
- }
684
- } catch (error) {
685
- outcomes.push({ ...base, outcome: "failed", detail: error instanceof Error ? error.message : String(error) });
686
- continue;
687
- }
688
- const earlier = state.skills[skill.name]?.installs.length;
689
- if (wrote || !kept) recordInstall(state, skill, now);
690
- outcomes.push({ ...base, outcome: !wrote && kept ? "kept_yours" : earlier ? "updated" : "installed", ...kept ? { detail: `${kept} is your own; left as it is` } : {} });
691
- }
692
- for (const name of Object.keys(state.skills)) {
693
- if (named.has(name) || state.pins[name]) continue;
694
- if (!opts.dryRun) {
695
- for (const target of opts.targets) {
696
- const dir = join2(target.skillsDir, name);
697
- if (deliveredHere(dir)) rmSync(dir, { recursive: true, force: true });
698
- }
699
- delete state.skills[name];
700
- }
701
- outcomes.push({ name, outcome: opts.dryRun ? "planned" : "removed" });
702
- }
703
- const changed = JSON.stringify({ pins: state.pins, skills: state.skills }) !== before;
704
- if (!opts.dryRun && (changed || opts.recordCheck !== false)) {
705
- opts.journal?.own(statePath);
706
- saveLocalSkillState({ ...state, workspace: answer.workspace ?? opts.workspace, checkedAt: now }, statePath);
707
- }
708
- return { workspace: answer.workspace ?? opts.workspace, checked: true, skills: outcomes };
709
- }
710
- function recordInstall(state, skill, at) {
711
- const entry2 = state.skills[skill.name] ?? { skill_id: skill.skill_id, layer: skill.layer, hides: skill.hides, installs: [] };
712
- if (entry2.installs.at(-1)?.fingerprint !== skill.fingerprint) entry2.installs = [...entry2.installs, { revision_id: skill.revision_id, fingerprint: skill.fingerprint, from: at }].slice(-HISTORY);
713
- state.skills[skill.name] = { ...entry2, skill_id: skill.skill_id, layer: skill.layer, hides: skill.hides };
714
- }
715
- function pinLocalSkill(name, statePath) {
716
- const state = loadLocalSkillState(statePath);
717
- const latest = state.skills[name]?.installs.at(-1);
718
- if (!latest) throw new Error(`no skill named ${name} is installed by sky on this computer; see \`sky skills local\``);
719
- state.pins[name] = latest.fingerprint;
720
- saveLocalSkillState(state, statePath);
721
- return latest;
722
- }
723
- function unpinLocalSkill(name, statePath) {
724
- const state = loadLocalSkillState(statePath);
725
- if (!state.pins[name]) return false;
726
- delete state.pins[name];
727
- saveLocalSkillState(state, statePath);
728
- return true;
729
- }
730
- function checkedWithin(ms, now = /* @__PURE__ */ new Date(), statePath) {
731
- const at = Date.parse(loadLocalSkillState(statePath).checkedAt ?? "");
732
- return Number.isFinite(at) && now.getTime() - at < ms;
733
- }
734
- function skillTargets(agents, hermesRoot) {
735
- return [...agents.map((agent) => ({ id: agent.id, skillsDir: agent.skillsDir })), ...hermesRoot ? [{ id: "hermes", skillsDir: join2(hermesRoot, "skills") }] : []];
736
- }
737
- function revisionAt(state, name, at) {
738
- const installs = state.skills[name]?.installs ?? [];
739
- const when = Date.parse(at ?? "");
740
- if (!Number.isFinite(when)) return installs.at(-1)?.revision_id ?? null;
741
- let found = null;
742
- for (const install of installs) if (Date.parse(install.from) <= when) found = install.revision_id;
743
- return found;
744
- }
745
-
746
578
  export {
747
579
  SKILL_NAME,
580
+ SKILL_MARKER,
581
+ skillState,
748
582
  isInstalledSkill,
749
583
  installSkill,
750
- skillPaths,
751
- localSkillStatePath,
752
- loadLocalSkillState,
753
- saveLocalSkillState,
754
- installedMarker,
755
- syncLocalSkills,
756
- pinLocalSkill,
757
- unpinLocalSkill,
758
- checkedWithin,
759
- skillTargets,
760
- revisionAt
584
+ skillPaths
761
585
  };