@asteroidai/cli 1.9.369 → 1.9.373
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 +247 -309
- package/dist/core.js +5 -39
- package/package.json +1 -1
package/dist/asteroid.js
CHANGED
|
@@ -4627,7 +4627,7 @@ var COMMANDS = [
|
|
|
4627
4627
|
command: "skill sync",
|
|
4628
4628
|
tool: "skill_sync",
|
|
4629
4629
|
title: "Sync skills",
|
|
4630
|
-
description: "Get the latest Asteroid skills for the portals your organization has added: how to build Asteroid workflows on each portal.
|
|
4630
|
+
description: "Get the latest Asteroid skills for the portals your organization has added: how to build Asteroid workflows on each portal.",
|
|
4631
4631
|
method: "POST",
|
|
4632
4632
|
path: "/astro/v2/skills",
|
|
4633
4633
|
args: [],
|
|
@@ -4643,22 +4643,7 @@ var COMMANDS = [
|
|
|
4643
4643
|
],
|
|
4644
4644
|
binary: false,
|
|
4645
4645
|
readOnly: false,
|
|
4646
|
-
destructive: false
|
|
4647
|
-
body: {
|
|
4648
|
-
required: false,
|
|
4649
|
-
contentType: "application/json",
|
|
4650
|
-
fields: [
|
|
4651
|
-
{
|
|
4652
|
-
name: "learnings",
|
|
4653
|
-
flag: "learnings",
|
|
4654
|
-
type: "json",
|
|
4655
|
-
required: false,
|
|
4656
|
-
description: "Up to 10 things you found out about portals. Leave it out to sync only."
|
|
4657
|
-
}
|
|
4658
|
-
],
|
|
4659
|
-
files: [],
|
|
4660
|
-
credentialOrganization: false
|
|
4661
|
-
}
|
|
4646
|
+
destructive: false
|
|
4662
4647
|
},
|
|
4663
4648
|
{
|
|
4664
4649
|
command: "tag create",
|
|
@@ -6973,18 +6958,7 @@ function withSyncCommands(commands) {
|
|
|
6973
6958
|
(a, b) => a.command.localeCompare(b.command)
|
|
6974
6959
|
);
|
|
6975
6960
|
}
|
|
6976
|
-
var
|
|
6977
|
-
name: "learnings",
|
|
6978
|
-
flag: "learning",
|
|
6979
|
-
type: "json[]",
|
|
6980
|
-
required: false,
|
|
6981
|
-
description: 'What you found out about a portal, as JSON: `{"portal":"<name>","content":"<text>"}`. Add `portalId` if you have one. Repeat for more.'
|
|
6982
|
-
};
|
|
6983
|
-
function withLearningFlag(command) {
|
|
6984
|
-
if (command.tool !== "skill_sync" || !command.body) return command;
|
|
6985
|
-
return { ...command, body: { ...command.body, fields: [LEARNING] } };
|
|
6986
|
-
}
|
|
6987
|
-
var ALL_COMMANDS = withSyncCommands(COMMANDS).map(withLearningFlag);
|
|
6961
|
+
var ALL_COMMANDS = withSyncCommands(COMMANDS);
|
|
6988
6962
|
|
|
6989
6963
|
// src/config.ts
|
|
6990
6964
|
import envPaths from "env-paths";
|
|
@@ -7269,18 +7243,12 @@ var BUILTINS = [
|
|
|
7269
7243
|
},
|
|
7270
7244
|
{
|
|
7271
7245
|
command: "skill sync",
|
|
7272
|
-
usage: "asteroid skill sync
|
|
7273
|
-
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. Do not edit an installed skill, because the next sync overwrites it. If a skill is missing something about how a portal works,
|
|
7246
|
+
usage: "asteroid skill sync",
|
|
7247
|
+
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. Do not edit an installed skill, because the next sync overwrites it. If a skill is missing something about how a portal works, save it with `asteroid memory create`.",
|
|
7274
7248
|
args: 0,
|
|
7275
7249
|
options: [
|
|
7276
7250
|
["--no-remove", "Keep the skills and files the API no longer serves."]
|
|
7277
7251
|
],
|
|
7278
|
-
repeatableOptions: [
|
|
7279
|
-
[
|
|
7280
|
-
"--learning <json>",
|
|
7281
|
-
'Optional. Something the portal\'s skill is missing about how the portal works, as JSON: `{"portal":"<name>","content":"<text>"}`. Add `portalId` if you have one. Repeat for more. Send this instead of editing the skill, because the next sync overwrites local edits. Send general knowledge of the portal only.'
|
|
7282
|
-
]
|
|
7283
|
-
],
|
|
7284
7252
|
section: "Skills"
|
|
7285
7253
|
}
|
|
7286
7254
|
];
|
|
@@ -7435,8 +7403,6 @@ function defineCommands(root, options, dotted2 = /* @__PURE__ */ new Map(), onIn
|
|
|
7435
7403
|
const leaf = parent.command(words.at(-1)).description(builtin.description);
|
|
7436
7404
|
if (builtin.arg) leaf.argument(`[${builtin.arg}]`);
|
|
7437
7405
|
for (const [flags, text3] of builtin.options ?? []) leaf.option(flags, text3);
|
|
7438
|
-
for (const [flags, text3] of builtin.repeatableOptions ?? [])
|
|
7439
|
-
leaf.option(flags, text3, collect);
|
|
7440
7406
|
for (const [flags, text3] of builtin.hiddenOptions ?? [])
|
|
7441
7407
|
leaf.addOption(new Flag(flags, text3).hideHelp());
|
|
7442
7408
|
leaf.action((...args) => {
|
|
@@ -8015,7 +7981,7 @@ var ApiError = class extends Error {
|
|
|
8015
7981
|
status;
|
|
8016
7982
|
body;
|
|
8017
7983
|
};
|
|
8018
|
-
var VERSION = "1.9.
|
|
7984
|
+
var VERSION = "1.9.373";
|
|
8019
7985
|
function problem(status, body, fallback) {
|
|
8020
7986
|
if (body && typeof body === "object") {
|
|
8021
7987
|
const record2 = body;
|
|
@@ -8108,246 +8074,13 @@ import {
|
|
|
8108
8074
|
lstatSync,
|
|
8109
8075
|
mkdirSync as mkdirSync3,
|
|
8110
8076
|
readdirSync,
|
|
8111
|
-
readFileSync as
|
|
8077
|
+
readFileSync as readFileSync2,
|
|
8112
8078
|
rmdirSync,
|
|
8113
8079
|
rmSync as rmSync2,
|
|
8114
8080
|
writeFileSync as writeFileSync2
|
|
8115
8081
|
} from "node:fs";
|
|
8116
8082
|
import { dirname as dirname2, join as join4 } from "node:path";
|
|
8117
8083
|
|
|
8118
|
-
// src/request.ts
|
|
8119
|
-
import { readFileSync as readFileSync2 } from "node:fs";
|
|
8120
|
-
import { basename } from "node:path";
|
|
8121
|
-
function camel(segment) {
|
|
8122
|
-
return segment.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
8123
|
-
}
|
|
8124
|
-
function scalar(option2, raw) {
|
|
8125
|
-
const type = option2.type.replace("[]", "");
|
|
8126
|
-
if (option2.enum && !option2.enum.includes(raw)) {
|
|
8127
|
-
throw new UsageError(
|
|
8128
|
-
`--${option2.flag} must be one of ${option2.enum.join(", ")}`
|
|
8129
|
-
);
|
|
8130
|
-
}
|
|
8131
|
-
if (type === "integer" || type === "number") {
|
|
8132
|
-
const value2 = Number(raw);
|
|
8133
|
-
if (raw.trim() === "" || Number.isNaN(value2) || type === "integer" && !Number.isInteger(value2)) {
|
|
8134
|
-
throw new UsageError(
|
|
8135
|
-
`--${option2.flag} must be ${type === "integer" ? "an integer" : "a number"}`
|
|
8136
|
-
);
|
|
8137
|
-
}
|
|
8138
|
-
return value2;
|
|
8139
|
-
}
|
|
8140
|
-
if (type === "boolean") {
|
|
8141
|
-
if (raw !== "true" && raw !== "false") {
|
|
8142
|
-
throw new UsageError(`--${option2.flag} must be true or false`);
|
|
8143
|
-
}
|
|
8144
|
-
return raw === "true";
|
|
8145
|
-
}
|
|
8146
|
-
if (type === "json") return parseJson(raw, `--${option2.flag}`);
|
|
8147
|
-
return raw;
|
|
8148
|
-
}
|
|
8149
|
-
function value(option2, raws) {
|
|
8150
|
-
if (option2.type.endsWith("[]")) return raws.map((raw) => scalar(option2, raw));
|
|
8151
|
-
return scalar(option2, raws.at(-1));
|
|
8152
|
-
}
|
|
8153
|
-
var nodeReader = {
|
|
8154
|
-
text: async (path) => readFileSync2(path, "utf8"),
|
|
8155
|
-
bytes: async (path) => new Uint8Array(readFileSync2(path))
|
|
8156
|
-
};
|
|
8157
|
-
async function readInput(raw, io) {
|
|
8158
|
-
if (raw === "-") return io.text(0);
|
|
8159
|
-
if (raw.startsWith("@")) return io.text(raw.slice(1));
|
|
8160
|
-
return raw;
|
|
8161
|
-
}
|
|
8162
|
-
async function resolveInputs(command, parsed, io) {
|
|
8163
|
-
const jsonFlags = [...command.query, ...command.body?.fields ?? []].filter((option2) => option2.type === "json" || option2.type === "json[]").map((option2) => option2.flag);
|
|
8164
|
-
const flags = new Map(parsed.flags);
|
|
8165
|
-
for (const flag2 of jsonFlags) {
|
|
8166
|
-
const raws = flags.get(flag2);
|
|
8167
|
-
if (raws)
|
|
8168
|
-
flags.set(flag2, await Promise.all(raws.map((raw) => readInput(raw, io))));
|
|
8169
|
-
}
|
|
8170
|
-
const body = parsed.body === void 0 ? void 0 : await readInput(parsed.body, io);
|
|
8171
|
-
return { ...parsed, flags, body };
|
|
8172
|
-
}
|
|
8173
|
-
function parseJson(raw, label) {
|
|
8174
|
-
try {
|
|
8175
|
-
return JSON.parse(raw);
|
|
8176
|
-
} catch {
|
|
8177
|
-
throw new UsageError(`${label} is not valid JSON`);
|
|
8178
|
-
}
|
|
8179
|
-
}
|
|
8180
|
-
function loose(raw) {
|
|
8181
|
-
if (/^(true|false|null)$/.test(raw) || /^[[{]/.test(raw.trim())) {
|
|
8182
|
-
try {
|
|
8183
|
-
return JSON.parse(raw);
|
|
8184
|
-
} catch {
|
|
8185
|
-
return raw;
|
|
8186
|
-
}
|
|
8187
|
-
}
|
|
8188
|
-
return raw;
|
|
8189
|
-
}
|
|
8190
|
-
function setPath(target, path, value2) {
|
|
8191
|
-
let node = target;
|
|
8192
|
-
for (const key of path.slice(0, -1)) {
|
|
8193
|
-
const next = node[key];
|
|
8194
|
-
if (typeof next !== "object" || next === null || Array.isArray(next))
|
|
8195
|
-
node[key] = {};
|
|
8196
|
-
node = node[key];
|
|
8197
|
-
}
|
|
8198
|
-
node[path.at(-1)] = value2;
|
|
8199
|
-
}
|
|
8200
|
-
async function dotted(field, segments, flag2, raws, io) {
|
|
8201
|
-
const path = [];
|
|
8202
|
-
let option2 = field;
|
|
8203
|
-
for (const [i, segment] of segments.entries()) {
|
|
8204
|
-
if (option2?.record) {
|
|
8205
|
-
const key = segments.slice(i).join(".");
|
|
8206
|
-
const entry = { ...option2, flag: flag2, type: option2.record };
|
|
8207
|
-
delete entry.enum;
|
|
8208
|
-
return [
|
|
8209
|
-
[...path, key],
|
|
8210
|
-
entry.type === "json" ? loose(raws.at(-1)) : value(entry, raws)
|
|
8211
|
-
];
|
|
8212
|
-
}
|
|
8213
|
-
if (option2?.fields) {
|
|
8214
|
-
const child = option2.fields.find(
|
|
8215
|
-
(f) => f.flag === segment
|
|
8216
|
-
);
|
|
8217
|
-
if (!child) throw new UsageError(`unknown flag: --${flag2}`);
|
|
8218
|
-
path.push(child.name);
|
|
8219
|
-
option2 = child;
|
|
8220
|
-
continue;
|
|
8221
|
-
}
|
|
8222
|
-
if (option2 && option2.type !== "json") {
|
|
8223
|
-
throw new UsageError(`unknown flag: --${flag2}`);
|
|
8224
|
-
}
|
|
8225
|
-
path.push(camel(segment));
|
|
8226
|
-
option2 = void 0;
|
|
8227
|
-
}
|
|
8228
|
-
if (!option2) return [path, loose(raws.at(-1))];
|
|
8229
|
-
if (option2.fields || option2.record) {
|
|
8230
|
-
throw new UsageError(`--${flag2} needs a field, as --${flag2}.<name>`);
|
|
8231
|
-
}
|
|
8232
|
-
const inputs = option2.type === "json" ? await Promise.all(raws.map((raw) => readInput(raw, io))) : raws;
|
|
8233
|
-
return [path, value({ ...option2, flag: flag2 }, inputs)];
|
|
8234
|
-
}
|
|
8235
|
-
async function buildRequest(command, input, context = {}) {
|
|
8236
|
-
const io = context.io ?? nodeReader;
|
|
8237
|
-
const parsed = await resolveInputs(command, input, io);
|
|
8238
|
-
if (parsed.positionals.length !== command.args.length) {
|
|
8239
|
-
const expected = command.args.map((a) => `<${a.flag}>`).join(" ") || "no arguments";
|
|
8240
|
-
throw new UsageError(
|
|
8241
|
-
`expected ${expected}, got ${parsed.positionals.length} argument(s)`
|
|
8242
|
-
);
|
|
8243
|
-
}
|
|
8244
|
-
let path = command.path;
|
|
8245
|
-
command.args.forEach((arg, i) => {
|
|
8246
|
-
path = path.replace(
|
|
8247
|
-
`{${arg.name}}`,
|
|
8248
|
-
encodeURIComponent(parsed.positionals[i])
|
|
8249
|
-
);
|
|
8250
|
-
});
|
|
8251
|
-
const flags = new Map(parsed.flags);
|
|
8252
|
-
const query = new URLSearchParams();
|
|
8253
|
-
for (const option2 of command.query) {
|
|
8254
|
-
const raws = flags.get(option2.flag);
|
|
8255
|
-
flags.delete(option2.flag);
|
|
8256
|
-
if (!raws) {
|
|
8257
|
-
if (option2.required) throw new UsageError(`--${option2.flag} is required`);
|
|
8258
|
-
continue;
|
|
8259
|
-
}
|
|
8260
|
-
const parsedValue = value(option2, raws);
|
|
8261
|
-
const values = Array.isArray(parsedValue) ? parsedValue : [parsedValue];
|
|
8262
|
-
if (option2.explode === false)
|
|
8263
|
-
query.append(option2.name, values.map(String).join(","));
|
|
8264
|
-
else for (const v of values) query.append(option2.name, String(v));
|
|
8265
|
-
}
|
|
8266
|
-
const built = { method: command.method, path, query };
|
|
8267
|
-
const body = command.body;
|
|
8268
|
-
if (!body) {
|
|
8269
|
-
if (parsed.body) throw new UsageError(`${command.command} takes no body`);
|
|
8270
|
-
rejectUnknown(flags);
|
|
8271
|
-
return built;
|
|
8272
|
-
}
|
|
8273
|
-
if (body.contentType === "multipart/form-data") {
|
|
8274
|
-
if (parsed.body) {
|
|
8275
|
-
throw new UsageError(
|
|
8276
|
-
`${command.command} uploads files; use the file flags, not --body`
|
|
8277
|
-
);
|
|
8278
|
-
}
|
|
8279
|
-
const form = new FormData();
|
|
8280
|
-
for (const file of body.files) {
|
|
8281
|
-
const paths = flags.get(file) ?? [];
|
|
8282
|
-
if (body.required && paths.length === 0) {
|
|
8283
|
-
throw new UsageError(`--${file} is required`);
|
|
8284
|
-
}
|
|
8285
|
-
for (const filePath of paths) {
|
|
8286
|
-
form.append(
|
|
8287
|
-
file,
|
|
8288
|
-
new Blob([await io.bytes(filePath)]),
|
|
8289
|
-
basename(filePath)
|
|
8290
|
-
);
|
|
8291
|
-
}
|
|
8292
|
-
flags.delete(file);
|
|
8293
|
-
}
|
|
8294
|
-
for (const field of body.fields) {
|
|
8295
|
-
const raws = flags.get(field.flag);
|
|
8296
|
-
flags.delete(field.flag);
|
|
8297
|
-
if (raws) for (const raw of raws) form.append(field.name, raw);
|
|
8298
|
-
}
|
|
8299
|
-
rejectUnknown(flags);
|
|
8300
|
-
built.form = form;
|
|
8301
|
-
return built;
|
|
8302
|
-
}
|
|
8303
|
-
const base = parsed.body ? parseJson(parsed.body, "--body") : {};
|
|
8304
|
-
if (typeof base !== "object" || base === null || Array.isArray(base)) {
|
|
8305
|
-
throw new UsageError("--body must be a JSON object");
|
|
8306
|
-
}
|
|
8307
|
-
const json = base;
|
|
8308
|
-
for (const field of body.fields) {
|
|
8309
|
-
const raws = flags.get(field.flag);
|
|
8310
|
-
if (!raws) continue;
|
|
8311
|
-
flags.delete(field.flag);
|
|
8312
|
-
json[field.name] = value(field, raws);
|
|
8313
|
-
}
|
|
8314
|
-
for (const [flag2, raws] of [...flags]) {
|
|
8315
|
-
const [head, ...rest] = flag2.split(".");
|
|
8316
|
-
const field = body.fields.find((f) => f.flag === head);
|
|
8317
|
-
if (!field || rest.length === 0) continue;
|
|
8318
|
-
flags.delete(flag2);
|
|
8319
|
-
const current = json[field.name];
|
|
8320
|
-
json[field.name] = typeof current === "object" && current !== null ? current : {};
|
|
8321
|
-
const [path2, value2] = await dotted(field, rest, flag2, raws, io);
|
|
8322
|
-
setPath(json, [field.name, ...path2], value2);
|
|
8323
|
-
}
|
|
8324
|
-
rejectUnknown(flags);
|
|
8325
|
-
delete json.organizationId;
|
|
8326
|
-
if (body.credentialOrganization) {
|
|
8327
|
-
if (!context.organizationId) {
|
|
8328
|
-
throw new UsageError(
|
|
8329
|
-
"could not tell which organization this credential acts in"
|
|
8330
|
-
);
|
|
8331
|
-
}
|
|
8332
|
-
json.organizationId = context.organizationId;
|
|
8333
|
-
}
|
|
8334
|
-
for (const field of body.fields) {
|
|
8335
|
-
if (field.required && json[field.name] === void 0) {
|
|
8336
|
-
throw new UsageError(`--${field.flag} is required`);
|
|
8337
|
-
}
|
|
8338
|
-
}
|
|
8339
|
-
if (body.required || Object.keys(json).length > 0) built.json = json;
|
|
8340
|
-
return built;
|
|
8341
|
-
}
|
|
8342
|
-
function rejectUnknown(flags) {
|
|
8343
|
-
const unknown = [...flags.keys()];
|
|
8344
|
-
if (unknown.length > 0) {
|
|
8345
|
-
throw new UsageError(
|
|
8346
|
-
`unknown flag${unknown.length > 1 ? "s" : ""}: ${unknown.map((f) => `--${f}`).join(", ")}`
|
|
8347
|
-
);
|
|
8348
|
-
}
|
|
8349
|
-
}
|
|
8350
|
-
|
|
8351
8084
|
// ../workflow-files/src/representation/name-charset.ts
|
|
8352
8085
|
var NAME_CHARSET_RE = /^[A-Za-z0-9 !#$%&'()+,.;=@^`{}[\]~-]+$/;
|
|
8353
8086
|
var WINDOWS_RESERVED = /* @__PURE__ */ new Set([
|
|
@@ -8560,7 +8293,7 @@ function matchesLocal(skillDir, path, digest) {
|
|
|
8560
8293
|
if (!existsSync2(file)) return false;
|
|
8561
8294
|
if (throughSymlink(skillDir, path) || !lstatSync(file).isFile())
|
|
8562
8295
|
return true;
|
|
8563
|
-
const local2 = createHash2("sha256").update(
|
|
8296
|
+
const local2 = createHash2("sha256").update(readFileSync2(file)).digest("hex");
|
|
8564
8297
|
return digest === `sha256:${local2}`;
|
|
8565
8298
|
} catch {
|
|
8566
8299
|
return false;
|
|
@@ -8739,43 +8472,17 @@ function noHosts(deps) {
|
|
|
8739
8472
|
"No skills directory found: none of ~/.claude, ~/.cursor or ~/.agents exists.\n"
|
|
8740
8473
|
);
|
|
8741
8474
|
}
|
|
8742
|
-
async function sendLearnings(deps, auth, learnings) {
|
|
8743
|
-
const command = ALL_COMMANDS.find((c) => c.tool === "skill_sync");
|
|
8744
|
-
if (!command) throw new Error("skill_sync is missing from the command table");
|
|
8745
|
-
const request = await buildRequest(command, {
|
|
8746
|
-
positionals: [],
|
|
8747
|
-
flags: /* @__PURE__ */ new Map([["learning", learnings]]),
|
|
8748
|
-
json: false
|
|
8749
|
-
});
|
|
8750
|
-
await send(deps.env.apiUrl, auth, request, false, deps.fetch);
|
|
8751
|
-
const noun = learnings.length === 1 ? "learning" : "learnings";
|
|
8752
|
-
deps.stderr(`Sent ${learnings.length} ${noun}.
|
|
8753
|
-
`);
|
|
8754
|
-
}
|
|
8755
8475
|
async function syncSkills(deps, flagOrg, options) {
|
|
8756
8476
|
const auth = await authFor(deps, flagOrg);
|
|
8757
|
-
const sent = options.learnings.length > 0;
|
|
8758
|
-
if (sent) await sendLearnings(deps, auth, options.learnings);
|
|
8759
8477
|
const hosts = detectHosts(deps.env.home);
|
|
8760
8478
|
if (hosts.length === 0) {
|
|
8761
8479
|
noHosts(deps);
|
|
8762
|
-
return
|
|
8480
|
+
return 1;
|
|
8763
8481
|
}
|
|
8764
|
-
|
|
8765
|
-
|
|
8766
|
-
remove: options.remove && !sent
|
|
8767
|
-
});
|
|
8768
|
-
deps.stderr(`${formatInstall(result)}
|
|
8482
|
+
const result = await installSkills(deps, auth, hosts, options);
|
|
8483
|
+
deps.stderr(`${formatInstall(result)}
|
|
8769
8484
|
`);
|
|
8770
|
-
|
|
8771
|
-
} catch (error) {
|
|
8772
|
-
if (!sent) throw error;
|
|
8773
|
-
deps.stderr(
|
|
8774
|
-
`The skills did not update: ${clean(error.message)}. ${SYNC_HINT} to retry.
|
|
8775
|
-
`
|
|
8776
|
-
);
|
|
8777
|
-
return 0;
|
|
8778
|
-
}
|
|
8485
|
+
return 0;
|
|
8779
8486
|
}
|
|
8780
8487
|
async function offerSkills(deps) {
|
|
8781
8488
|
const hosts = detectHosts(deps.env.home);
|
|
@@ -9226,6 +8933,239 @@ async function whoami(deps, flagOrg, json) {
|
|
|
9226
8933
|
return 0;
|
|
9227
8934
|
}
|
|
9228
8935
|
|
|
8936
|
+
// src/request.ts
|
|
8937
|
+
import { readFileSync as readFileSync3 } from "node:fs";
|
|
8938
|
+
import { basename } from "node:path";
|
|
8939
|
+
function camel(segment) {
|
|
8940
|
+
return segment.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
8941
|
+
}
|
|
8942
|
+
function scalar(option2, raw) {
|
|
8943
|
+
const type = option2.type.replace("[]", "");
|
|
8944
|
+
if (option2.enum && !option2.enum.includes(raw)) {
|
|
8945
|
+
throw new UsageError(
|
|
8946
|
+
`--${option2.flag} must be one of ${option2.enum.join(", ")}`
|
|
8947
|
+
);
|
|
8948
|
+
}
|
|
8949
|
+
if (type === "integer" || type === "number") {
|
|
8950
|
+
const value2 = Number(raw);
|
|
8951
|
+
if (raw.trim() === "" || Number.isNaN(value2) || type === "integer" && !Number.isInteger(value2)) {
|
|
8952
|
+
throw new UsageError(
|
|
8953
|
+
`--${option2.flag} must be ${type === "integer" ? "an integer" : "a number"}`
|
|
8954
|
+
);
|
|
8955
|
+
}
|
|
8956
|
+
return value2;
|
|
8957
|
+
}
|
|
8958
|
+
if (type === "boolean") {
|
|
8959
|
+
if (raw !== "true" && raw !== "false") {
|
|
8960
|
+
throw new UsageError(`--${option2.flag} must be true or false`);
|
|
8961
|
+
}
|
|
8962
|
+
return raw === "true";
|
|
8963
|
+
}
|
|
8964
|
+
if (type === "json") return parseJson(raw, `--${option2.flag}`);
|
|
8965
|
+
return raw;
|
|
8966
|
+
}
|
|
8967
|
+
function value(option2, raws) {
|
|
8968
|
+
if (option2.type.endsWith("[]")) return raws.map((raw) => scalar(option2, raw));
|
|
8969
|
+
return scalar(option2, raws.at(-1));
|
|
8970
|
+
}
|
|
8971
|
+
var nodeReader = {
|
|
8972
|
+
text: async (path) => readFileSync3(path, "utf8"),
|
|
8973
|
+
bytes: async (path) => new Uint8Array(readFileSync3(path))
|
|
8974
|
+
};
|
|
8975
|
+
async function readInput(raw, io) {
|
|
8976
|
+
if (raw === "-") return io.text(0);
|
|
8977
|
+
if (raw.startsWith("@")) return io.text(raw.slice(1));
|
|
8978
|
+
return raw;
|
|
8979
|
+
}
|
|
8980
|
+
async function resolveInputs(command, parsed, io) {
|
|
8981
|
+
const jsonFlags = [...command.query, ...command.body?.fields ?? []].filter((option2) => option2.type === "json" || option2.type === "json[]").map((option2) => option2.flag);
|
|
8982
|
+
const flags = new Map(parsed.flags);
|
|
8983
|
+
for (const flag2 of jsonFlags) {
|
|
8984
|
+
const raws = flags.get(flag2);
|
|
8985
|
+
if (raws)
|
|
8986
|
+
flags.set(flag2, await Promise.all(raws.map((raw) => readInput(raw, io))));
|
|
8987
|
+
}
|
|
8988
|
+
const body = parsed.body === void 0 ? void 0 : await readInput(parsed.body, io);
|
|
8989
|
+
return { ...parsed, flags, body };
|
|
8990
|
+
}
|
|
8991
|
+
function parseJson(raw, label) {
|
|
8992
|
+
try {
|
|
8993
|
+
return JSON.parse(raw);
|
|
8994
|
+
} catch {
|
|
8995
|
+
throw new UsageError(`${label} is not valid JSON`);
|
|
8996
|
+
}
|
|
8997
|
+
}
|
|
8998
|
+
function loose(raw) {
|
|
8999
|
+
if (/^(true|false|null)$/.test(raw) || /^[[{]/.test(raw.trim())) {
|
|
9000
|
+
try {
|
|
9001
|
+
return JSON.parse(raw);
|
|
9002
|
+
} catch {
|
|
9003
|
+
return raw;
|
|
9004
|
+
}
|
|
9005
|
+
}
|
|
9006
|
+
return raw;
|
|
9007
|
+
}
|
|
9008
|
+
function setPath(target, path, value2) {
|
|
9009
|
+
let node = target;
|
|
9010
|
+
for (const key of path.slice(0, -1)) {
|
|
9011
|
+
const next = node[key];
|
|
9012
|
+
if (typeof next !== "object" || next === null || Array.isArray(next))
|
|
9013
|
+
node[key] = {};
|
|
9014
|
+
node = node[key];
|
|
9015
|
+
}
|
|
9016
|
+
node[path.at(-1)] = value2;
|
|
9017
|
+
}
|
|
9018
|
+
async function dotted(field, segments, flag2, raws, io) {
|
|
9019
|
+
const path = [];
|
|
9020
|
+
let option2 = field;
|
|
9021
|
+
for (const [i, segment] of segments.entries()) {
|
|
9022
|
+
if (option2?.record) {
|
|
9023
|
+
const key = segments.slice(i).join(".");
|
|
9024
|
+
const entry = { ...option2, flag: flag2, type: option2.record };
|
|
9025
|
+
delete entry.enum;
|
|
9026
|
+
return [
|
|
9027
|
+
[...path, key],
|
|
9028
|
+
entry.type === "json" ? loose(raws.at(-1)) : value(entry, raws)
|
|
9029
|
+
];
|
|
9030
|
+
}
|
|
9031
|
+
if (option2?.fields) {
|
|
9032
|
+
const child = option2.fields.find(
|
|
9033
|
+
(f) => f.flag === segment
|
|
9034
|
+
);
|
|
9035
|
+
if (!child) throw new UsageError(`unknown flag: --${flag2}`);
|
|
9036
|
+
path.push(child.name);
|
|
9037
|
+
option2 = child;
|
|
9038
|
+
continue;
|
|
9039
|
+
}
|
|
9040
|
+
if (option2 && option2.type !== "json") {
|
|
9041
|
+
throw new UsageError(`unknown flag: --${flag2}`);
|
|
9042
|
+
}
|
|
9043
|
+
path.push(camel(segment));
|
|
9044
|
+
option2 = void 0;
|
|
9045
|
+
}
|
|
9046
|
+
if (!option2) return [path, loose(raws.at(-1))];
|
|
9047
|
+
if (option2.fields || option2.record) {
|
|
9048
|
+
throw new UsageError(`--${flag2} needs a field, as --${flag2}.<name>`);
|
|
9049
|
+
}
|
|
9050
|
+
const inputs = option2.type === "json" ? await Promise.all(raws.map((raw) => readInput(raw, io))) : raws;
|
|
9051
|
+
return [path, value({ ...option2, flag: flag2 }, inputs)];
|
|
9052
|
+
}
|
|
9053
|
+
async function buildRequest(command, input, context = {}) {
|
|
9054
|
+
const io = context.io ?? nodeReader;
|
|
9055
|
+
const parsed = await resolveInputs(command, input, io);
|
|
9056
|
+
if (parsed.positionals.length !== command.args.length) {
|
|
9057
|
+
const expected = command.args.map((a) => `<${a.flag}>`).join(" ") || "no arguments";
|
|
9058
|
+
throw new UsageError(
|
|
9059
|
+
`expected ${expected}, got ${parsed.positionals.length} argument(s)`
|
|
9060
|
+
);
|
|
9061
|
+
}
|
|
9062
|
+
let path = command.path;
|
|
9063
|
+
command.args.forEach((arg, i) => {
|
|
9064
|
+
path = path.replace(
|
|
9065
|
+
`{${arg.name}}`,
|
|
9066
|
+
encodeURIComponent(parsed.positionals[i])
|
|
9067
|
+
);
|
|
9068
|
+
});
|
|
9069
|
+
const flags = new Map(parsed.flags);
|
|
9070
|
+
const query = new URLSearchParams();
|
|
9071
|
+
for (const option2 of command.query) {
|
|
9072
|
+
const raws = flags.get(option2.flag);
|
|
9073
|
+
flags.delete(option2.flag);
|
|
9074
|
+
if (!raws) {
|
|
9075
|
+
if (option2.required) throw new UsageError(`--${option2.flag} is required`);
|
|
9076
|
+
continue;
|
|
9077
|
+
}
|
|
9078
|
+
const parsedValue = value(option2, raws);
|
|
9079
|
+
const values = Array.isArray(parsedValue) ? parsedValue : [parsedValue];
|
|
9080
|
+
if (option2.explode === false)
|
|
9081
|
+
query.append(option2.name, values.map(String).join(","));
|
|
9082
|
+
else for (const v of values) query.append(option2.name, String(v));
|
|
9083
|
+
}
|
|
9084
|
+
const built = { method: command.method, path, query };
|
|
9085
|
+
const body = command.body;
|
|
9086
|
+
if (!body) {
|
|
9087
|
+
if (parsed.body) throw new UsageError(`${command.command} takes no body`);
|
|
9088
|
+
rejectUnknown(flags);
|
|
9089
|
+
return built;
|
|
9090
|
+
}
|
|
9091
|
+
if (body.contentType === "multipart/form-data") {
|
|
9092
|
+
if (parsed.body) {
|
|
9093
|
+
throw new UsageError(
|
|
9094
|
+
`${command.command} uploads files; use the file flags, not --body`
|
|
9095
|
+
);
|
|
9096
|
+
}
|
|
9097
|
+
const form = new FormData();
|
|
9098
|
+
for (const file of body.files) {
|
|
9099
|
+
const paths = flags.get(file) ?? [];
|
|
9100
|
+
if (body.required && paths.length === 0) {
|
|
9101
|
+
throw new UsageError(`--${file} is required`);
|
|
9102
|
+
}
|
|
9103
|
+
for (const filePath of paths) {
|
|
9104
|
+
form.append(
|
|
9105
|
+
file,
|
|
9106
|
+
new Blob([await io.bytes(filePath)]),
|
|
9107
|
+
basename(filePath)
|
|
9108
|
+
);
|
|
9109
|
+
}
|
|
9110
|
+
flags.delete(file);
|
|
9111
|
+
}
|
|
9112
|
+
for (const field of body.fields) {
|
|
9113
|
+
const raws = flags.get(field.flag);
|
|
9114
|
+
flags.delete(field.flag);
|
|
9115
|
+
if (raws) for (const raw of raws) form.append(field.name, raw);
|
|
9116
|
+
}
|
|
9117
|
+
rejectUnknown(flags);
|
|
9118
|
+
built.form = form;
|
|
9119
|
+
return built;
|
|
9120
|
+
}
|
|
9121
|
+
const base = parsed.body ? parseJson(parsed.body, "--body") : {};
|
|
9122
|
+
if (typeof base !== "object" || base === null || Array.isArray(base)) {
|
|
9123
|
+
throw new UsageError("--body must be a JSON object");
|
|
9124
|
+
}
|
|
9125
|
+
const json = base;
|
|
9126
|
+
for (const field of body.fields) {
|
|
9127
|
+
const raws = flags.get(field.flag);
|
|
9128
|
+
if (!raws) continue;
|
|
9129
|
+
flags.delete(field.flag);
|
|
9130
|
+
json[field.name] = value(field, raws);
|
|
9131
|
+
}
|
|
9132
|
+
for (const [flag2, raws] of [...flags]) {
|
|
9133
|
+
const [head, ...rest] = flag2.split(".");
|
|
9134
|
+
const field = body.fields.find((f) => f.flag === head);
|
|
9135
|
+
if (!field || rest.length === 0) continue;
|
|
9136
|
+
flags.delete(flag2);
|
|
9137
|
+
const current = json[field.name];
|
|
9138
|
+
json[field.name] = typeof current === "object" && current !== null ? current : {};
|
|
9139
|
+
const [path2, value2] = await dotted(field, rest, flag2, raws, io);
|
|
9140
|
+
setPath(json, [field.name, ...path2], value2);
|
|
9141
|
+
}
|
|
9142
|
+
rejectUnknown(flags);
|
|
9143
|
+
delete json.organizationId;
|
|
9144
|
+
if (body.credentialOrganization) {
|
|
9145
|
+
if (!context.organizationId) {
|
|
9146
|
+
throw new UsageError(
|
|
9147
|
+
"could not tell which organization this credential acts in"
|
|
9148
|
+
);
|
|
9149
|
+
}
|
|
9150
|
+
json.organizationId = context.organizationId;
|
|
9151
|
+
}
|
|
9152
|
+
for (const field of body.fields) {
|
|
9153
|
+
if (field.required && json[field.name] === void 0) {
|
|
9154
|
+
throw new UsageError(`--${field.flag} is required`);
|
|
9155
|
+
}
|
|
9156
|
+
}
|
|
9157
|
+
if (body.required || Object.keys(json).length > 0) built.json = json;
|
|
9158
|
+
return built;
|
|
9159
|
+
}
|
|
9160
|
+
function rejectUnknown(flags) {
|
|
9161
|
+
const unknown = [...flags.keys()];
|
|
9162
|
+
if (unknown.length > 0) {
|
|
9163
|
+
throw new UsageError(
|
|
9164
|
+
`unknown flag${unknown.length > 1 ? "s" : ""}: ${unknown.map((f) => `--${f}`).join(", ")}`
|
|
9165
|
+
);
|
|
9166
|
+
}
|
|
9167
|
+
}
|
|
9168
|
+
|
|
9229
9169
|
// src/sync/activities.ts
|
|
9230
9170
|
function indentJson(data) {
|
|
9231
9171
|
return JSON.stringify(data, null, 2).split("\n").map((line2) => ` ${line2}`).join("\n");
|
|
@@ -10222,11 +10162,9 @@ async function runBuiltin(name, parsed, deps) {
|
|
|
10222
10162
|
exit: parsed.flags.has("exit")
|
|
10223
10163
|
});
|
|
10224
10164
|
case "skill sync":
|
|
10225
|
-
if (parsed.body)
|
|
10226
|
-
throw new UsageError("skill sync takes --learning, not --body");
|
|
10165
|
+
if (parsed.body) throw new UsageError("skill sync takes no --body");
|
|
10227
10166
|
return syncSkills(deps, parsed.org, {
|
|
10228
|
-
remove: parsed.flags.get("remove")?.[0] !== "false"
|
|
10229
|
-
learnings: parsed.flags.get("learning") ?? []
|
|
10167
|
+
remove: parsed.flags.get("remove")?.[0] !== "false"
|
|
10230
10168
|
});
|
|
10231
10169
|
default:
|
|
10232
10170
|
return whoami(deps, parsed.org, parsed.json);
|
package/dist/core.js
CHANGED
|
@@ -4648,7 +4648,7 @@ var COMMANDS = [
|
|
|
4648
4648
|
command: "skill sync",
|
|
4649
4649
|
tool: "skill_sync",
|
|
4650
4650
|
title: "Sync skills",
|
|
4651
|
-
description: "Get the latest Asteroid skills for the portals your organization has added: how to build Asteroid workflows on each portal.
|
|
4651
|
+
description: "Get the latest Asteroid skills for the portals your organization has added: how to build Asteroid workflows on each portal.",
|
|
4652
4652
|
method: "POST",
|
|
4653
4653
|
path: "/astro/v2/skills",
|
|
4654
4654
|
args: [],
|
|
@@ -4664,22 +4664,7 @@ var COMMANDS = [
|
|
|
4664
4664
|
],
|
|
4665
4665
|
binary: false,
|
|
4666
4666
|
readOnly: false,
|
|
4667
|
-
destructive: false
|
|
4668
|
-
body: {
|
|
4669
|
-
required: false,
|
|
4670
|
-
contentType: "application/json",
|
|
4671
|
-
fields: [
|
|
4672
|
-
{
|
|
4673
|
-
name: "learnings",
|
|
4674
|
-
flag: "learnings",
|
|
4675
|
-
type: "json",
|
|
4676
|
-
required: false,
|
|
4677
|
-
description: "Up to 10 things you found out about portals. Leave it out to sync only."
|
|
4678
|
-
}
|
|
4679
|
-
],
|
|
4680
|
-
files: [],
|
|
4681
|
-
credentialOrganization: false
|
|
4682
|
-
}
|
|
4667
|
+
destructive: false
|
|
4683
4668
|
},
|
|
4684
4669
|
{
|
|
4685
4670
|
command: "tag create",
|
|
@@ -7023,18 +7008,12 @@ var BUILTINS = [
|
|
|
7023
7008
|
},
|
|
7024
7009
|
{
|
|
7025
7010
|
command: "skill sync",
|
|
7026
|
-
usage: "asteroid skill sync
|
|
7027
|
-
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. Do not edit an installed skill, because the next sync overwrites it. If a skill is missing something about how a portal works,
|
|
7011
|
+
usage: "asteroid skill sync",
|
|
7012
|
+
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. Do not edit an installed skill, because the next sync overwrites it. If a skill is missing something about how a portal works, save it with `asteroid memory create`.",
|
|
7028
7013
|
args: 0,
|
|
7029
7014
|
options: [
|
|
7030
7015
|
["--no-remove", "Keep the skills and files the API no longer serves."]
|
|
7031
7016
|
],
|
|
7032
|
-
repeatableOptions: [
|
|
7033
|
-
[
|
|
7034
|
-
"--learning <json>",
|
|
7035
|
-
'Optional. Something the portal\'s skill is missing about how the portal works, as JSON: `{"portal":"<name>","content":"<text>"}`. Add `portalId` if you have one. Repeat for more. Send this instead of editing the skill, because the next sync overwrites local edits. Send general knowledge of the portal only.'
|
|
7036
|
-
]
|
|
7037
|
-
],
|
|
7038
7017
|
section: "Skills"
|
|
7039
7018
|
}
|
|
7040
7019
|
];
|
|
@@ -7189,8 +7168,6 @@ function defineCommands(root, options, dotted2 = /* @__PURE__ */ new Map(), onIn
|
|
|
7189
7168
|
const leaf = parent.command(words.at(-1)).description(builtin.description);
|
|
7190
7169
|
if (builtin.arg) leaf.argument(`[${builtin.arg}]`);
|
|
7191
7170
|
for (const [flags, text2] of builtin.options ?? []) leaf.option(flags, text2);
|
|
7192
|
-
for (const [flags, text2] of builtin.repeatableOptions ?? [])
|
|
7193
|
-
leaf.option(flags, text2, collect);
|
|
7194
7171
|
for (const [flags, text2] of builtin.hiddenOptions ?? [])
|
|
7195
7172
|
leaf.addOption(new Flag(flags, text2).hideHelp());
|
|
7196
7173
|
leaf.action((...args) => {
|
|
@@ -7709,18 +7686,7 @@ function withSyncCommands(commands) {
|
|
|
7709
7686
|
(a, b) => a.command.localeCompare(b.command)
|
|
7710
7687
|
);
|
|
7711
7688
|
}
|
|
7712
|
-
var
|
|
7713
|
-
name: "learnings",
|
|
7714
|
-
flag: "learning",
|
|
7715
|
-
type: "json[]",
|
|
7716
|
-
required: false,
|
|
7717
|
-
description: 'What you found out about a portal, as JSON: `{"portal":"<name>","content":"<text>"}`. Add `portalId` if you have one. Repeat for more.'
|
|
7718
|
-
};
|
|
7719
|
-
function withLearningFlag(command) {
|
|
7720
|
-
if (command.tool !== "skill_sync" || !command.body) return command;
|
|
7721
|
-
return { ...command, body: { ...command.body, fields: [LEARNING] } };
|
|
7722
|
-
}
|
|
7723
|
-
var ALL_COMMANDS = withSyncCommands(COMMANDS).map(withLearningFlag);
|
|
7689
|
+
var ALL_COMMANDS = withSyncCommands(COMMANDS);
|
|
7724
7690
|
|
|
7725
7691
|
// src/sync/activities.ts
|
|
7726
7692
|
function indentJson(data) {
|