@asteroidai/cli 1.9.181 → 1.9.185

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.
package/dist/asteroid.js CHANGED
@@ -4305,7 +4305,7 @@ var COMMANDS = [
4305
4305
  command: "skill get",
4306
4306
  tool: "skill_get",
4307
4307
  title: "Get skill",
4308
- description: "Get one skill with the content of every file, SKILL.md first, in the Agent Skills format. A name resolves to the public skill, then a portal's, then the organization's; set `kind` to pick one. A portal skill needs its portal added with `portal_skills_add`. Pass `surface` `mcp` to spell the platform's commands as MCP tools.",
4308
+ description: "Get one skill with the content of every file, SKILL.md first, in the Agent Skills format. A large skill can exceed your result limit: pass `paths` to fetch only some files, such as `SKILL.md` first and then the reference files it names. A link like `../workflow-reference/references/nodes.md` is file `references/nodes.md` of skill `workflow-reference`. `skills_list` gives every file's path and size. A name resolves to the public skill, then a portal's, then the organization's; set `kind` to pick one. A portal skill needs its portal added with `portal_skills_add`. Pass `surface` `mcp` to spell the platform's commands as MCP tools.",
4309
4309
  method: "GET",
4310
4310
  path: "/astro/v2/skills/{name}",
4311
4311
  args: [
@@ -4317,6 +4317,13 @@ var COMMANDS = [
4317
4317
  }
4318
4318
  ],
4319
4319
  query: [
4320
+ {
4321
+ name: "paths",
4322
+ flag: "paths",
4323
+ type: "string[]",
4324
+ required: false,
4325
+ description: "Return only the files at these skill-relative paths, such as `SKILL.md` or `references/nodes.md`. A path that names no file yields no entry."
4326
+ },
4320
4327
  {
4321
4328
  name: "kind",
4322
4329
  flag: "kind",
@@ -6723,6 +6730,7 @@ import {
6723
6730
  renameSync,
6724
6731
  writeFileSync
6725
6732
  } from "node:fs";
6733
+ import { homedir } from "node:os";
6726
6734
  import { dirname, join } from "node:path";
6727
6735
 
6728
6736
  // src/output.ts
@@ -6872,7 +6880,8 @@ function readEnv(env = process.env) {
6872
6880
  org: env.ASTEROID_ORG || void 0,
6873
6881
  workosClientId: env.ASTEROID_WORKOS_CLIENT_ID || DEFAULT_WORKOS_CLIENT_ID,
6874
6882
  workosApiUrl: (env.ASTEROID_WORKOS_API_URL || DEFAULT_WORKOS_API_URL).replace(/\/+$/, ""),
6875
- configDir: env.ASTEROID_CONFIG_DIR || envPaths("asteroid", { suffix: "" }).config
6883
+ configDir: env.ASTEROID_CONFIG_DIR || envPaths("asteroid", { suffix: "" }).config,
6884
+ home: env.HOME || homedir()
6876
6885
  };
6877
6886
  }
6878
6887
  function readJson(path, fallback) {
@@ -6945,8 +6954,9 @@ var BUILTINS = [
6945
6954
  {
6946
6955
  command: "login",
6947
6956
  usage: "asteroid login",
6948
- description: "Sign in with your browser. Stores a refresh token in the OS keychain, or in a private file in the config directory when no keychain is available.",
6949
- args: 0
6957
+ description: "Sign in with your browser. Stores a refresh token in the OS keychain, or in a private file in the config directory when no keychain is available. Then offers to install the Asteroid skills into every skills directory it finds: `~/.claude/skills` (Claude Code), `~/.cursor/skills` (Cursor) and `~/.agents/skills`.",
6958
+ args: 0,
6959
+ options: [["--no-skills", "Do not offer to install the Asteroid skills."]]
6950
6960
  },
6951
6961
  {
6952
6962
  command: "logout",
@@ -6989,6 +6999,16 @@ var BUILTINS = [
6989
6999
  usage: "asteroid whoami",
6990
7000
  description: "Show who you act as, in which organization, and how long the token lasts.",
6991
7001
  args: 0
7002
+ },
7003
+ {
7004
+ command: "skill sync",
7005
+ usage: "asteroid skill sync",
7006
+ description: "Install the Asteroid skills, or bring them up to date, in every skills directory found: `~/.claude/skills`, `~/.cursor/skills` and `~/.agents/skills`. Writes the files that changed, removes the skills the API no longer serves, and leaves a skill directory it did not create alone.",
7007
+ args: 0,
7008
+ options: [
7009
+ ["--no-remove", "Keep the skills and files the API no longer serves."]
7010
+ ],
7011
+ section: "Skills"
6992
7012
  }
6993
7013
  ];
6994
7014
  var BUILTIN_COMMANDS = new Set(BUILTINS.map((b) => b.command));
@@ -7132,9 +7152,16 @@ function defineCommands(root, options, dotted2 = /* @__PURE__ */ new Map(), onIn
7132
7152
  for (const [flags, text3] of GLOBAL_FLAGS) {
7133
7153
  if (!flags.startsWith("-h")) root.option(flags, text3);
7134
7154
  }
7155
+ const groups = /* @__PURE__ */ new Map();
7135
7156
  for (const builtin of options.builtins ?? []) {
7136
- const leaf = root.command(builtin.command).description(builtin.description);
7157
+ const words = builtin.command.split(" ");
7158
+ let parent = root;
7159
+ for (let i = 0; i < words.length - 1; i++) {
7160
+ parent = group(parent, words[i], groups, words.slice(0, i + 1).join(" "));
7161
+ }
7162
+ const leaf = parent.command(words.at(-1)).description(builtin.description);
7137
7163
  if (builtin.arg) leaf.argument(`[${builtin.arg}]`);
7164
+ for (const [flags, text3] of builtin.options ?? []) leaf.option(flags, text3);
7138
7165
  for (const [flags, text3] of builtin.hiddenOptions ?? [])
7139
7166
  leaf.addOption(new Flag(flags, text3).hideHelp());
7140
7167
  leaf.action((...args) => {
@@ -7147,7 +7174,6 @@ function defineCommands(root, options, dotted2 = /* @__PURE__ */ new Map(), onIn
7147
7174
  });
7148
7175
  }
7149
7176
  const reserved = new Set((options.builtins ?? []).map((b) => b.command));
7150
- const groups = /* @__PURE__ */ new Map();
7151
7177
  for (const command of options.commands) {
7152
7178
  if (reserved.has(command.command)) continue;
7153
7179
  const words = command.command.split(" ");
@@ -7263,7 +7289,7 @@ async function runCompletion(argv2, options) {
7263
7289
  }
7264
7290
 
7265
7291
  // src/run.ts
7266
- import { writeFileSync as writeFileSync2 } from "node:fs";
7292
+ import { writeFileSync as writeFileSync3 } from "node:fs";
7267
7293
 
7268
7294
  // src/auth/store.ts
7269
7295
  import { mkdirSync as mkdirSync2, rmSync } from "node:fs";
@@ -7710,7 +7736,7 @@ var ApiError = class extends Error {
7710
7736
  status;
7711
7737
  body;
7712
7738
  };
7713
- var VERSION = "1.9.181";
7739
+ var VERSION = "1.9.185";
7714
7740
  function problem(status, body, fallback) {
7715
7741
  if (body && typeof body === "object") {
7716
7742
  const record2 = body;
@@ -7796,6 +7822,456 @@ async function send(apiUrl, auth, request, binary, fetchImpl = fetch) {
7796
7822
  return { status: response.status, text: await response.text() };
7797
7823
  }
7798
7824
 
7825
+ // src/skills.ts
7826
+ import {
7827
+ existsSync as existsSync2,
7828
+ lstatSync,
7829
+ mkdirSync as mkdirSync3,
7830
+ readdirSync,
7831
+ rmdirSync,
7832
+ rmSync as rmSync2,
7833
+ writeFileSync as writeFileSync2
7834
+ } from "node:fs";
7835
+ import { dirname as dirname2, join as join4 } from "node:path";
7836
+
7837
+ // ../workflow-files/src/representation/name-charset.ts
7838
+ var NAME_CHARSET_RE = /^[A-Za-z0-9 !#$%&'()+,.;=@^`{}[\]~-]+$/;
7839
+ var WINDOWS_RESERVED = /* @__PURE__ */ new Set([
7840
+ "con",
7841
+ "prn",
7842
+ "aux",
7843
+ "nul",
7844
+ ...Array.from({ length: 9 }, (_, i) => `com${i + 1}`),
7845
+ ...Array.from({ length: 9 }, (_, i) => `lpt${i + 1}`)
7846
+ ]);
7847
+ function isNameCharsetConforming(name) {
7848
+ return NAME_CHARSET_RE.test(name);
7849
+ }
7850
+
7851
+ // ../workflow-files/src/representation/types.ts
7852
+ function normalizeNodeName(name) {
7853
+ let result = name.toLowerCase();
7854
+ result = result.replace(/[^a-z0-9]+/g, "_");
7855
+ result = result.replace(/^_+|_+$/g, "");
7856
+ if (result.length > 80) {
7857
+ result = result.slice(0, 80).replace(/_+$/, "");
7858
+ }
7859
+ if (result === "") {
7860
+ throw new Error(
7861
+ `representation: node name "${name}" produces an empty directory name after normalization`
7862
+ );
7863
+ }
7864
+ return result;
7865
+ }
7866
+ function lossySlugOr(name, fallback) {
7867
+ try {
7868
+ return normalizeNodeName(name);
7869
+ } catch {
7870
+ return fallback;
7871
+ }
7872
+ }
7873
+ function nodeDirName(name) {
7874
+ if (isNameCharsetConforming(name)) {
7875
+ return name.replaceAll(" ", "_");
7876
+ }
7877
+ return normalizeNodeName(name);
7878
+ }
7879
+ function agentDirName(name) {
7880
+ try {
7881
+ return nodeDirName(name);
7882
+ } catch {
7883
+ return "agent";
7884
+ }
7885
+ }
7886
+ function executionDirName(executionId2) {
7887
+ return executionId2.slice(0, 8);
7888
+ }
7889
+ function workflowDirName(workflowId, version, parentId, parentVersion) {
7890
+ const short = workflowId.slice(0, 8);
7891
+ if (version !== void 0 && version !== null) {
7892
+ return `v${version}_${short}`;
7893
+ }
7894
+ if (parentId) {
7895
+ if (parentVersion !== void 0 && parentVersion !== null) {
7896
+ return `draft_${short}_from_v${parentVersion}`;
7897
+ }
7898
+ return `draft_${short}_from_draft_${parentId.slice(0, 8)}`;
7899
+ }
7900
+ return `draft_${short}`;
7901
+ }
7902
+
7903
+ // src/sync/paths.ts
7904
+ import { createHash } from "node:crypto";
7905
+ function join3(...parts) {
7906
+ return parts.filter((part) => part !== "").join("/").replace(/\/{2,}/g, "/");
7907
+ }
7908
+ function workflowRoot(root, workflowName) {
7909
+ return join3(root, agentDirName(workflowName));
7910
+ }
7911
+ function isContained(path) {
7912
+ if (path === "" || path.startsWith("/") || path.includes("\\")) return false;
7913
+ return path.split("/").every((segment) => segment !== ".." && segment !== "");
7914
+ }
7915
+ function sha256(bytes) {
7916
+ return createHash("sha256").update(bytes).digest("hex");
7917
+ }
7918
+ function matchesGlob(path, pattern) {
7919
+ let source = "";
7920
+ for (let i = 0; i < pattern.length; i++) {
7921
+ const ch = pattern[i];
7922
+ if (ch === "*" && pattern[i + 1] === "*" && pattern[i + 2] === "/") {
7923
+ source += "(?:.*/)?";
7924
+ i += 2;
7925
+ } else if (ch === "*" && pattern[i + 1] === "*") {
7926
+ source += ".*";
7927
+ i += 1;
7928
+ } else if (ch === "*") source += "[^/]*";
7929
+ else if (ch === "?") source += "[^/]";
7930
+ else source += ch.replace(/[.+^${}()|[\]\\]/g, "\\$&");
7931
+ }
7932
+ return new RegExp(`^${source}$`).test(path);
7933
+ }
7934
+
7935
+ // src/skills.ts
7936
+ var SKILLS_FILE = "skills.json";
7937
+ var CHECK_INTERVAL_MS = 24 * 36e5;
7938
+ var SYNC_HINT = "Run `asteroid skill sync`";
7939
+ var HOST_PARENTS = [
7940
+ { name: "Claude Code", parent: ".claude" },
7941
+ { name: "Cursor", parent: ".cursor" },
7942
+ { name: "~/.agents", parent: ".agents" }
7943
+ ];
7944
+ var SKILL_NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
7945
+ var CONCURRENCY = 8;
7946
+ function detectHosts(home) {
7947
+ return HOST_PARENTS.filter((host) => existsSync2(join4(home, host.parent))).map(
7948
+ (host) => ({ name: host.name, dir: join4(home, host.parent, "skills") })
7949
+ );
7950
+ }
7951
+ function hostLabel(hosts) {
7952
+ const names = hosts.map((host) => host.name);
7953
+ if (names.length <= 1) return names.join("");
7954
+ return `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`;
7955
+ }
7956
+ function loadSkillsState(env) {
7957
+ const state = readJson(
7958
+ join4(env.configDir, SKILLS_FILE),
7959
+ {}
7960
+ );
7961
+ return { ...state, hosts: state.hosts ?? {} };
7962
+ }
7963
+ function saveSkillsState(env, state) {
7964
+ writePrivateJson(join4(env.configDir, SKILLS_FILE), state);
7965
+ }
7966
+ function installable(row) {
7967
+ return row.kind !== "portal" || row.added === true;
7968
+ }
7969
+ function wantedSkills(rows, skipped) {
7970
+ const seen = /* @__PURE__ */ new Set();
7971
+ const wanted = [];
7972
+ for (const row of rows) {
7973
+ if (!installable(row)) continue;
7974
+ if (!SKILL_NAME.test(row.name)) {
7975
+ skipped.push(`${clean(row.name)} (not a skill name)`);
7976
+ continue;
7977
+ }
7978
+ if (seen.has(row.name)) {
7979
+ skipped.push(
7980
+ `${row.kind} skill ${row.name} (another skill has the same name)`
7981
+ );
7982
+ continue;
7983
+ }
7984
+ seen.add(row.name);
7985
+ wanted.push(row);
7986
+ }
7987
+ return wanted;
7988
+ }
7989
+ async function listSkills(env, auth, fetchImpl) {
7990
+ const response = await send(
7991
+ env.apiUrl,
7992
+ auth,
7993
+ { method: "GET", path: "/astro/v2/skills", query: new URLSearchParams() },
7994
+ false,
7995
+ fetchImpl
7996
+ );
7997
+ return response.json.skills ?? [];
7998
+ }
7999
+ async function getSkill(env, auth, fetchImpl, row) {
8000
+ const response = await send(
8001
+ env.apiUrl,
8002
+ auth,
8003
+ {
8004
+ method: "GET",
8005
+ path: `/astro/v2/skills/${encodeURIComponent(row.name)}`,
8006
+ query: new URLSearchParams({ kind: row.kind })
8007
+ },
8008
+ false,
8009
+ fetchImpl
8010
+ );
8011
+ return response.json;
8012
+ }
8013
+ function servedDigests(row, skipped) {
8014
+ const digests = {};
8015
+ for (const file of row.files) {
8016
+ if (isContained(file.path)) digests[file.path] = file.digest;
8017
+ else skipped.push(`${row.name}/${clean(file.path)} (unsafe path)`);
8018
+ }
8019
+ return digests;
8020
+ }
8021
+ function sameDigests(a, b) {
8022
+ if (!a) return false;
8023
+ const keys = Object.keys(a);
8024
+ return keys.length === Object.keys(b).length && keys.every((path) => a[path] === b[path]);
8025
+ }
8026
+ function removeEmptyDirs(from, upTo) {
8027
+ let dir = from;
8028
+ while (dir.startsWith(upTo)) {
8029
+ try {
8030
+ if (readdirSync(dir).length > 0) return;
8031
+ rmdirSync(dir);
8032
+ } catch {
8033
+ return;
8034
+ }
8035
+ if (dir === upTo) return;
8036
+ dir = dirname2(dir);
8037
+ }
8038
+ }
8039
+ function removeFile(skillDir, path) {
8040
+ rmSync2(join4(skillDir, path), { force: true });
8041
+ removeEmptyDirs(dirname2(join4(skillDir, path)), skillDir);
8042
+ }
8043
+ function throughSymlink(skillDir, path) {
8044
+ let current = skillDir;
8045
+ for (const part of ["", ...path.split("/")]) {
8046
+ current = join4(current, part);
8047
+ try {
8048
+ if (lstatSync(current).isSymbolicLink()) return true;
8049
+ } catch (error) {
8050
+ return error.code !== "ENOENT";
8051
+ }
8052
+ }
8053
+ return false;
8054
+ }
8055
+ function planHost(host, owned, wanted, served) {
8056
+ const result = {
8057
+ dir: host.dir,
8058
+ skills: 0,
8059
+ written: 0,
8060
+ removed: 0,
8061
+ skipped: []
8062
+ };
8063
+ const names = /* @__PURE__ */ new Set();
8064
+ const needs = /* @__PURE__ */ new Map();
8065
+ for (const row of wanted) {
8066
+ const skillDir = join4(host.dir, row.name);
8067
+ if (!(row.name in owned) && existsSync2(skillDir)) {
8068
+ result.skipped.push(`${skillDir} (not installed by asteroid)`);
8069
+ continue;
8070
+ }
8071
+ names.add(row.name);
8072
+ result.skills++;
8073
+ const digests = served.get(row.name) ?? {};
8074
+ const stale = /* @__PURE__ */ new Set();
8075
+ for (const [path, digest] of Object.entries(digests)) {
8076
+ if (owned[row.name]?.[path] !== digest || !existsSync2(join4(skillDir, path)))
8077
+ stale.add(path);
8078
+ }
8079
+ if (stale.size > 0) needs.set(row.name, stale);
8080
+ }
8081
+ return { host, owned, names, needs, result };
8082
+ }
8083
+ async function inBatches(items, each) {
8084
+ for (let i = 0; i < items.length; i += CONCURRENCY) {
8085
+ await Promise.all(items.slice(i, i + CONCURRENCY).map(each));
8086
+ }
8087
+ }
8088
+ function applyHost(plan, served, fetched, options) {
8089
+ const { host, owned, names, needs, result } = plan;
8090
+ for (const name of names) {
8091
+ const skillDir = join4(host.dir, name);
8092
+ const digests = { ...served.get(name) };
8093
+ const stale = needs.get(name);
8094
+ const skill = fetched.get(name);
8095
+ const unwritten = /* @__PURE__ */ new Set();
8096
+ if (stale && skill) {
8097
+ for (const file of skill.files) {
8098
+ if (!stale.has(file.path)) continue;
8099
+ if (throughSymlink(skillDir, file.path)) {
8100
+ result.skipped.push(
8101
+ `${join4(skillDir, file.path)} (a symlink is in the way)`
8102
+ );
8103
+ unwritten.add(file.path);
8104
+ continue;
8105
+ }
8106
+ mkdirSync3(dirname2(join4(skillDir, file.path)), { recursive: true });
8107
+ writeFileSync2(join4(skillDir, file.path), file.content, "utf8");
8108
+ result.written++;
8109
+ }
8110
+ }
8111
+ for (const path of unwritten) delete digests[path];
8112
+ const previous = owned[name] ?? {};
8113
+ const kept = {};
8114
+ for (const path of Object.keys(previous)) {
8115
+ if (path in digests) continue;
8116
+ if (options.remove) {
8117
+ removeFile(skillDir, path);
8118
+ result.removed++;
8119
+ } else kept[path] = previous[path];
8120
+ }
8121
+ owned[name] = { ...kept, ...digests };
8122
+ }
8123
+ for (const name of Object.keys(owned)) {
8124
+ if (names.has(name) || !options.remove) continue;
8125
+ const skillDir = join4(host.dir, name);
8126
+ for (const path of Object.keys(owned[name])) {
8127
+ removeFile(skillDir, path);
8128
+ result.removed++;
8129
+ }
8130
+ delete owned[name];
8131
+ }
8132
+ }
8133
+ async function installSkills(deps, auth, hosts, options, rows) {
8134
+ rows ??= await listSkills(deps.env, auth, deps.fetch);
8135
+ const skipped = [];
8136
+ const wanted = wantedSkills(rows, skipped);
8137
+ const served = new Map(
8138
+ wanted.map((row) => [row.name, servedDigests(row, skipped)])
8139
+ );
8140
+ const state = loadSkillsState(deps.env);
8141
+ const plans = hosts.map(
8142
+ (host) => planHost(host, state.hosts[host.dir] ??= {}, wanted, served)
8143
+ );
8144
+ const toFetch = wanted.filter(
8145
+ (row) => plans.some((plan) => plan.needs.has(row.name))
8146
+ );
8147
+ const fetched = /* @__PURE__ */ new Map();
8148
+ await inBatches(toFetch, async (row) => {
8149
+ fetched.set(row.name, await getSkill(deps.env, auth, deps.fetch, row));
8150
+ });
8151
+ for (const plan of plans) applyHost(plan, served, fetched, options);
8152
+ saveSkillsState(deps.env, state);
8153
+ return {
8154
+ skills: wanted.length,
8155
+ skipped,
8156
+ hosts: plans.map((plan) => plan.result)
8157
+ };
8158
+ }
8159
+ function formatInstall(result) {
8160
+ const lines = result.hosts.map((host) => {
8161
+ const changes = [
8162
+ host.written > 0 ? `${host.written} files written` : "",
8163
+ host.removed > 0 ? `${host.removed} removed` : ""
8164
+ ].filter(Boolean);
8165
+ return `${host.dir}: ${host.skills} skills, ${changes.length > 0 ? changes.join(", ") : "up to date"}.`;
8166
+ });
8167
+ for (const line2 of [
8168
+ ...result.skipped,
8169
+ ...result.hosts.flatMap((host) => host.skipped)
8170
+ ])
8171
+ lines.push(`Skipped ${line2}.`);
8172
+ return lines.join("\n");
8173
+ }
8174
+ function staleSkills(state, hosts, rows) {
8175
+ const wanted = wantedSkills(rows, []);
8176
+ const served = new Map(
8177
+ wanted.map((row) => [row.name, servedDigests(row, [])])
8178
+ );
8179
+ const stale = /* @__PURE__ */ new Set();
8180
+ for (const host of hosts) {
8181
+ const owned = state.hosts[host.dir] ?? {};
8182
+ for (const [name, digests] of served) {
8183
+ const present = Object.keys(digests).every(
8184
+ (path) => existsSync2(join4(host.dir, name, path))
8185
+ );
8186
+ if (!present || !sameDigests(owned[name], digests)) stale.add(name);
8187
+ }
8188
+ for (const name of Object.keys(owned))
8189
+ if (!served.has(name)) stale.add(name);
8190
+ }
8191
+ return stale.size;
8192
+ }
8193
+ async function authFor(deps, flagOrg) {
8194
+ const config = loadConfig(deps.env);
8195
+ return resolveAuth(
8196
+ deps.env,
8197
+ config,
8198
+ requestedOrg(flagOrg, deps.env, deps.cwd, config),
8199
+ deps.fetch
8200
+ );
8201
+ }
8202
+ function noHosts(deps) {
8203
+ deps.stderr(
8204
+ "No skills directory found: none of ~/.claude, ~/.cursor or ~/.agents exists.\n"
8205
+ );
8206
+ }
8207
+ async function syncSkills(deps, flagOrg, options) {
8208
+ const auth = await authFor(deps, flagOrg);
8209
+ const hosts = detectHosts(deps.env.home);
8210
+ if (hosts.length === 0) {
8211
+ noHosts(deps);
8212
+ return 1;
8213
+ }
8214
+ const result = await installSkills(deps, auth, hosts, options);
8215
+ deps.stderr(`${formatInstall(result)}
8216
+ `);
8217
+ return 0;
8218
+ }
8219
+ async function offerSkills(deps) {
8220
+ const hosts = detectHosts(deps.env.home);
8221
+ if (hosts.length === 0) return noHosts(deps);
8222
+ try {
8223
+ const auth = await authFor(deps, void 0);
8224
+ const rows = await listSkills(deps.env, auth, deps.fetch);
8225
+ const count = wantedSkills(rows, []).length;
8226
+ if (count === 0) return;
8227
+ const label = `${count} Asteroid skill${count === 1 ? "" : "s"} for ${hostLabel(hosts)}`;
8228
+ if (!deps.ui) {
8229
+ deps.stderr(`${SYNC_HINT} to install ${label}.
8230
+ `);
8231
+ return;
8232
+ }
8233
+ const yes = await deps.ui.confirm(`Install ${label}?`, true);
8234
+ if (!yes) {
8235
+ deps.stderr(`Skipped. ${SYNC_HINT} to install them later.
8236
+ `);
8237
+ return;
8238
+ }
8239
+ const result = await installSkills(
8240
+ deps,
8241
+ auth,
8242
+ hosts,
8243
+ { remove: true },
8244
+ rows
8245
+ );
8246
+ deps.stderr(`${formatInstall(result)}
8247
+ `);
8248
+ } catch (error) {
8249
+ deps.stderr(
8250
+ `Could not install the Asteroid skills: ${clean(error instanceof Error ? error.message : String(error))}. ${SYNC_HINT} to retry.
8251
+ `
8252
+ );
8253
+ }
8254
+ }
8255
+ async function skillsNotice(deps, flagOrg) {
8256
+ try {
8257
+ const state = loadSkillsState(deps.env);
8258
+ if (Object.keys(state.hosts).length === 0) return;
8259
+ if (state.checkedAt && Date.now() - state.checkedAt < CHECK_INTERVAL_MS)
8260
+ return;
8261
+ saveSkillsState(deps.env, { ...state, checkedAt: Date.now() });
8262
+ const auth = await authFor(deps, flagOrg);
8263
+ const rows = await listSkills(deps.env, auth, deps.fetch);
8264
+ const stale = staleSkills(state, detectHosts(deps.env.home), rows);
8265
+ if (stale === 0) return;
8266
+ deps.stderr(
8267
+ `${stale} Asteroid skill${stale === 1 ? " is" : "s are"} out of date. ${SYNC_HINT}.
8268
+ `
8269
+ );
8270
+ } catch {
8271
+ return;
8272
+ }
8273
+ }
8274
+
7799
8275
  // src/account.ts
7800
8276
  async function chooseOrg(deps, orgs2) {
7801
8277
  if (orgs2.length === 0)
@@ -7809,7 +8285,7 @@ async function chooseOrg(deps, orgs2) {
7809
8285
  if (!chosen) throw new AuthError("sign-in cancelled");
7810
8286
  return chosen;
7811
8287
  }
7812
- async function login(deps) {
8288
+ async function login(deps, options = {}) {
7813
8289
  if (deps.env.apiKey)
7814
8290
  deps.stderr(
7815
8291
  `Warning: ${API_KEY_OVERRIDES} Every command will use the key, not this sign-in. ${UNSET_API_KEY}
@@ -7862,6 +8338,7 @@ and confirm the code ${clean(device.user_code)}
7862
8338
  `Signed in as ${clean(session2.email ?? "you")}${config.org ? ` in ${orgLabel(config.org)}` : ""}. Token saved to the ${where === "keychain" ? "OS keychain" : "config directory"}.
7863
8339
  `
7864
8340
  );
8341
+ if (options.skills !== false) await offerSkills(deps);
7865
8342
  return 0;
7866
8343
  }
7867
8344
  async function logout(deps) {
@@ -8493,104 +8970,6 @@ function formatActivitiesMarkdown(activities, status, createdAt) {
8493
8970
  return lines.join("\n");
8494
8971
  }
8495
8972
 
8496
- // ../workflow-files/src/representation/name-charset.ts
8497
- var NAME_CHARSET_RE = /^[A-Za-z0-9 !#$%&'()+,.;=@^`{}[\]~-]+$/;
8498
- var WINDOWS_RESERVED = /* @__PURE__ */ new Set([
8499
- "con",
8500
- "prn",
8501
- "aux",
8502
- "nul",
8503
- ...Array.from({ length: 9 }, (_, i) => `com${i + 1}`),
8504
- ...Array.from({ length: 9 }, (_, i) => `lpt${i + 1}`)
8505
- ]);
8506
- function isNameCharsetConforming(name) {
8507
- return NAME_CHARSET_RE.test(name);
8508
- }
8509
-
8510
- // ../workflow-files/src/representation/types.ts
8511
- function normalizeNodeName(name) {
8512
- let result = name.toLowerCase();
8513
- result = result.replace(/[^a-z0-9]+/g, "_");
8514
- result = result.replace(/^_+|_+$/g, "");
8515
- if (result.length > 80) {
8516
- result = result.slice(0, 80).replace(/_+$/, "");
8517
- }
8518
- if (result === "") {
8519
- throw new Error(
8520
- `representation: node name "${name}" produces an empty directory name after normalization`
8521
- );
8522
- }
8523
- return result;
8524
- }
8525
- function lossySlugOr(name, fallback) {
8526
- try {
8527
- return normalizeNodeName(name);
8528
- } catch {
8529
- return fallback;
8530
- }
8531
- }
8532
- function nodeDirName(name) {
8533
- if (isNameCharsetConforming(name)) {
8534
- return name.replaceAll(" ", "_");
8535
- }
8536
- return normalizeNodeName(name);
8537
- }
8538
- function agentDirName(name) {
8539
- try {
8540
- return nodeDirName(name);
8541
- } catch {
8542
- return "agent";
8543
- }
8544
- }
8545
- function executionDirName(executionId2) {
8546
- return executionId2.slice(0, 8);
8547
- }
8548
- function workflowDirName(workflowId, version, parentId, parentVersion) {
8549
- const short = workflowId.slice(0, 8);
8550
- if (version !== void 0 && version !== null) {
8551
- return `v${version}_${short}`;
8552
- }
8553
- if (parentId) {
8554
- if (parentVersion !== void 0 && parentVersion !== null) {
8555
- return `draft_${short}_from_v${parentVersion}`;
8556
- }
8557
- return `draft_${short}_from_draft_${parentId.slice(0, 8)}`;
8558
- }
8559
- return `draft_${short}`;
8560
- }
8561
-
8562
- // src/sync/paths.ts
8563
- import { createHash } from "node:crypto";
8564
- function join3(...parts) {
8565
- return parts.filter((part) => part !== "").join("/").replace(/\/{2,}/g, "/");
8566
- }
8567
- function workflowRoot(root, workflowName) {
8568
- return join3(root, agentDirName(workflowName));
8569
- }
8570
- function isContained(path) {
8571
- if (path === "" || path.startsWith("/") || path.includes("\\")) return false;
8572
- return path.split("/").every((segment) => segment !== ".." && segment !== "");
8573
- }
8574
- function sha256(bytes) {
8575
- return createHash("sha256").update(bytes).digest("hex");
8576
- }
8577
- function matchesGlob(path, pattern) {
8578
- let source = "";
8579
- for (let i = 0; i < pattern.length; i++) {
8580
- const ch = pattern[i];
8581
- if (ch === "*" && pattern[i + 1] === "*" && pattern[i + 2] === "/") {
8582
- source += "(?:.*/)?";
8583
- i += 2;
8584
- } else if (ch === "*" && pattern[i + 1] === "*") {
8585
- source += ".*";
8586
- i += 1;
8587
- } else if (ch === "*") source += "[^/]*";
8588
- else if (ch === "?") source += "[^/]";
8589
- else source += ch.replace(/[.+^${}()|[\]\\]/g, "\\$&");
8590
- }
8591
- return new RegExp(`^${source}$`).test(path);
8592
- }
8593
-
8594
8973
  // src/sync/execution-pull.ts
8595
8974
  var DIRECTORIES = ["workspace", "downloads", "shared"];
8596
8975
  function relativeFilePath(file) {
@@ -8873,7 +9252,7 @@ function formatInsightPull(result) {
8873
9252
 
8874
9253
  // src/sync/node-files.ts
8875
9254
  import { mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises";
8876
- import { dirname as dirname2, relative, resolve, sep } from "node:path";
9255
+ import { dirname as dirname3, relative, resolve, sep } from "node:path";
8877
9256
  function missing(error) {
8878
9257
  return error.code === "ENOENT";
8879
9258
  }
@@ -8897,7 +9276,7 @@ function nodeFiles(cwd) {
8897
9276
  }
8898
9277
  },
8899
9278
  async write(path, bytes) {
8900
- await mkdir(dirname2(at(path)), { recursive: true });
9279
+ await mkdir(dirname3(at(path)), { recursive: true });
8901
9280
  await writeFile(at(path), bytes);
8902
9281
  },
8903
9282
  async remove(path) {
@@ -8928,7 +9307,7 @@ async function writeManifest(sync, dir, manifest) {
8928
9307
  }
8929
9308
 
8930
9309
  // src/sync/workflow-pull.ts
8931
- var CONCURRENCY = 16;
9310
+ var CONCURRENCY2 = 16;
8932
9311
  function pullDir(root, tree, head) {
8933
9312
  const base = workflowRoot(root, tree.workflowName);
8934
9313
  if (head) return join3(base, "head");
@@ -8966,10 +9345,10 @@ function wantedEntries(options, tree, skipped) {
8966
9345
  return false;
8967
9346
  });
8968
9347
  }
8969
- async function inBatches(items, each) {
8970
- for (let i = 0; i < items.length; i += CONCURRENCY) {
9348
+ async function inBatches2(items, each) {
9349
+ for (let i = 0; i < items.length; i += CONCURRENCY2) {
8971
9350
  const results = await Promise.allSettled(
8972
- items.slice(i, i + CONCURRENCY).map(each)
9351
+ items.slice(i, i + CONCURRENCY2).map(each)
8973
9352
  );
8974
9353
  const failed = results.find((r) => r.status === "rejected");
8975
9354
  if (failed) throw failed.reason;
@@ -8980,7 +9359,7 @@ async function writeEntries(sync, options, tree, dir) {
8980
9359
  const skipped = [];
8981
9360
  let shared = 0;
8982
9361
  let written = 0;
8983
- await inBatches(wantedEntries(options, tree, skipped), async (entry) => {
9362
+ await inBatches2(wantedEntries(options, tree, skipped), async (entry) => {
8984
9363
  const bytes = await entryBytes(sync, options.workflowId, tree, entry);
8985
9364
  if (!bytes) return void skipped.push(`${entry.path} (no content)`);
8986
9365
  await sync.files.write(join3(dir, entry.path), bytes);
@@ -9030,7 +9409,7 @@ async function mergeEntries(sync, options, tree, dir, previous) {
9030
9409
  written: 0
9031
9410
  };
9032
9411
  const wanted = wantedEntries(options, tree, out.skipped);
9033
- await inBatches(
9412
+ await inBatches2(
9034
9413
  wanted,
9035
9414
  (entry) => mergeEntry(sync, options, tree, dir, previous, entry, out)
9036
9415
  );
@@ -9440,7 +9819,9 @@ async function runBuiltin(name, parsed, deps) {
9440
9819
  rejectOrgWithApiKey(deps, parsed.org);
9441
9820
  switch (name) {
9442
9821
  case "login":
9443
- return login(deps);
9822
+ return login(deps, {
9823
+ skills: parsed.flags.get("skills")?.[0] !== "false"
9824
+ });
9444
9825
  case "logout":
9445
9826
  return logout(deps);
9446
9827
  case "orgs":
@@ -9454,6 +9835,10 @@ async function runBuiltin(name, parsed, deps) {
9454
9835
  reason: parsed.flags.get("reason")?.[0],
9455
9836
  exit: parsed.flags.has("exit")
9456
9837
  });
9838
+ case "skill sync":
9839
+ return syncSkills(deps, parsed.org, {
9840
+ remove: parsed.flags.get("remove")?.[0] !== "false"
9841
+ });
9457
9842
  default:
9458
9843
  return whoami(deps, parsed.org, parsed.json);
9459
9844
  }
@@ -9469,7 +9854,7 @@ async function credentialOrganization(deps, auth) {
9469
9854
  );
9470
9855
  return response.json?.organizationId;
9471
9856
  }
9472
- async function authFor(parsed, deps) {
9857
+ async function authFor2(parsed, deps) {
9473
9858
  rejectOrgWithApiKey(deps, parsed.org);
9474
9859
  const config = loadConfig(deps.env);
9475
9860
  return resolveAuth(
@@ -9489,7 +9874,7 @@ function announce(command, auth, deps) {
9489
9874
  async function runCommand(command, parsed, deps) {
9490
9875
  const needsOrganization = command.body?.credentialOrganization === true;
9491
9876
  let request = needsOrganization ? void 0 : await buildRequest(command, parsed);
9492
- const auth = await authFor(parsed, deps);
9877
+ const auth = await authFor2(parsed, deps);
9493
9878
  request ??= await buildRequest(command, parsed, {
9494
9879
  organizationId: await credentialOrganization(deps, auth)
9495
9880
  });
@@ -9503,7 +9888,7 @@ async function runCommand(command, parsed, deps) {
9503
9888
  );
9504
9889
  if (response.bytes) {
9505
9890
  if (parsed.output) {
9506
- writeFileSync2(parsed.output, response.bytes);
9891
+ writeFileSync3(parsed.output, response.bytes);
9507
9892
  deps.stderr(
9508
9893
  `Wrote ${response.bytes.length} bytes to ${parsed.output}.
9509
9894
  `
@@ -9545,9 +9930,35 @@ function nodeRemote(apiUrl, auth, fetchImpl) {
9545
9930
  };
9546
9931
  }
9547
9932
  var DESCRIPTION = "The Asteroid CLI. Sign in with `asteroid login`, or set ASTEROID_API_KEY.\nAt a terminal, tables show up to 6 columns and cut long cells to fit; when output is piped, they show every column in full. Use `--json` for every field.";
9933
+ var NO_NOTICE = /* @__PURE__ */ new Set(["login", "logout", "complete", "skill sync"]);
9934
+ function noticeApplies(invocation, deps) {
9935
+ if (!deps.ui || deps.env.apiKey || invocation.parsed.json) return false;
9936
+ return invocation.kind === "command" || !NO_NOTICE.has(invocation.name);
9937
+ }
9938
+ async function execute2(invocation, deps) {
9939
+ if (invocation.kind === "exit") {
9940
+ if (invocation.stdout) deps.stdout(invocation.stdout);
9941
+ if (invocation.stderr) deps.stderr(invocation.stderr);
9942
+ return invocation.code;
9943
+ }
9944
+ if (invocation.kind === "builtin") {
9945
+ return runBuiltin(invocation.name, invocation.parsed, deps);
9946
+ }
9947
+ if (runsLocally(invocation.command, invocation.parsed)) {
9948
+ const auth = await authFor2(invocation.parsed, deps);
9949
+ announce(invocation.command, auth, deps);
9950
+ return runSync(invocation.command, invocation.parsed, {
9951
+ ...deps,
9952
+ remote: nodeRemote(deps.env.apiUrl, auth, deps.fetch)
9953
+ });
9954
+ }
9955
+ return runCommand(invocation.command, invocation.parsed, deps);
9956
+ }
9548
9957
  async function run(argv2, deps) {
9958
+ let invocation;
9959
+ let code2;
9549
9960
  try {
9550
- const invocation = await parseInvocation(argv2, {
9961
+ invocation = await parseInvocation(argv2, {
9551
9962
  commands: ALL_COMMANDS,
9552
9963
  builtins: BUILTINS,
9553
9964
  version: VERSION,
@@ -9555,41 +9966,25 @@ async function run(argv2, deps) {
9555
9966
  defaultArg: (command, arg) => command.files === "push" && arg.name === "workflowId" ? "" : void 0,
9556
9967
  defaultArgNote: "<workflow-id> defaults to the workflow the pushed folder was pulled from."
9557
9968
  });
9558
- if (invocation.kind === "exit") {
9559
- if (invocation.stdout) deps.stdout(invocation.stdout);
9560
- if (invocation.stderr) deps.stderr(invocation.stderr);
9561
- return invocation.code;
9562
- }
9563
- if (invocation.kind === "builtin") {
9564
- return await runBuiltin(invocation.name, invocation.parsed, deps);
9565
- }
9566
- if (runsLocally(invocation.command, invocation.parsed)) {
9567
- const auth = await authFor(invocation.parsed, deps);
9568
- announce(invocation.command, auth, deps);
9569
- return await runSync(invocation.command, invocation.parsed, {
9570
- ...deps,
9571
- remote: nodeRemote(deps.env.apiUrl, auth, deps.fetch)
9572
- });
9573
- }
9574
- return await runCommand(invocation.command, invocation.parsed, deps);
9969
+ code2 = await execute2(invocation, deps);
9575
9970
  } catch (error) {
9576
9971
  if (error instanceof UsageError) {
9577
9972
  deps.stderr(`asteroid: ${clean(error.message)}
9578
9973
  `);
9579
- return 2;
9580
- }
9581
- if (error instanceof ApiError) {
9974
+ code2 = 2;
9975
+ } else if (error instanceof ApiError) {
9582
9976
  deps.stderr(`asteroid: ${error.status}: ${clean(error.message)}
9583
9977
  `);
9584
- return 1;
9585
- }
9586
- if (error instanceof AuthError || error instanceof WorkosError) {
9978
+ code2 = 1;
9979
+ } else if (error instanceof AuthError || error instanceof WorkosError) {
9587
9980
  deps.stderr(`asteroid: ${clean(error.message)}
9588
9981
  `);
9589
- return 1;
9590
- }
9591
- throw error;
9982
+ code2 = 1;
9983
+ } else throw error;
9592
9984
  }
9985
+ if (invocation && invocation.kind !== "exit" && noticeApplies(invocation, deps))
9986
+ await skillsNotice(deps, invocation.parsed.org);
9987
+ return code2;
9593
9988
  }
9594
9989
 
9595
9990
  // src/ui.ts
@@ -9603,6 +9998,10 @@ var clackUi = {
9603
9998
  const value2 = await clack.text({ message });
9604
9999
  return clack.isCancel(value2) ? void 0 : value2;
9605
10000
  },
10001
+ async confirm(message, initial) {
10002
+ const value2 = await clack.confirm({ message, initialValue: initial });
10003
+ return clack.isCancel(value2) ? void 0 : value2;
10004
+ },
9606
10005
  async wait(message, done, work) {
9607
10006
  const spinner2 = clack.spinner();
9608
10007
  spinner2.start(message);
package/dist/core.js CHANGED
@@ -4326,7 +4326,7 @@ var COMMANDS = [
4326
4326
  command: "skill get",
4327
4327
  tool: "skill_get",
4328
4328
  title: "Get skill",
4329
- description: "Get one skill with the content of every file, SKILL.md first, in the Agent Skills format. A name resolves to the public skill, then a portal's, then the organization's; set `kind` to pick one. A portal skill needs its portal added with `portal_skills_add`. Pass `surface` `mcp` to spell the platform's commands as MCP tools.",
4329
+ description: "Get one skill with the content of every file, SKILL.md first, in the Agent Skills format. A large skill can exceed your result limit: pass `paths` to fetch only some files, such as `SKILL.md` first and then the reference files it names. A link like `../workflow-reference/references/nodes.md` is file `references/nodes.md` of skill `workflow-reference`. `skills_list` gives every file's path and size. A name resolves to the public skill, then a portal's, then the organization's; set `kind` to pick one. A portal skill needs its portal added with `portal_skills_add`. Pass `surface` `mcp` to spell the platform's commands as MCP tools.",
4330
4330
  method: "GET",
4331
4331
  path: "/astro/v2/skills/{name}",
4332
4332
  args: [
@@ -4338,6 +4338,13 @@ var COMMANDS = [
4338
4338
  }
4339
4339
  ],
4340
4340
  query: [
4341
+ {
4342
+ name: "paths",
4343
+ flag: "paths",
4344
+ type: "string[]",
4345
+ required: false,
4346
+ description: "Return only the files at these skill-relative paths, such as `SKILL.md` or `references/nodes.md`. A path that names no file yields no entry."
4347
+ },
4341
4348
  {
4342
4349
  name: "kind",
4343
4350
  flag: "kind",
@@ -6689,8 +6696,9 @@ var BUILTINS = [
6689
6696
  {
6690
6697
  command: "login",
6691
6698
  usage: "asteroid login",
6692
- description: "Sign in with your browser. Stores a refresh token in the OS keychain, or in a private file in the config directory when no keychain is available.",
6693
- args: 0
6699
+ description: "Sign in with your browser. Stores a refresh token in the OS keychain, or in a private file in the config directory when no keychain is available. Then offers to install the Asteroid skills into every skills directory it finds: `~/.claude/skills` (Claude Code), `~/.cursor/skills` (Cursor) and `~/.agents/skills`.",
6700
+ args: 0,
6701
+ options: [["--no-skills", "Do not offer to install the Asteroid skills."]]
6694
6702
  },
6695
6703
  {
6696
6704
  command: "logout",
@@ -6733,6 +6741,16 @@ var BUILTINS = [
6733
6741
  usage: "asteroid whoami",
6734
6742
  description: "Show who you act as, in which organization, and how long the token lasts.",
6735
6743
  args: 0
6744
+ },
6745
+ {
6746
+ command: "skill sync",
6747
+ usage: "asteroid skill sync",
6748
+ description: "Install the Asteroid skills, or bring them up to date, in every skills directory found: `~/.claude/skills`, `~/.cursor/skills` and `~/.agents/skills`. Writes the files that changed, removes the skills the API no longer serves, and leaves a skill directory it did not create alone.",
6749
+ args: 0,
6750
+ options: [
6751
+ ["--no-remove", "Keep the skills and files the API no longer serves."]
6752
+ ],
6753
+ section: "Skills"
6736
6754
  }
6737
6755
  ];
6738
6756
  var BUILTIN_COMMANDS = new Set(BUILTINS.map((b) => b.command));
@@ -6876,9 +6894,16 @@ function defineCommands(root, options, dotted2 = /* @__PURE__ */ new Map(), onIn
6876
6894
  for (const [flags, text2] of GLOBAL_FLAGS) {
6877
6895
  if (!flags.startsWith("-h")) root.option(flags, text2);
6878
6896
  }
6897
+ const groups = /* @__PURE__ */ new Map();
6879
6898
  for (const builtin of options.builtins ?? []) {
6880
- const leaf = root.command(builtin.command).description(builtin.description);
6899
+ const words = builtin.command.split(" ");
6900
+ let parent = root;
6901
+ for (let i = 0; i < words.length - 1; i++) {
6902
+ parent = group(parent, words[i], groups, words.slice(0, i + 1).join(" "));
6903
+ }
6904
+ const leaf = parent.command(words.at(-1)).description(builtin.description);
6881
6905
  if (builtin.arg) leaf.argument(`[${builtin.arg}]`);
6906
+ for (const [flags, text2] of builtin.options ?? []) leaf.option(flags, text2);
6882
6907
  for (const [flags, text2] of builtin.hiddenOptions ?? [])
6883
6908
  leaf.addOption(new Flag(flags, text2).hideHelp());
6884
6909
  leaf.action((...args) => {
@@ -6891,7 +6916,6 @@ function defineCommands(root, options, dotted2 = /* @__PURE__ */ new Map(), onIn
6891
6916
  });
6892
6917
  }
6893
6918
  const reserved = new Set((options.builtins ?? []).map((b) => b.command));
6894
- const groups = /* @__PURE__ */ new Map();
6895
6919
  for (const command of options.commands) {
6896
6920
  if (reserved.has(command.command)) continue;
6897
6921
  const words = command.command.split(" ");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asteroidai/cli",
3
- "version": "1.9.181",
3
+ "version": "1.9.185",
4
4
  "description": "The asteroid command-line interface for the Asteroid platform.",
5
5
  "type": "module",
6
6
  "license": "MIT",