@mostra/cli 0.13.0 → 0.15.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.
- package/dist/bin.js +2 -2
- package/dist/{bootstrap-3_Tdfdg7.js → bootstrap-CYgyuZFk.js} +8 -4
- package/dist/bootstrap-CYgyuZFk.js.map +1 -0
- package/dist/bootstrap-DHnt5zU_.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/reference/cli.md +147 -5
- package/dist/reference/diagnostics.json +234 -0
- package/dist/reference/errors/MOSTRA_LICENSE_ACCEPT_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_LICENSE_MISMATCH.md +23 -0
- package/dist/reference/errors/MOSTRA_LICENSE_UNACCEPTED.md +23 -0
- package/dist/reference/errors/MOSTRA_LICENSE_UNDECLARED.md +23 -0
- package/dist/reference/errors/MOSTRA_PACK_ADDRESS_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_PACK_CSS_UNIMPORTED.md +23 -0
- package/dist/reference/errors/MOSTRA_PACK_FETCH_FAILED.md +23 -0
- package/dist/reference/errors/MOSTRA_PACK_FILE_EXISTS.md +23 -0
- package/dist/reference/errors/MOSTRA_PACK_ITEM_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_PACK_ITEM_NOT_FOUND.md +23 -0
- package/dist/reference/errors/MOSTRA_PACK_NOT_APPLIED.md +23 -0
- package/dist/reference/errors/MOSTRA_PACK_OFFLINE.md +23 -0
- package/dist/reference/errors/MOSTRA_PACK_TARGET_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_PLUGIN_CONFLICT.md +23 -0
- package/dist/reference/errors/MOSTRA_PLUGIN_CONTRACT_UNSUPPORTED.md +23 -0
- package/dist/reference/errors/MOSTRA_PLUGIN_ENTRY_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_PLUGIN_EXPORTER_UNKNOWN.md +23 -0
- package/dist/reference/errors/MOSTRA_PLUGIN_FAILED.md +23 -0
- package/dist/reference/errors/MOSTRA_PLUGIN_MANIFEST_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_PLUGIN_MANIFEST_WARNING.md +23 -0
- package/dist/reference/errors/MOSTRA_PLUGIN_NOT_A_PLUGIN.md +23 -0
- package/dist/reference/errors/MOSTRA_PLUGIN_NOT_INSTALLED.md +23 -0
- package/dist/reference/errors/MOSTRA_PLUGIN_OPTIONS_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_PLUGIN_PLATFORM_UNSUPPORTED.md +23 -0
- package/dist/reference/errors/MOSTRA_PLUGIN_SCOPE_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_PLUGIN_SHADOWED.md +23 -0
- package/dist/reference/self-hosting.md +1 -0
- package/dist/{run-CtR0PFMj.js → run-BsUzIBQj.js} +437 -29
- package/dist/run-BsUzIBQj.js.map +1 -0
- package/dist/run-c8U3GkBy.js +1 -0
- package/dist/skill/SKILL.md +4 -2
- package/dist/skill/assets/examples/dashboard/styles.css +27 -9
- package/dist/skill/assets/examples/decision/styles.css +27 -9
- package/dist/skill/assets/examples/inbox/styles.css +27 -9
- package/dist/skill/assets/studio.css +27 -9
- package/dist/skill/references/mcp.md +2 -2
- package/dist/skill/references/plugins.md +51 -0
- package/package.json +7 -5
- package/src/command.ts +2 -0
- package/src/commands/authoring.ts +129 -18
- package/src/commands/index.ts +14 -3
- package/src/commands/plugins.ts +219 -0
- package/src/exit.ts +7 -0
- package/src/plugin-commands.ts +170 -0
- package/src/run.ts +64 -4
- package/dist/bootstrap-3_Tdfdg7.js.map +0 -1
- package/dist/bootstrap-C9a2gSWf.js +0 -1
- package/dist/run-CtR0PFMj.js.map +0 -1
- package/dist/run-NWeQcyh9.js +0 -1
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { a as GLOBAL_FLAGS, c as
|
|
1
|
+
import { a as GLOBAL_FLAGS, c as globalFlags, d as usage, f as EXIT, h as defineCommand, l as parseCommandLine, m as commandName, o as commandWords, p as exitCodeFor, r as progressReporter, s as durationMs, u as topWords } from "./bootstrap-CYgyuZFk.js";
|
|
2
2
|
import { _ as packageRoot, a as detachedEnvironment, c as durationBucket, d as mcpSessionFields, f as buildEndpoint, g as fromSource, h as cliVersion, i as detachedDirectory, l as minute, m as truthy, n as startFlusher, o as TelemetryEvent, p as decide, r as TelemetryStore, s as catalogCodes, u as detectHarness } from "./flush-TPaIdwjy.js";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, readlinkSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { isAbsolute, join, resolve, win32 } from "node:path";
|
|
6
|
-
import { ARTIFACT_PROGRESS, CLI_CLIENT_NAME, DEFAULT_DOCS_BASE, DEV_NOTIFY, FieldOp, HOST_PROTOCOL_REVISIONS, LineSplitter, MutationId, RESULTS_LIST_MAX, RespondentSpec, RpcError, RpcPeer, artifactCreateMethod, artifactExportMethod, artifactGetMethod, artifactImportMethod, artifactListMethod, artifactPauseMethod, artifactPublishMethod, artifactVerifyMethod, createDiagnostic, depsAddMethod, devStartMethod, devStopMethod, diagnosticCatalog, encodeLine, gcRunMethod, instanceCheckMethod, instanceStatusMethod, livePushMethod, mostraInitializeMethod, mostraShutdownMethod, remoteLinkMethod, remoteLoginMethod, remoteLoginWaitMethod, remoteLogoutMethod, resultsGetMethod, resultsListMethod, rosterAddMethod, rosterGetMethod, rosterRemoveMethod, secretDeleteMethod, secretListMethod, secretSetMethod, shareListMethod, shareStartMethod, shareStopMethod, stateGetMethod, statePatchMethod, viewDefaultMethod, viewLaunchMethod, viewRevokeMethod, viewRotateMethod, viewUrlMethod, waitMethod } from "@mostra/protocol";
|
|
6
|
+
import { ARTIFACT_PROGRESS, CLI_CLIENT_NAME, DEFAULT_DOCS_BASE, DEV_NOTIFY, FieldOp, HOST_PROTOCOL_REVISIONS, LineSplitter, MutationId, RESULTS_LIST_MAX, RespondentSpec, RpcError, RpcPeer, artifactCreateMethod, artifactExportMethod, artifactGetMethod, artifactImportMethod, artifactListMethod, artifactPauseMethod, artifactPublishMethod, artifactVerifyMethod, createDiagnostic, depsAddMethod, devStartMethod, devStopMethod, diagnosticCatalog, encodeLine, gcRunMethod, hostMethods, instanceCheckMethod, instanceStatusMethod, livePushMethod, mostraInitializeMethod, mostraShutdownMethod, packAddMethod, pluginAddMethod, pluginCommandsMethod, pluginExportMethod, pluginListMethod, pluginRemoveMethod, pluginValidateMethod, remoteLinkMethod, remoteLoginMethod, remoteLoginWaitMethod, remoteLogoutMethod, resultsGetMethod, resultsListMethod, rosterAddMethod, rosterGetMethod, rosterRemoveMethod, secretDeleteMethod, secretListMethod, secretSetMethod, shareListMethod, shareStartMethod, shareStopMethod, stateGetMethod, statePatchMethod, viewDefaultMethod, viewLaunchMethod, viewRevokeMethod, viewRotateMethod, viewUrlMethod, waitMethod } from "@mostra/protocol";
|
|
7
7
|
import { checkBrowser, checkFiles, connectControl, enclosingBundle, readBundle, readSetup, resolveRuntime } from "@mostra/sdk";
|
|
8
8
|
import { MCP_GUIDE_LINKS, MCP_PATH, createHttpEndpoint, createMcpServerFactory, defaultWorkspaceRoot, docsIndex, fileDocs, indexMarkdown, localWorkspace, nearestTopics, topicMarkdown } from "@mostra/mcp";
|
|
9
|
+
import { pathToFileURL } from "node:url";
|
|
9
10
|
import { homedir, tmpdir } from "node:os";
|
|
10
11
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
12
|
+
import { readFile } from "node:fs/promises";
|
|
13
|
+
import { packVariables, parsePackAddress, stampServed } from "@mostra/protocol/plugin";
|
|
11
14
|
import { isIP } from "node:net";
|
|
12
15
|
import { serve } from "@hono/node-server";
|
|
13
16
|
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
@@ -2212,10 +2215,15 @@ const exportCommand = defineCommand({
|
|
|
2212
2215
|
{
|
|
2213
2216
|
name: "as",
|
|
2214
2217
|
kind: "string",
|
|
2215
|
-
value: "<
|
|
2216
|
-
choices: ["bundle"],
|
|
2218
|
+
value: "<exporter>",
|
|
2217
2219
|
default: "bundle",
|
|
2218
|
-
summary: "What to write: `bundle`, the version's builds, manifest, lockfile and source."
|
|
2220
|
+
summary: "What to write: `bundle`, the version's builds, manifest, lockfile and source; or the ID of an exporter a plugin of the artifact or the home contributes."
|
|
2221
|
+
},
|
|
2222
|
+
{
|
|
2223
|
+
name: "option",
|
|
2224
|
+
kind: "list",
|
|
2225
|
+
value: "<name=value>",
|
|
2226
|
+
summary: "An option for a plugin's exporter; its value is read as JSON when it parses."
|
|
2219
2227
|
},
|
|
2220
2228
|
{
|
|
2221
2229
|
name: "out",
|
|
@@ -2240,6 +2248,8 @@ const exportCommand = defineCommand({
|
|
|
2240
2248
|
const out = flag(context, "out");
|
|
2241
2249
|
if (out === void 0) throw usage("\"mostra export\" needs --out <path>.");
|
|
2242
2250
|
const version = flag(context, "version");
|
|
2251
|
+
const as = flag(context, "as") ?? "bundle";
|
|
2252
|
+
if (as !== "bundle") return exportWithPlugin(context, as, out, version);
|
|
2243
2253
|
const result = await context.call(artifactExportMethod, {
|
|
2244
2254
|
artifact: artifactRef(arg(context, "artifact"), context.cwd),
|
|
2245
2255
|
as: "bundle",
|
|
@@ -2252,8 +2262,37 @@ const exportCommand = defineCommand({
|
|
|
2252
2262
|
};
|
|
2253
2263
|
}
|
|
2254
2264
|
});
|
|
2265
|
+
/** `export --as <id>` with an exporter a plugin contributes (`plugin/export`). */
|
|
2266
|
+
async function exportWithPlugin(context, exporter, out, version) {
|
|
2267
|
+
const options = {};
|
|
2268
|
+
for (const pair of Array.isArray(context.flags["option"]) ? context.flags["option"] : []) {
|
|
2269
|
+
const at = pair.indexOf("=");
|
|
2270
|
+
if (at <= 0) throw usage(`--option ${pair} needs the form name=value.`);
|
|
2271
|
+
const raw = pair.slice(at + 1);
|
|
2272
|
+
let value = raw;
|
|
2273
|
+
try {
|
|
2274
|
+
value = JSON.parse(raw);
|
|
2275
|
+
} catch {}
|
|
2276
|
+
options[pair.slice(0, at)] = value;
|
|
2277
|
+
}
|
|
2278
|
+
const result = await context.call(pluginExportMethod, {
|
|
2279
|
+
artifact: artifactRef(arg(context, "artifact"), context.cwd),
|
|
2280
|
+
exporter,
|
|
2281
|
+
out: resolve(context.cwd, out),
|
|
2282
|
+
...Object.keys(options).length > 0 ? { options } : {},
|
|
2283
|
+
...version !== void 0 ? { version: /^\d+$/.test(version) ? Number(version) : version } : {}
|
|
2284
|
+
});
|
|
2285
|
+
return {
|
|
2286
|
+
result,
|
|
2287
|
+
human: `${[
|
|
2288
|
+
`Exported ${result.versionId} with ${result.exporter.id} (${result.exporter.package}):`,
|
|
2289
|
+
...result.files.map((file) => ` ${file}`),
|
|
2290
|
+
...result.findings.map((finding) => `${finding.severity} ${finding.code}: ${finding.message}`)
|
|
2291
|
+
].join("\n")}\n`
|
|
2292
|
+
};
|
|
2293
|
+
}
|
|
2255
2294
|
/** `mostra run <bundle>`. */
|
|
2256
|
-
const runCommand = defineCommand({
|
|
2295
|
+
const runCommand$1 = defineCommand({
|
|
2257
2296
|
path: ["run"],
|
|
2258
2297
|
summary: "Make a bundle `mostra export` wrote a version of this home, with the same IDs, and print its link.",
|
|
2259
2298
|
args: [{
|
|
@@ -2284,28 +2323,42 @@ const runCommand = defineCommand({
|
|
|
2284
2323
|
};
|
|
2285
2324
|
}
|
|
2286
2325
|
});
|
|
2287
|
-
/** `mostra add <package…>`. */
|
|
2326
|
+
/** `mostra add <package|item…>`. */
|
|
2288
2327
|
const addCommand = defineCommand({
|
|
2289
2328
|
path: ["add"],
|
|
2290
|
-
summary: "Add npm packages to an artifact's lockfile
|
|
2329
|
+
summary: "Add npm packages to an artifact's lockfile, or copy source-pack items (shadcn registry items) into it.",
|
|
2291
2330
|
args: [{
|
|
2292
2331
|
name: "package",
|
|
2293
|
-
summary: "npm specs
|
|
2332
|
+
summary: "npm specs (name, name@version, name@range, name@tag), or items: a URL, a local .json, owner/repo/item on GitHub, @namespace/item, plugin:<package>/<item>.",
|
|
2294
2333
|
variadic: true
|
|
2295
2334
|
}],
|
|
2296
|
-
flags: [
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2335
|
+
flags: [
|
|
2336
|
+
{
|
|
2337
|
+
name: "artifact",
|
|
2338
|
+
kind: "string",
|
|
2339
|
+
value: "<path|id>",
|
|
2340
|
+
summary: "The artifact. Default: the one in the current directory."
|
|
2341
|
+
},
|
|
2342
|
+
{
|
|
2343
|
+
name: "overwrite",
|
|
2344
|
+
kind: "boolean",
|
|
2345
|
+
summary: "Replace files of the artifact that an item writes with other content."
|
|
2346
|
+
},
|
|
2347
|
+
{
|
|
2348
|
+
name: "accept-license",
|
|
2349
|
+
kind: "list",
|
|
2350
|
+
value: "<id>",
|
|
2351
|
+
summary: "Acknowledge a license the items' packages bring (LicenseRef-…), recorded in the lockfile."
|
|
2352
|
+
},
|
|
2353
|
+
{
|
|
2354
|
+
name: "request-id",
|
|
2355
|
+
kind: "string",
|
|
2356
|
+
value: "<id>",
|
|
2357
|
+
summary: "Make a retry return the first attempt's result."
|
|
2358
|
+
}
|
|
2359
|
+
],
|
|
2307
2360
|
output: {
|
|
2308
|
-
type: "DepsAddResult",
|
|
2361
|
+
type: "DepsAddResult | PackAddResult",
|
|
2309
2362
|
topic: "cli"
|
|
2310
2363
|
},
|
|
2311
2364
|
exits: [EXIT.failure],
|
|
@@ -2314,14 +2367,46 @@ const addCommand = defineCommand({
|
|
|
2314
2367
|
const packages = context.args["package"];
|
|
2315
2368
|
if (!Array.isArray(packages) || packages.length === 0) throw usage("\"mostra add\" needs <package…>.");
|
|
2316
2369
|
const requestId = flag(context, "request-id");
|
|
2317
|
-
const
|
|
2318
|
-
|
|
2319
|
-
|
|
2370
|
+
const artifact = sourceRef(flag(context, "artifact") ?? ".", context.cwd);
|
|
2371
|
+
const specs = packages.map((spec) => {
|
|
2372
|
+
const address = parsePackAddress(spec);
|
|
2373
|
+
return address?.kind === "file" ? resolve(context.cwd, address.path) : spec;
|
|
2374
|
+
});
|
|
2375
|
+
if (!specs.some((spec) => parsePackAddress(spec) !== void 0)) {
|
|
2376
|
+
const accept = context.flags["accept-license"];
|
|
2377
|
+
const result = await context.call(depsAddMethod, {
|
|
2378
|
+
artifact,
|
|
2379
|
+
packages: specs,
|
|
2380
|
+
...Array.isArray(accept) && accept.length > 0 ? { acceptLicenses: [...accept] } : {},
|
|
2381
|
+
...requestId !== void 0 ? { requestId } : {}
|
|
2382
|
+
});
|
|
2383
|
+
return {
|
|
2384
|
+
result,
|
|
2385
|
+
human: result.packages.map((added) => `${added.name}@${added.version}${added.warm ? " (warm set)" : ""}\n`).join("")
|
|
2386
|
+
};
|
|
2387
|
+
}
|
|
2388
|
+
const accept = context.flags["accept-license"];
|
|
2389
|
+
const components = "path" in artifact ? await readFile(join(artifact.path, "components.json"), "utf8").catch(() => void 0) : void 0;
|
|
2390
|
+
const environment = Object.fromEntries(packVariables(components).flatMap((name) => {
|
|
2391
|
+
const value = context.env[name];
|
|
2392
|
+
return value !== void 0 ? [[name, value]] : [];
|
|
2393
|
+
}));
|
|
2394
|
+
const result = await context.call(packAddMethod, {
|
|
2395
|
+
artifact,
|
|
2396
|
+
specs,
|
|
2397
|
+
...context.flags["overwrite"] === true ? { overwrite: true } : {},
|
|
2398
|
+
...Array.isArray(accept) && accept.length > 0 ? { acceptLicenses: [...accept] } : {},
|
|
2399
|
+
...Object.keys(environment).length > 0 ? { environment } : {},
|
|
2320
2400
|
...requestId !== void 0 ? { requestId } : {}
|
|
2321
2401
|
});
|
|
2402
|
+
for (const note of result.notes) context.warn(note);
|
|
2322
2403
|
return {
|
|
2323
2404
|
result,
|
|
2324
|
-
human:
|
|
2405
|
+
human: [
|
|
2406
|
+
...result.items.map((item) => `${item.name} (${item.type})${item.requiredBy ? `, for ${item.requiredBy}` : ""}`),
|
|
2407
|
+
...result.files.map((file) => ` ${file.action} ${file.path}`),
|
|
2408
|
+
...result.packages.map((added) => `${added.name}@${added.version}${added.warm ? " (warm set)" : ""}`)
|
|
2409
|
+
].map((line) => `${line}\n`).join("")
|
|
2325
2410
|
};
|
|
2326
2411
|
}
|
|
2327
2412
|
});
|
|
@@ -3594,6 +3679,185 @@ const mcpCommand = defineCommand({
|
|
|
3594
3679
|
}
|
|
3595
3680
|
});
|
|
3596
3681
|
//#endregion
|
|
3682
|
+
//#region src/commands/plugins.ts
|
|
3683
|
+
/**
|
|
3684
|
+
* Plugins and packs (D30, D31, INTERFACES §14): `plugin validate|add|list|remove`, thin clients of
|
|
3685
|
+
* `plugin/*`. `add` (in `authoring.ts`) installs packs through `pack/add`, and `export --as` runs a
|
|
3686
|
+
* plugin's exporter through `plugin/export`.
|
|
3687
|
+
*/
|
|
3688
|
+
/** `--artifact` and `--global`: where a plugin is installed (`--home` names the home itself). */
|
|
3689
|
+
const SCOPE_FLAGS = [{
|
|
3690
|
+
name: "artifact",
|
|
3691
|
+
kind: "string",
|
|
3692
|
+
value: "<path|id>",
|
|
3693
|
+
summary: "The artifact whose lockfile records the plugins. Default: the one in the current directory."
|
|
3694
|
+
}, {
|
|
3695
|
+
name: "global",
|
|
3696
|
+
kind: "boolean",
|
|
3697
|
+
summary: "The home's own plugins instead, for every artifact of the home (exporters and CLI commands only)."
|
|
3698
|
+
}];
|
|
3699
|
+
const ACCEPT_FLAG = {
|
|
3700
|
+
name: "accept-license",
|
|
3701
|
+
kind: "list",
|
|
3702
|
+
value: "<id>",
|
|
3703
|
+
summary: "Acknowledge a license the install brings (LicenseRef-Remotion), recorded in the lockfile. Repeat or comma-separate."
|
|
3704
|
+
};
|
|
3705
|
+
/** The scope the flags name: the home, or an artifact (the current directory's by default). */
|
|
3706
|
+
function scope(context) {
|
|
3707
|
+
if (context.flags["global"] === true) {
|
|
3708
|
+
if (flag(context, "artifact") !== void 0) throw usage("Give --artifact or --global, not both.");
|
|
3709
|
+
return { home: true };
|
|
3710
|
+
}
|
|
3711
|
+
return { artifact: sourceRef(flag(context, "artifact") ?? ".", context.cwd) };
|
|
3712
|
+
}
|
|
3713
|
+
/** The list of a `list` flag. */
|
|
3714
|
+
function list(context, name) {
|
|
3715
|
+
const value = context.flags[name];
|
|
3716
|
+
return Array.isArray(value) ? [...value] : [];
|
|
3717
|
+
}
|
|
3718
|
+
/** People's view of plugins: one line each, then what loading them found. */
|
|
3719
|
+
function describePlugins(plugins) {
|
|
3720
|
+
if (plugins.length === 0) return "No plugins.\n";
|
|
3721
|
+
return plugins.map((plugin) => {
|
|
3722
|
+
const lines = [`${plugin.package}@${plugin.version} (${plugin.name}, ${plugin.scope}): ${plugin.contributions.map((item) => `${item.contract} ${item.id}`).join(", ") || "packs only"}${plugin.status === "error" ? " [doesn't load]" : ""}`];
|
|
3723
|
+
for (const diagnostic of plugin.diagnostics) lines.push(` ${diagnostic.severity} ${diagnostic.code}: ${diagnostic.message}`);
|
|
3724
|
+
return lines.join("\n");
|
|
3725
|
+
}).join("\n").concat("\n");
|
|
3726
|
+
}
|
|
3727
|
+
/** People's view of licenses: each with its class and where its acknowledgment stands. */
|
|
3728
|
+
function describeLicenses(licenses) {
|
|
3729
|
+
if (licenses.length === 0) return "";
|
|
3730
|
+
return `Licenses:\n${licenses.map((license) => ` ${license.id} (${license.class}, ${license.acknowledgment}): ${license.packages.map((pkg) => pkg.version !== void 0 ? `${pkg.name}@${pkg.version}` : `item ${pkg.name}`).join(", ")}`).join("\n")}\n`;
|
|
3731
|
+
}
|
|
3732
|
+
/** `mostra plugin validate [dir]`. */
|
|
3733
|
+
const pluginValidateCommand = defineCommand({
|
|
3734
|
+
path: ["plugin", "validate"],
|
|
3735
|
+
summary: "Check a plugin package as Mostra would load it: its manifest, contract ranges, entries and licenses.",
|
|
3736
|
+
args: [{
|
|
3737
|
+
name: "dir",
|
|
3738
|
+
summary: "The plugin's package directory. Default: the current directory.",
|
|
3739
|
+
optional: true
|
|
3740
|
+
}],
|
|
3741
|
+
flags: [ACCEPT_FLAG],
|
|
3742
|
+
output: {
|
|
3743
|
+
type: "PluginValidateResult",
|
|
3744
|
+
topic: "cli"
|
|
3745
|
+
},
|
|
3746
|
+
exits: [EXIT.failure],
|
|
3747
|
+
example: "plugin validate ./my-plugin",
|
|
3748
|
+
async run(context) {
|
|
3749
|
+
const dir = typeof context.args["dir"] === "string" ? context.args["dir"] : ".";
|
|
3750
|
+
const accept = context.flags["accept-license"];
|
|
3751
|
+
const result = await context.call(pluginValidateMethod, {
|
|
3752
|
+
path: resolve(context.cwd, dir),
|
|
3753
|
+
...Array.isArray(accept) && accept.length > 0 ? { acceptLicenses: [...accept] } : {}
|
|
3754
|
+
});
|
|
3755
|
+
const lines = result.diagnostics.map((diagnostic) => `${diagnostic.severity} ${diagnostic.code}${diagnostic.location && "file" in diagnostic.location ? ` (${diagnostic.location.file}:${diagnostic.location.line}:${diagnostic.location.column})` : ""}: ${diagnostic.message}`);
|
|
3756
|
+
return {
|
|
3757
|
+
result,
|
|
3758
|
+
human: `${result.valid ? "valid" : "invalid"}${result.plugin ? `: ${result.plugin.package}@${result.plugin.version} (${result.plugin.name})` : ""}\n${lines.join("\n")}${lines.length > 0 ? "\n" : ""}`,
|
|
3759
|
+
...result.valid ? {} : { exit: EXIT.failure }
|
|
3760
|
+
};
|
|
3761
|
+
}
|
|
3762
|
+
});
|
|
3763
|
+
/** `mostra plugin add <package…>`. */
|
|
3764
|
+
const pluginAddCommand = defineCommand({
|
|
3765
|
+
path: ["plugin", "add"],
|
|
3766
|
+
summary: "Install plugins for an artifact or the home, checking their contracts, conflicts and licenses first.",
|
|
3767
|
+
args: [{
|
|
3768
|
+
name: "package",
|
|
3769
|
+
summary: "npm specs of the plugins: name, name@version or name@range.",
|
|
3770
|
+
variadic: true
|
|
3771
|
+
}],
|
|
3772
|
+
flags: [
|
|
3773
|
+
...SCOPE_FLAGS,
|
|
3774
|
+
ACCEPT_FLAG,
|
|
3775
|
+
{
|
|
3776
|
+
name: "request-id",
|
|
3777
|
+
kind: "string",
|
|
3778
|
+
value: "<id>",
|
|
3779
|
+
summary: "Make a retry return the first attempt's result."
|
|
3780
|
+
}
|
|
3781
|
+
],
|
|
3782
|
+
output: {
|
|
3783
|
+
type: "PluginAddResult",
|
|
3784
|
+
topic: "cli"
|
|
3785
|
+
},
|
|
3786
|
+
exits: [EXIT.failure],
|
|
3787
|
+
example: "plugin add mostra-plugin-pdf --artifact ./report",
|
|
3788
|
+
async run(context) {
|
|
3789
|
+
const packages = context.args["package"];
|
|
3790
|
+
if (!Array.isArray(packages) || packages.length === 0) throw usage("\"mostra plugin add\" needs <package…>.");
|
|
3791
|
+
const accept = list(context, "accept-license");
|
|
3792
|
+
const requestId = flag(context, "request-id");
|
|
3793
|
+
const result = await context.call(pluginAddMethod, {
|
|
3794
|
+
...scope(context),
|
|
3795
|
+
packages,
|
|
3796
|
+
...accept.length > 0 ? { acceptLicenses: accept } : {},
|
|
3797
|
+
...requestId !== void 0 ? { requestId } : {}
|
|
3798
|
+
});
|
|
3799
|
+
return {
|
|
3800
|
+
result,
|
|
3801
|
+
human: `${describePlugins(result.plugins)}${describeLicenses(result.licenses)}`
|
|
3802
|
+
};
|
|
3803
|
+
}
|
|
3804
|
+
});
|
|
3805
|
+
/** `mostra plugin list`. */
|
|
3806
|
+
const pluginListCommand = defineCommand({
|
|
3807
|
+
path: ["plugin", "list"],
|
|
3808
|
+
summary: "List an artifact's plugins, or the home's, in load order, as verify and publish load them now.",
|
|
3809
|
+
flags: [...SCOPE_FLAGS],
|
|
3810
|
+
output: {
|
|
3811
|
+
type: "PluginListResult",
|
|
3812
|
+
topic: "cli"
|
|
3813
|
+
},
|
|
3814
|
+
exits: [EXIT.failure],
|
|
3815
|
+
example: "plugin list --artifact ./report",
|
|
3816
|
+
async run(context) {
|
|
3817
|
+
const result = await context.call(pluginListMethod, scope(context));
|
|
3818
|
+
return {
|
|
3819
|
+
result,
|
|
3820
|
+
human: `${describePlugins(result.plugins)}${describeLicenses(result.licenses)}`
|
|
3821
|
+
};
|
|
3822
|
+
}
|
|
3823
|
+
});
|
|
3824
|
+
/** `mostra plugin remove <package…>`. */
|
|
3825
|
+
const pluginRemoveCommand = defineCommand({
|
|
3826
|
+
path: ["plugin", "remove"],
|
|
3827
|
+
summary: "Take plugins out of an artifact's lockfile, or the home's.",
|
|
3828
|
+
args: [{
|
|
3829
|
+
name: "package",
|
|
3830
|
+
summary: "The plugins' package names.",
|
|
3831
|
+
variadic: true
|
|
3832
|
+
}],
|
|
3833
|
+
flags: [...SCOPE_FLAGS, {
|
|
3834
|
+
name: "request-id",
|
|
3835
|
+
kind: "string",
|
|
3836
|
+
value: "<id>",
|
|
3837
|
+
summary: "Make a retry return the first attempt's result."
|
|
3838
|
+
}],
|
|
3839
|
+
output: {
|
|
3840
|
+
type: "PluginRemoveResult",
|
|
3841
|
+
topic: "cli"
|
|
3842
|
+
},
|
|
3843
|
+
exits: [EXIT.failure],
|
|
3844
|
+
example: "plugin remove mostra-plugin-pdf --artifact ./report",
|
|
3845
|
+
async run(context) {
|
|
3846
|
+
const packages = context.args["package"];
|
|
3847
|
+
if (!Array.isArray(packages) || packages.length === 0) throw usage("\"mostra plugin remove\" needs <package…>.");
|
|
3848
|
+
const requestId = flag(context, "request-id");
|
|
3849
|
+
const result = await context.call(pluginRemoveMethod, {
|
|
3850
|
+
...scope(context),
|
|
3851
|
+
packages,
|
|
3852
|
+
...requestId !== void 0 ? { requestId } : {}
|
|
3853
|
+
});
|
|
3854
|
+
return {
|
|
3855
|
+
result,
|
|
3856
|
+
human: `Removed ${result.removed.join(", ")}.\n${describePlugins(result.plugins)}`
|
|
3857
|
+
};
|
|
3858
|
+
}
|
|
3859
|
+
});
|
|
3860
|
+
//#endregion
|
|
3597
3861
|
//#region src/commands/remote.ts
|
|
3598
3862
|
/**
|
|
3599
3863
|
* `mostra login` and `mostra logout` (INTERFACES §18.7, D165 items 2, 15): this home signs in to a
|
|
@@ -4357,8 +4621,12 @@ const COMMANDS = [
|
|
|
4357
4621
|
statePatchCommand,
|
|
4358
4622
|
pushCommand,
|
|
4359
4623
|
addCommand,
|
|
4624
|
+
pluginAddCommand,
|
|
4625
|
+
pluginListCommand,
|
|
4626
|
+
pluginRemoveCommand,
|
|
4627
|
+
pluginValidateCommand,
|
|
4360
4628
|
exportCommand,
|
|
4361
|
-
runCommand,
|
|
4629
|
+
runCommand$1,
|
|
4362
4630
|
secretSetCommand,
|
|
4363
4631
|
secretListCommand,
|
|
4364
4632
|
secretRmCommand,
|
|
@@ -4540,6 +4808,95 @@ function referenceMarkdown(commands) {
|
|
|
4540
4808
|
].join("\n");
|
|
4541
4809
|
}
|
|
4542
4810
|
//#endregion
|
|
4811
|
+
//#region src/plugin-commands.ts
|
|
4812
|
+
/**
|
|
4813
|
+
* Commands plugins contribute (`@mostra/contract-cli-command`, D30): when a command line names
|
|
4814
|
+
* none of `mostra`'s own commands, the runner asks the instance which commands the home's plugins
|
|
4815
|
+
* and the current artifact's contribute (`plugin/commands`), and runs the longest one the words
|
|
4816
|
+
* name in this process, as git runs a subcommand: its `call` goes over the CLI's own session, to
|
|
4817
|
+
* the methods of the host protocol only, each checked against its schema.
|
|
4818
|
+
*/
|
|
4819
|
+
const failed = (message) => new RpcError(createDiagnostic("MOSTRA_PLUGIN_FAILED", { message }));
|
|
4820
|
+
/** The plugin command `words` start with (the longest), or `undefined`. */
|
|
4821
|
+
function matchCommand(commands, words) {
|
|
4822
|
+
let best;
|
|
4823
|
+
for (const command of commands) {
|
|
4824
|
+
const path = command.command.split(" ");
|
|
4825
|
+
if (path.length > words.length) continue;
|
|
4826
|
+
if (!path.every((word, index) => words[index] === word)) continue;
|
|
4827
|
+
if (best === void 0 || path.length > best.command.split(" ").length) best = command;
|
|
4828
|
+
}
|
|
4829
|
+
return best;
|
|
4830
|
+
}
|
|
4831
|
+
/**
|
|
4832
|
+
* Loads a plugin command and turns it into a command of `mostra`: its definition is checked
|
|
4833
|
+
* (its stamp is one this release serves, its words are the manifest's), and its `run` gets a
|
|
4834
|
+
* context whose `call` reaches the host protocol through the CLI's session.
|
|
4835
|
+
*/
|
|
4836
|
+
async function loadPluginCommand(info) {
|
|
4837
|
+
let value;
|
|
4838
|
+
try {
|
|
4839
|
+
value = (await import(pathToFileURL(info.file).href))[info.export];
|
|
4840
|
+
} catch (error) {
|
|
4841
|
+
throw failed(`The plugin ${info.package} couldn't load its command "${info.command}": ${error instanceof Error ? error.message : String(error)}`);
|
|
4842
|
+
}
|
|
4843
|
+
const definition = value;
|
|
4844
|
+
if (definition === void 0 || typeof definition !== "object" || typeof definition.run !== "function") throw failed(`The plugin ${info.package} exports no command definition for "${info.command}".`);
|
|
4845
|
+
if (!stampServed(definition.contract, "cli-command")) throw new RpcError(createDiagnostic("MOSTRA_PLUGIN_CONTRACT_UNSUPPORTED", { message: `The plugin ${info.package}@${info.version}'s command "${info.command}" was built for a cli-command contract this release doesn't serve.` }));
|
|
4846
|
+
if (!Array.isArray(definition.path) || definition.path.join(" ") !== info.command) throw failed(`The plugin ${info.package}'s command is "${String(definition.path)}", not "${info.command}" as its manifest says.`);
|
|
4847
|
+
return defineCommand({
|
|
4848
|
+
path: [...definition.path],
|
|
4849
|
+
summary: typeof definition.summary === "string" ? definition.summary : info.command,
|
|
4850
|
+
...definition.args !== void 0 ? { args: definition.args } : {},
|
|
4851
|
+
...definition.flags !== void 0 ? { flags: definition.flags } : {},
|
|
4852
|
+
output: {
|
|
4853
|
+
type: `the result of ${info.package}'s command`,
|
|
4854
|
+
topic: "cli"
|
|
4855
|
+
},
|
|
4856
|
+
exits: [EXIT.failure],
|
|
4857
|
+
example: definition.example ?? info.command,
|
|
4858
|
+
telemetryName: "plugin",
|
|
4859
|
+
async run(context) {
|
|
4860
|
+
const controller = new AbortController();
|
|
4861
|
+
const outcome = await runCommand(info, () => definition.run({
|
|
4862
|
+
args: context.args,
|
|
4863
|
+
flags: context.flags,
|
|
4864
|
+
cwd: context.cwd,
|
|
4865
|
+
json: context.json
|
|
4866
|
+
}, {
|
|
4867
|
+
signal: controller.signal,
|
|
4868
|
+
log: (message) => context.log(String(message)),
|
|
4869
|
+
progress: (line) => context.log(String(line)),
|
|
4870
|
+
mostraVersion: cliVersion(),
|
|
4871
|
+
call: (method, params) => {
|
|
4872
|
+
const known = hostMethods.find((candidate) => candidate.method === method);
|
|
4873
|
+
if (known === void 0 || known.direction !== "client-to-instance") throw new RpcError(createDiagnostic("MOSTRA_HOST_METHOD_UNKNOWN", { message: `${method} isn't a method of the host protocol a client calls.` }));
|
|
4874
|
+
return context.call(known, known.params.parse(params));
|
|
4875
|
+
}
|
|
4876
|
+
}));
|
|
4877
|
+
if (typeof outcome !== "object" || outcome === null || !("result" in outcome)) throw failed(`The plugin ${info.package}'s command "${info.command}" returned no result.`);
|
|
4878
|
+
const exit = typeof outcome.exit === "number" && Number.isInteger(outcome.exit) && outcome.exit >= 0 && outcome.exit <= 255 ? outcome.exit : void 0;
|
|
4879
|
+
return {
|
|
4880
|
+
result: outcome.result,
|
|
4881
|
+
...typeof outcome.human === "string" ? { human: outcome.human } : {},
|
|
4882
|
+
...exit !== void 0 && exit !== 0 ? { exit } : {}
|
|
4883
|
+
};
|
|
4884
|
+
}
|
|
4885
|
+
});
|
|
4886
|
+
}
|
|
4887
|
+
/**
|
|
4888
|
+
* Runs a plugin's command: a diagnostic it throws (its own, or one a protocol call answered)
|
|
4889
|
+
* stays as it is; anything else it throws is the plugin's failure, never Mostra's crash.
|
|
4890
|
+
*/
|
|
4891
|
+
async function runCommand(info, run) {
|
|
4892
|
+
try {
|
|
4893
|
+
return await run();
|
|
4894
|
+
} catch (error) {
|
|
4895
|
+
if (error instanceof RpcError) throw error;
|
|
4896
|
+
throw failed(`The plugin ${info.package}'s command "${info.command}" failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
4897
|
+
}
|
|
4898
|
+
}
|
|
4899
|
+
//#endregion
|
|
4543
4900
|
//#region src/run.ts
|
|
4544
4901
|
/**
|
|
4545
4902
|
* The runner (INTERFACES §9, D140 item 16): reads the command line, runs one command, and owns
|
|
@@ -4623,7 +4980,21 @@ async function run(io) {
|
|
|
4623
4980
|
try {
|
|
4624
4981
|
parsed = parseCommandLine(COMMANDS, io.argv);
|
|
4625
4982
|
} catch (error) {
|
|
4626
|
-
|
|
4983
|
+
let plugin;
|
|
4984
|
+
try {
|
|
4985
|
+
plugin = await pluginCommandOf(io, global, error, (opened) => {
|
|
4986
|
+
connection = opened;
|
|
4987
|
+
summary = opened.summary;
|
|
4988
|
+
});
|
|
4989
|
+
} catch (problem) {
|
|
4990
|
+
return fail(diagnosticOf(problem));
|
|
4991
|
+
}
|
|
4992
|
+
if (plugin === void 0) return fail(diagnosticOf(error));
|
|
4993
|
+
try {
|
|
4994
|
+
parsed = parseCommandLine([...COMMANDS, plugin], io.argv);
|
|
4995
|
+
} catch (again) {
|
|
4996
|
+
return fail(diagnosticOf(again));
|
|
4997
|
+
}
|
|
4627
4998
|
}
|
|
4628
4999
|
if (parsed.kind === "version") {
|
|
4629
5000
|
if (json) writeJson({
|
|
@@ -4659,7 +5030,7 @@ async function run(io) {
|
|
|
4659
5030
|
const telemetry = telemetrySession({
|
|
4660
5031
|
env: io.env,
|
|
4661
5032
|
configDir: config,
|
|
4662
|
-
command: commandName(command),
|
|
5033
|
+
command: command.telemetryName ?? commandName(command),
|
|
4663
5034
|
json,
|
|
4664
5035
|
tty: io.tty,
|
|
4665
5036
|
readsStdin,
|
|
@@ -4814,7 +5185,44 @@ async function runRuntime(io, args, stdio) {
|
|
|
4814
5185
|
}));
|
|
4815
5186
|
});
|
|
4816
5187
|
}
|
|
5188
|
+
/**
|
|
5189
|
+
* The plugin command a command line names, when `error` says it names none of `mostra`'s own:
|
|
5190
|
+
* found among the home's plugins and the current directory's artifact's (`plugin/commands`),
|
|
5191
|
+
* over a session the command then keeps (`keep`).
|
|
5192
|
+
*/
|
|
5193
|
+
async function pluginCommandOf(io, global, error, keep) {
|
|
5194
|
+
if (!(error instanceof RpcError) || error.diagnostic.code !== "MOSTRA_CLI_UNKNOWN_COMMAND") return;
|
|
5195
|
+
const words = commandWords(io.argv);
|
|
5196
|
+
if (words.length === 0) return void 0;
|
|
5197
|
+
const cwd = global.cwd !== void 0 ? resolve(io.cwd, global.cwd) : io.cwd;
|
|
5198
|
+
const home = resolveHome({
|
|
5199
|
+
home: global.home,
|
|
5200
|
+
env: io.env,
|
|
5201
|
+
cwd,
|
|
5202
|
+
platform: io.platform ?? process.platform
|
|
5203
|
+
});
|
|
5204
|
+
const autostart = existsSync(join(home, "plugins")) || [
|
|
5205
|
+
"index.tsx",
|
|
5206
|
+
"index.jsx",
|
|
5207
|
+
"index.mdx"
|
|
5208
|
+
].some((entry) => existsSync(join(cwd, entry)));
|
|
5209
|
+
let opened;
|
|
5210
|
+
try {
|
|
5211
|
+
opened = await connect({
|
|
5212
|
+
home,
|
|
5213
|
+
env: io.env,
|
|
5214
|
+
autostart
|
|
5215
|
+
});
|
|
5216
|
+
} catch {
|
|
5217
|
+
return;
|
|
5218
|
+
}
|
|
5219
|
+
if (!opened) return void 0;
|
|
5220
|
+
keep(opened);
|
|
5221
|
+
const { commands } = await opened.call(pluginCommandsMethod, { artifact: { path: cwd } });
|
|
5222
|
+
const found = matchCommand(commands, words);
|
|
5223
|
+
return found === void 0 ? void 0 : loadPluginCommand(found);
|
|
5224
|
+
}
|
|
4817
5225
|
//#endregion
|
|
4818
5226
|
export { COMMANDS as a, referenceMarkdown as i, commandDefinition as n, commandHelp as r, run as t };
|
|
4819
5227
|
|
|
4820
|
-
//# sourceMappingURL=run-
|
|
5228
|
+
//# sourceMappingURL=run-BsUzIBQj.js.map
|