@mostra/cli 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/bin.js +2 -2
  2. package/dist/bootstrap-Dc-SQHRF.js +422 -0
  3. package/dist/bootstrap-Dc-SQHRF.js.map +1 -0
  4. package/dist/bootstrap-aaE5wFo9.js +1 -0
  5. package/dist/{flush-CBN3AU9X.js → flush-C16w3JL8.js} +24 -3
  6. package/dist/flush-C16w3JL8.js.map +1 -0
  7. package/dist/index.d.ts +13 -3
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +2 -2
  10. package/dist/reference/cli.md +34 -1
  11. package/dist/reference/diagnostics.json +39 -3
  12. package/dist/reference/errors/MOSTRA_ARTIFACT_ID_DROPPED.md +23 -0
  13. package/dist/reference/errors/MOSTRA_ARTIFACT_PATCH_REJECTED.md +23 -0
  14. package/dist/reference/errors/MOSTRA_ARTIFACT_PATH_INVALID.md +23 -0
  15. package/dist/reference/errors/MOSTRA_ENV_RUNTIME_INSTALLING.md +23 -0
  16. package/dist/reference/errors/MOSTRA_SUBMIT_NOT_FOUND.md +3 -3
  17. package/dist/reference/telemetry.md +5 -3
  18. package/dist/run-Bw4_6kcW.js +1 -0
  19. package/dist/{run-CuMkFuH7.js → run-DdYT3iHQ.js} +1072 -814
  20. package/dist/run-DdYT3iHQ.js.map +1 -0
  21. package/dist/skill/SKILL.md +5 -2
  22. package/dist/skill/references/answers.md +1 -1
  23. package/dist/skill/references/long-lived.md +2 -2
  24. package/dist/skill/references/mcp.md +63 -0
  25. package/dist/telemetry/flush-main.js +1 -1
  26. package/package.json +10 -4
  27. package/src/bootstrap.ts +16 -3
  28. package/src/command.ts +13 -3
  29. package/src/commands/dev.ts +60 -44
  30. package/src/commands/index.ts +4 -2
  31. package/src/commands/interaction.ts +19 -1
  32. package/src/commands/mcp.ts +128 -0
  33. package/src/detached.ts +1 -0
  34. package/src/docs.ts +14 -6
  35. package/src/help.ts +1 -1
  36. package/src/home.ts +5 -3
  37. package/src/mcp.ts +448 -0
  38. package/src/parse.ts +20 -6
  39. package/src/run.ts +24 -13
  40. package/src/telemetry/harness.ts +24 -0
  41. package/src/telemetry/index.ts +75 -48
  42. package/dist/bootstrap-DfEe_yPr.js +0 -113
  43. package/dist/bootstrap-DfEe_yPr.js.map +0 -1
  44. package/dist/exit-CBIf8nAU.js +0 -79
  45. package/dist/exit-CBIf8nAU.js.map +0 -1
  46. package/dist/flush-CBN3AU9X.js.map +0 -1
  47. package/dist/run-3WlZ2Jos.js +0 -1
  48. package/dist/run-CuMkFuH7.js.map +0 -1
package/dist/bin.js CHANGED
@@ -42,7 +42,7 @@ async function refuseOldNode() {
42
42
  }
43
43
  const code = nodeTooOld(process.versions.node) ? await refuseOldNode() : await start();
44
44
  async function start() {
45
- const { bootstrap } = await import("./bootstrap-DfEe_yPr.js");
45
+ const { bootstrap } = await import("./bootstrap-aaE5wFo9.js");
46
46
  return await bootstrap({
47
47
  argv: process.argv.slice(2),
48
48
  env: process.env,
@@ -54,7 +54,7 @@ async function start() {
54
54
  },
55
55
  stderrTty: process.stderr.isTTY === true,
56
56
  terminal: process.stdin.isTTY === true || process.stdout.isTTY === true || process.stderr.isTTY === true
57
- }) ?? await (await import("./run-3WlZ2Jos.js")).run({
57
+ }) ?? await (await import("./run-Bw4_6kcW.js")).run({
58
58
  argv: process.argv.slice(2),
59
59
  env: process.env,
60
60
  cwd: process.cwd(),
@@ -0,0 +1,422 @@
1
+ import { spawn } from "node:child_process";
2
+ import { RpcError, createDiagnostic } from "@mostra/protocol";
3
+ import { enclosingBundle, readPins, resolveRuntime } from "@mostra/sdk";
4
+ import { constants } from "node:os";
5
+ import { parseArgs } from "node:util";
6
+ //#region src/command.ts
7
+ /** Defines a command; the identity function, for types. */
8
+ function defineCommand(command) {
9
+ return command;
10
+ }
11
+ /** The command path as one string: `daemon install`. */
12
+ function commandName(command) {
13
+ return command.path.join(" ");
14
+ }
15
+ //#endregion
16
+ //#region src/exit.ts
17
+ /** The exit codes of INTERFACES §9. */
18
+ const EXIT = {
19
+ /** Success, or `verify` passed. */
20
+ ok: 0,
21
+ /** Artifact failure: verify failed, publish refused, a request the artifact's state refused. */
22
+ failure: 1,
23
+ /** Usage error. */
24
+ usage: 2,
25
+ /** Environment error: no runtime, browser or socket; the home; an unsupported platform. */
26
+ environment: 3,
27
+ /** Timeout: `--timeout` passed before the instance answered. */
28
+ timeout: 4,
29
+ /** `wait` ended `still_waiting`: not an error, the status is in the result. */
30
+ stillWaiting: 5,
31
+ /** Conflict: `once` already submitted, a compare-and-set mismatch, a reused request ID. */
32
+ conflict: 6
33
+ };
34
+ /** Each area's exit code. Every area is here: a new one fails the type check until it is. */
35
+ const BY_AREA = {
36
+ MANIFEST: EXIT.failure,
37
+ BUILD: EXIT.failure,
38
+ TYPE: EXIT.failure,
39
+ LINT: EXIT.failure,
40
+ DEP: EXIT.failure,
41
+ KIT: EXIT.failure,
42
+ FIELD: EXIT.failure,
43
+ ACTION: EXIT.failure,
44
+ LIVE: EXIT.failure,
45
+ RUNTIME: EXIT.failure,
46
+ CONSOLE: EXIT.failure,
47
+ NETWORK: EXIT.failure,
48
+ A11Y: EXIT.failure,
49
+ VISUAL: EXIT.failure,
50
+ SMOKE: EXIT.failure,
51
+ REGRESSION: EXIT.failure,
52
+ TERM: EXIT.failure,
53
+ PUBLISH: EXIT.failure,
54
+ SUBMIT: EXIT.failure,
55
+ HOST: EXIT.environment,
56
+ HOME: EXIT.environment,
57
+ HYGIENE: EXIT.failure,
58
+ SECRET: EXIT.failure,
59
+ SHARE: EXIT.environment,
60
+ VERIFY: EXIT.failure,
61
+ TARGET: EXIT.failure,
62
+ ENV: EXIT.environment,
63
+ PLATFORM: EXIT.environment,
64
+ ARTIFACT: EXIT.failure,
65
+ CLI: EXIT.usage
66
+ };
67
+ /** Codes whose exit code isn't their area's. */
68
+ const BY_CODE = {
69
+ MOSTRA_HOST_TIMEOUT: EXIT.timeout,
70
+ MOSTRA_CLI_CONFIG_UNWRITABLE: EXIT.environment,
71
+ MOSTRA_HOST_INVALID_PARAMS: EXIT.usage,
72
+ MOSTRA_HOST_REQUEST_ID_REUSED: EXIT.conflict,
73
+ MOSTRA_HOST_CURSOR_COMPACTED: EXIT.failure,
74
+ MOSTRA_HOST_SUBSCRIPTION_UNKNOWN: EXIT.usage,
75
+ MOSTRA_SUBMIT_ALREADY: EXIT.conflict,
76
+ MOSTRA_SUBMIT_REVISION_MOVED: EXIT.conflict,
77
+ MOSTRA_FIELD_CONFLICT: EXIT.conflict,
78
+ MOSTRA_FIELD_MUTATION_ID_REUSED: EXIT.conflict,
79
+ MOSTRA_PUBLISH_ID_CONFLICT: EXIT.failure,
80
+ MOSTRA_HOME_INTEGRITY: EXIT.failure,
81
+ MOSTRA_HOME_NOT_ALWAYS_ON: EXIT.ok,
82
+ MOSTRA_VERIFY_CRASHED: EXIT.environment
83
+ };
84
+ /** The exit code a diagnostic ends a command with. An unknown area is an environment error. */
85
+ function exitCodeFor(code) {
86
+ const exact = BY_CODE[code];
87
+ if (exact !== void 0) return exact;
88
+ const area = /^MOSTRA_([A-Z0-9]+)_/.exec(code)?.[1];
89
+ return (area !== void 0 ? BY_AREA[area] : void 0) ?? EXIT.environment;
90
+ }
91
+ //#endregion
92
+ //#region src/parse.ts
93
+ /**
94
+ * The command line, read against the command definitions (D140 item 13): the global flags, the
95
+ * command path, its arguments and flags. Every failure is `MOSTRA_CLI_USAGE` or
96
+ * `MOSTRA_CLI_UNKNOWN_COMMAND`, so `--json` mode reports it like any other error.
97
+ */
98
+ /** The flags every command takes (INTERFACES §9). */
99
+ const GLOBAL_FLAGS = [
100
+ {
101
+ name: "json",
102
+ kind: "boolean",
103
+ summary: "Print one JSON envelope on stdout (NDJSON for streams)."
104
+ },
105
+ {
106
+ name: "home",
107
+ kind: "string",
108
+ value: "<dir>",
109
+ summary: "Use this Mostra home instead of MOSTRA_HOME or the default."
110
+ },
111
+ {
112
+ name: "cwd",
113
+ kind: "string",
114
+ value: "<dir>",
115
+ summary: "Resolve relative paths from this directory."
116
+ },
117
+ {
118
+ name: "timeout",
119
+ kind: "duration",
120
+ value: "<d>",
121
+ summary: "Give up on the instance after this long (exit 4), such as 30s or 5m."
122
+ },
123
+ {
124
+ name: "help",
125
+ kind: "boolean",
126
+ summary: "Show this command's help; with --json, its definition."
127
+ }
128
+ ];
129
+ /** A usage error. */
130
+ function usage(message) {
131
+ return new RpcError(createDiagnostic("MOSTRA_CLI_USAGE", { message }));
132
+ }
133
+ const DURATION = /^([1-9][0-9]*)(ms|s|m|h|d)$/;
134
+ const UNIT_MS = {
135
+ ms: 1,
136
+ s: 1e3,
137
+ m: 6e4,
138
+ h: 36e5,
139
+ d: 864e5
140
+ };
141
+ /** A duration flag's milliseconds: `30s`, `5m`, `2h`, `7d`, `500ms`. */
142
+ function durationMs(value) {
143
+ const match = DURATION.exec(value);
144
+ if (!match) throw usage(`"${value}" isn't a duration; use a number with ms, s, m, h or d, such as 30s.`);
145
+ return Number(match[1]) * UNIT_MS[match[2]];
146
+ }
147
+ /**
148
+ * Reads the global flags wherever they stand, before the command is known: `--json` anywhere
149
+ * before `--` makes even a usage error a JSON envelope (D140 item 16).
150
+ */
151
+ function globalFlags(argv) {
152
+ const end = argv.indexOf("--");
153
+ const words = end === -1 ? argv : argv.slice(0, end);
154
+ const value = (name) => {
155
+ for (let index = 0; index < words.length; index += 1) {
156
+ const word = words[index];
157
+ if (word === `--${name}`) return words[index + 1];
158
+ if (word.startsWith(`--${name}=`)) return word.slice(name.length + 3);
159
+ }
160
+ };
161
+ const timeout = value("timeout");
162
+ let timeoutMs;
163
+ try {
164
+ timeoutMs = timeout === void 0 ? void 0 : durationMs(timeout);
165
+ } catch {
166
+ timeoutMs = void 0;
167
+ }
168
+ const home = value("home");
169
+ const cwd = value("cwd");
170
+ return {
171
+ json: words.includes("--json"),
172
+ ...home !== void 0 ? { home } : {},
173
+ ...cwd !== void 0 ? { cwd } : {},
174
+ ...timeoutMs !== void 0 ? { timeoutMs } : {}
175
+ };
176
+ }
177
+ /** The command that names `words`' longest prefix. */
178
+ function findCommand(commands, words) {
179
+ let best;
180
+ for (const command of commands) {
181
+ const { path } = command;
182
+ if (path.length <= words.length && path.every((word, index) => words[index] === word)) {
183
+ if (!best || path.length > best.used) best = {
184
+ command,
185
+ used: path.length
186
+ };
187
+ }
188
+ }
189
+ return best;
190
+ }
191
+ /** The first words of every command: the groups and the single-word commands. */
192
+ function topWords(commands) {
193
+ return [...new Set(commands.map((command) => command.path[0]))].sort();
194
+ }
195
+ /**
196
+ * The command path's candidates: the leading words that aren't flags, with the global flags (and
197
+ * their values) that may stand before them skipped, and where each stands in `argv`.
198
+ */
199
+ function leadingWords(argv) {
200
+ const words = [];
201
+ const pathAt = [];
202
+ for (let index = 0; index < argv.length; index += 1) {
203
+ const word = argv[index];
204
+ if (word === "--json" || word === "--help" || word === "-h") continue;
205
+ if (word === "--home" || word === "--cwd" || word === "--timeout") {
206
+ index += 1;
207
+ continue;
208
+ }
209
+ if (/^--(home|cwd|timeout)=/.test(word)) continue;
210
+ if (word.startsWith("-")) break;
211
+ words.push(word);
212
+ pathAt.push(index);
213
+ }
214
+ return {
215
+ words,
216
+ pathAt
217
+ };
218
+ }
219
+ /** The words a command line starts its command with (`["mcp"]`, `["share", "stop", …]`). */
220
+ function commandWords(argv) {
221
+ return leadingWords(argv).words;
222
+ }
223
+ /** Parses the command line against the definitions. Throws a usage diagnostic. */
224
+ function parseCommandLine(commands, argv) {
225
+ const bare = argv.filter((word) => word !== "--json");
226
+ if (bare.length === 1 && (bare[0] === "--version" || bare[0] === "-v")) return { kind: "version" };
227
+ const { words, pathAt } = leadingWords(argv);
228
+ const helpAsked = argv.includes("--help") || argv.includes("-h");
229
+ if (words.length === 0) {
230
+ if (helpAsked || argv.every((word) => word === "--json")) return { kind: "help" };
231
+ throw usage(`Name a command first; ${argv[0]} isn't one.`);
232
+ }
233
+ const found = findCommand(commands, words);
234
+ if (!found) {
235
+ const group = commands.filter((command) => command.path[0] === words[0]);
236
+ if (group.length > 0) {
237
+ if (helpAsked) return {
238
+ kind: "help",
239
+ group: words[0]
240
+ };
241
+ throw usage(`"mostra ${words[0]}" needs one of: ${group.map((command) => command.path.slice(1).join(" ")).join(", ")}.`);
242
+ }
243
+ throw new RpcError(createDiagnostic("MOSTRA_CLI_UNKNOWN_COMMAND", { message: `"${words[0]}" isn't a mostra command. The commands are: ${topWords(commands).join(", ")}.` }));
244
+ }
245
+ const { command } = found;
246
+ if (helpAsked) return {
247
+ kind: "help",
248
+ command
249
+ };
250
+ const used = new Set(pathAt.slice(0, found.used));
251
+ const rest = argv.filter((_, index) => !used.has(index));
252
+ const flagDefs = [...GLOBAL_FLAGS, ...command.flags ?? []];
253
+ let parsed;
254
+ try {
255
+ parsed = parseArgs({
256
+ args: [...rest],
257
+ allowPositionals: true,
258
+ strict: true,
259
+ options: Object.fromEntries(flagDefs.map((flag) => [flag.name, { type: flag.kind === "boolean" ? "boolean" : "string" }]))
260
+ });
261
+ } catch (error) {
262
+ throw usage(`${error.message.split(". To specify")[0]}. Run "mostra ${commandName(command)} --help".`);
263
+ }
264
+ const flags = {};
265
+ for (const flag of command.flags ?? []) {
266
+ const raw = parsed.values[flag.name];
267
+ if (raw === void 0) continue;
268
+ if (flag.kind === "boolean") {
269
+ flags[flag.name] = raw === true;
270
+ continue;
271
+ }
272
+ const text = String(raw);
273
+ if (flag.choices && !flag.choices.includes(text)) throw usage(`--${flag.name} takes one of ${flag.choices.join(", ")}; "${text}" isn't one.`);
274
+ if (flag.kind === "number") {
275
+ const number = Number(text);
276
+ if (!Number.isInteger(number) || number < 0) throw usage(`--${flag.name} takes a whole number; "${text}" isn't one.`);
277
+ flags[flag.name] = number;
278
+ } else if (flag.kind === "duration") {
279
+ durationMs(text);
280
+ flags[flag.name] = text;
281
+ } else if (flag.kind === "list") flags[flag.name] = text.split(",").map((item) => item.trim()).filter((item) => item.length > 0);
282
+ else flags[flag.name] = text;
283
+ }
284
+ const positionals = [...parsed.positionals];
285
+ const args = {};
286
+ for (const arg of command.args ?? []) {
287
+ if (arg.variadic) {
288
+ if (positionals.length === 0 && !arg.optional) throw usage(`"mostra ${commandName(command)}" needs <${arg.name}…>.`);
289
+ args[arg.name] = positionals.splice(0);
290
+ continue;
291
+ }
292
+ const value = positionals.shift();
293
+ if (value === void 0 && !arg.optional) throw usage(`"mostra ${commandName(command)}" needs <${arg.name}>.`);
294
+ args[arg.name] = value;
295
+ }
296
+ if (positionals.length > 0) throw usage(`"mostra ${commandName(command)}" takes no argument "${positionals[0]}". Run "mostra ${commandName(command)} --help".`);
297
+ if (typeof parsed.values["timeout"] === "string") durationMs(parsed.values["timeout"]);
298
+ return {
299
+ kind: "run",
300
+ command,
301
+ args,
302
+ flags
303
+ };
304
+ }
305
+ //#endregion
306
+ //#region src/bootstrap.ts
307
+ /**
308
+ * The npm bootstrap (RT-01, D142): a `mostra` installed from npm runs on whatever Node.js the
309
+ * system has, so before anything else it finds the runtime bundle its release pins (from the
310
+ * cache, or downloaded once, with progress on stderr) and runs the bundle's own `mostra` with the
311
+ * same arguments on the bundle's private Node.js. Every command, telemetry included, then runs in
312
+ * the bundle, and this process only waits and passes the exit code on.
313
+ *
314
+ * Inside a bundle, in a development checkout, or with `MOSTRA_BUNDLE`/`MOSTRA_RUNTIME_BIN` set,
315
+ * there is nothing to bootstrap and the CLI runs in this process.
316
+ *
317
+ * This module runs on the system's Node.js, so it uses nothing newer than Node.js 22.19 and loads
318
+ * none of the CLI's commands.
319
+ */
320
+ /** Whether this CLI should move into its pinned bundle before running a command. */
321
+ function needsBootstrap(env) {
322
+ if (env["MOSTRA_BUNDLE"] || env["MOSTRA_RUNTIME_BIN"]) return false;
323
+ if (enclosingBundle() !== void 0) return false;
324
+ return readPins(env) !== void 0;
325
+ }
326
+ /**
327
+ * Whether the command serves in this process instead of in the bundle (D164 item 7): `mostra mcp`
328
+ * answers its client at once and installs the bundle in the background, since a client gives a
329
+ * server only seconds to start (Codex 10 s) and a first install takes minutes.
330
+ */
331
+ function servesBeforeBundle(argv) {
332
+ return commandWords(argv)[0] === "mcp";
333
+ }
334
+ /** Progress lines for a person waiting on the first download. */
335
+ function progressReporter(io) {
336
+ let lastPercent = -1;
337
+ let lastStep = "";
338
+ return (progress) => {
339
+ if (progress.step === "download") {
340
+ const percent = Math.floor(progress.received / progress.total * 100);
341
+ const mb = (bytes) => `${Math.round(bytes / 1e6)} MB`;
342
+ if (io.stderrTty) {
343
+ if (percent !== lastPercent) io.stderr(`\rmostra: downloading the Mostra runtime, ${mb(progress.received)} of ${mb(progress.total)} (${percent}%)`);
344
+ } else if (lastStep !== "download" || Math.floor(percent / 25) > Math.floor(lastPercent / 25)) io.stderr(`mostra: downloading the Mostra runtime (${mb(progress.total)}): ${percent}%\n`);
345
+ lastPercent = percent;
346
+ lastStep = "download";
347
+ return;
348
+ }
349
+ if (progress.step === lastStep) return;
350
+ if (lastStep === "download" && io.stderrTty) io.stderr("\n");
351
+ lastStep = progress.step;
352
+ const said = {
353
+ files: "checking the runtime's files",
354
+ browser: "fetching the browser verify uses"
355
+ }[progress.step];
356
+ if (said !== void 0) io.stderr(`mostra: ${said}…\n`);
357
+ };
358
+ }
359
+ /** The envelope `--json` promises, for a bootstrap that fails before any command runs. */
360
+ function failed(io, diagnostic) {
361
+ io.stderr(`mostra: ${diagnostic.message}\n`);
362
+ if (diagnostic.hint) io.stderr(`mostra: ${diagnostic.hint}\n`);
363
+ if (io.argv.includes("--json")) io.stdout(`${JSON.stringify({
364
+ ok: false,
365
+ error: diagnostic,
366
+ warnings: []
367
+ })}\n`);
368
+ return exitCodeFor(diagnostic.code);
369
+ }
370
+ /**
371
+ * When this copy needs the bundle its release pins (`needsBootstrap`), runs the bundle's
372
+ * `mostra` with `io.argv` and resolves with its exit code; otherwise, or for `mostra mcp`, which
373
+ * installs the bundle itself while it serves (`servesBeforeBundle`), resolves `undefined`, and the
374
+ * caller runs the command itself. Any failure, deciding included, is a diagnostic (one envelope
375
+ * with `--json`) and its exit code. Signals this process gets are passed on to the child.
376
+ */
377
+ async function bootstrap(io) {
378
+ try {
379
+ if (!needsBootstrap(io.env) || servesBeforeBundle(io.argv)) return void 0;
380
+ return await runInBundle(io);
381
+ } catch (error) {
382
+ if (error instanceof RpcError) return failed(io, error.diagnostic);
383
+ return failed(io, createDiagnostic("MOSTRA_HOST_INTERNAL_ERROR", { message: `The npm bootstrap failed: ${error instanceof Error ? error.message : String(error)}` }));
384
+ }
385
+ }
386
+ async function runInBundle(io) {
387
+ const runtime = await resolveRuntime({
388
+ env: io.env,
389
+ onProgress: progressReporter(io)
390
+ });
391
+ if (runtime.cliEntry === void 0) throw new RpcError(createDiagnostic("MOSTRA_ENV_RUNTIME_MISSING", { message: "The runtime the bootstrap found has no CLI entry." }));
392
+ const cli = runtime.cliEntry;
393
+ return new Promise((resolve) => {
394
+ const child = spawn(runtime.node, [cli, ...io.argv], {
395
+ stdio: "inherit",
396
+ env: io.env
397
+ });
398
+ const forward = (signal) => {
399
+ if (signal === "SIGINT" && io.terminal) return;
400
+ child.kill(signal);
401
+ };
402
+ const signals = [
403
+ "SIGINT",
404
+ "SIGTERM",
405
+ "SIGHUP"
406
+ ];
407
+ for (const signal of signals) process.on(signal, forward);
408
+ let settled = false;
409
+ const settle = (code) => {
410
+ if (settled) return;
411
+ settled = true;
412
+ for (const signal of signals) process.off(signal, forward);
413
+ resolve(code);
414
+ };
415
+ child.on("error", (error) => settle(failed(io, createDiagnostic("MOSTRA_ENV_RUNTIME_MISSING", { message: `The runtime bundle's CLI couldn't be started (${runtime.node}): ${error.message}` }))));
416
+ child.on("exit", (code, signal) => settle(code ?? 128 + (signal ? constants.signals[signal] ?? 0 : 0)));
417
+ });
418
+ }
419
+ //#endregion
420
+ export { GLOBAL_FLAGS as a, parseCommandLine as c, EXIT as d, exitCodeFor as f, servesBeforeBundle as i, topWords as l, defineCommand as m, needsBootstrap as n, durationMs as o, commandName as p, progressReporter as r, globalFlags as s, bootstrap as t, usage as u };
421
+
422
+ //# sourceMappingURL=bootstrap-Dc-SQHRF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap-Dc-SQHRF.js","names":[],"sources":["../src/command.ts","../src/exit.ts","../src/parse.ts","../src/bootstrap.ts"],"sourcesContent":["/**\n * What a command is (D140 items 13, 16): a definition the parser, the help, the reference page,\n * `--help --json`, telemetry's command names and the contract tests all read. Commands never\n * print or exit on their own; they return a result (or throw a diagnostic) and the runner decides\n * the envelope, the human text and the exit code.\n */\nimport type { Diagnostic, MethodDefinition } from \"@mostra/protocol\";\nimport type { InstanceConnection } from \"./client.ts\";\n\n/** A flag's value kind. Every flag is `--long`; booleans take no value. */\nexport type FlagKind = \"boolean\" | \"string\" | \"number\" | \"duration\" | \"list\";\n\n/** One flag of a command. */\nexport interface FlagDef {\n /** The flag's name, without the dashes. */\n readonly name: string;\n /** What it takes. */\n readonly kind: FlagKind;\n /** One line for help: what it does. */\n readonly summary: string;\n /** The placeholder in usage and help: `<path>`, `<d>` … */\n readonly value?: string;\n /** The allowed values, for a closed set. */\n readonly choices?: readonly string[];\n /** The default, as help shows it. */\n readonly default?: string;\n}\n\n/** One positional argument. */\nexport interface ArgDef {\n /** The argument's name, as help shows it. */\n readonly name: string;\n /** One line for help: what it is. */\n readonly summary: string;\n /** Whether it may be left out. */\n readonly optional?: boolean;\n /** Whether it takes every remaining word (`<package…>`). */\n readonly variadic?: boolean;\n}\n\n/** What the runner gives a command. */\nexport interface CommandContext {\n /** The positional arguments, after the command path, by name. */\n readonly args: Readonly<Record<string, string | readonly string[] | undefined>>;\n /** The command's flags, parsed by kind (durations in milliseconds, lists as arrays). */\n readonly flags: Readonly<\n Record<string, string | number | boolean | readonly string[] | undefined>\n >;\n /** The working directory relative paths resolve from (`--cwd`, else the process's). */\n readonly cwd: string;\n /** Whether `--json` was given. */\n readonly json: boolean;\n /** The request timeout from `--timeout`, in milliseconds. */\n readonly timeoutMs: number | undefined;\n /** Calls a host protocol method on the home's instance, starting its daemon when needed. */\n call<P, R>(method: MethodDefinition<P, R>, params: P): Promise<R>;\n /** Reads the whole of stdin, for commands that take a value there. */\n readStdin(): Promise<string>;\n /** Writes one line of progress or a log line to stderr (never stdout). */\n log(line: string): void;\n /** Emits one event of a streaming command (an NDJSON line in `--json` mode). */\n emit(event: unknown, human?: string): void;\n /** Adds a warning to the envelope (and stderr). */\n warn(diagnostic: Diagnostic): void;\n /** The environment the CLI runs in. */\n readonly env: Readonly<Record<string, string | undefined>>;\n /** Whether stdout and stdin are terminals. */\n readonly tty: { readonly stdin: boolean; readonly stdout: boolean; readonly stderr: boolean };\n /** The resolved home and the CLI's own facts, for commands that report them. */\n readonly home: string;\n /** Records a telemetry event of this command (D140 item 8), when telemetry allows it. */\n record(event: TelemetryEventInput): void;\n /**\n * Queues the events recorded so far, for a command that runs until it is stopped (`mcp`);\n * `hostInstance` says whether the instance it reached was host-spawned (then nothing is sent).\n */\n checkpoint(hostInstance: boolean): void;\n /**\n * The session with the home's instance, starting its daemon unless `autostart` is false; then\n * `undefined` when none runs. `call` uses the same session.\n */\n connection(autostart?: boolean): Promise<InstanceConnection | undefined>;\n /** Runs the runtime binary (`mostra-runtime …`) and returns its exit code and stdout. */\n runtime(\n args: readonly string[],\n stdio?: \"pipe\" | \"inherit\",\n ): Promise<{ code: number; stdout: string }>;\n /** The CLI's config directory (D140 item 5). */\n readonly configDir: string;\n /** Writes to stderr. */\n readonly stderr: (text: string) => void;\n /** Writes to stdout as the command runs (`host`, `dev`'s stream without `--json`). */\n readonly stdout: (text: string) => void;\n}\n\n/** A command-specific telemetry event: its name and its own fields. */\nexport interface TelemetryEventInput {\n /** The event's name. */\n readonly event: \"verify.result\" | \"publish.done\" | \"share.done\" | \"mcp.session\";\n /** Its own fields; the schema keeps only the published ones. */\n readonly fields: Readonly<Record<string, unknown>>;\n}\n\n/** What a command's run returns. */\nexport interface CommandOutcome {\n /** The `result` of the envelope. */\n readonly result: unknown;\n /** The text for people (stdout); default: the result as indented JSON. */\n readonly human?: string;\n /** The exit code when it isn't 0: a failing verdict (1), `still_waiting` (5), conflicts (6). */\n readonly exit?: number;\n /** The command wrote its own stdout (`host`): the runner prints no envelope and no text. */\n readonly raw?: boolean;\n /** The instance the command reached on a session of its own was host-spawned (`mcp`). */\n readonly hostInstance?: boolean;\n}\n\n/** One command. */\nexport interface CommandDef {\n /** Its words after `mostra`: `[\"daemon\", \"install\"]`. */\n readonly path: readonly string[];\n /** One line: what it does. */\n readonly summary: string;\n /** Its positional arguments, in order. */\n readonly args?: readonly ArgDef[];\n /** Its own flags, besides the global ones. */\n readonly flags?: readonly FlagDef[];\n /** The result type `--json` puts in `result`, and its `mostra docs` topic. */\n readonly output: { readonly type: string; readonly topic: string };\n /** The exit codes it can end with, besides 2 and 3, which every command can. */\n readonly exits: readonly number[];\n /** One example invocation, without `mostra`. */\n readonly example: string;\n /** It reads stdin, so telemetry's question is never asked before it (D140 item 11). */\n readonly readsStdin?: boolean | ((flags: CommandContext[\"flags\"]) => boolean);\n /** It never reaches an instance (`docs`, `telemetry`): no `instance` in its envelope. */\n readonly local?: boolean;\n /** It writes a stream of events before its result (NDJSON in `--json` mode). */\n readonly streams?: boolean;\n /**\n * Telemetry and its question leave it alone (`telemetry`, `docs`, D140 item 11), or, as a\n * function of its flags, when it runs on someone's behalf (`mcp --embedded`, D148).\n */\n readonly quiet?: boolean | ((flags: CommandContext[\"flags\"]) => boolean);\n /** Does the command's work. */\n run(context: CommandContext): Promise<CommandOutcome>;\n}\n\n/** Defines a command; the identity function, for types. */\nexport function defineCommand(command: CommandDef): CommandDef {\n return command;\n}\n\n/** The command path as one string: `daemon install`. */\nexport function commandName(command: Pick<CommandDef, \"path\">): string {\n return command.path.join(\" \");\n}\n","/**\n * The exit codes (INTERFACES §9, D140 item 16): one table keyed by diagnostic code, so every\n * command ends the same way for the same failure. Each area has a code, and a few codes differ\n * from their area; the table is total over the catalog by construction, and a test checks every\n * catalog code against it.\n */\nimport type { DiagnosticArea } from \"@mostra/protocol\";\n\n/** The exit codes of INTERFACES §9. */\nexport const EXIT = {\n /** Success, or `verify` passed. */\n ok: 0,\n /** Artifact failure: verify failed, publish refused, a request the artifact's state refused. */\n failure: 1,\n /** Usage error. */\n usage: 2,\n /** Environment error: no runtime, browser or socket; the home; an unsupported platform. */\n environment: 3,\n /** Timeout: `--timeout` passed before the instance answered. */\n timeout: 4,\n /** `wait` ended `still_waiting`: not an error, the status is in the result. */\n stillWaiting: 5,\n /** Conflict: `once` already submitted, a compare-and-set mismatch, a reused request ID. */\n conflict: 6,\n} as const;\n\n/** One of {@link EXIT}'s codes. */\nexport type ExitCode = (typeof EXIT)[keyof typeof EXIT];\n\n/** Each area's exit code. Every area is here: a new one fails the type check until it is. */\nconst BY_AREA: Readonly<Record<DiagnosticArea, ExitCode>> = {\n MANIFEST: EXIT.failure,\n BUILD: EXIT.failure,\n TYPE: EXIT.failure,\n LINT: EXIT.failure,\n DEP: EXIT.failure,\n KIT: EXIT.failure,\n FIELD: EXIT.failure,\n ACTION: EXIT.failure,\n LIVE: EXIT.failure,\n RUNTIME: EXIT.failure,\n CONSOLE: EXIT.failure,\n NETWORK: EXIT.failure,\n A11Y: EXIT.failure,\n VISUAL: EXIT.failure,\n SMOKE: EXIT.failure,\n REGRESSION: EXIT.failure,\n TERM: EXIT.failure,\n PUBLISH: EXIT.failure,\n SUBMIT: EXIT.failure,\n HOST: EXIT.environment,\n HOME: EXIT.environment,\n HYGIENE: EXIT.failure,\n SECRET: EXIT.failure,\n SHARE: EXIT.environment,\n VERIFY: EXIT.failure,\n TARGET: EXIT.failure,\n ENV: EXIT.environment,\n PLATFORM: EXIT.environment,\n ARTIFACT: EXIT.failure,\n CLI: EXIT.usage,\n};\n\n/** Codes whose exit code isn't their area's. */\nconst BY_CODE: Readonly<Record<string, ExitCode>> = {\n MOSTRA_HOST_TIMEOUT: EXIT.timeout,\n // The CLI can't record a choice: its environment, not its command line.\n MOSTRA_CLI_CONFIG_UNWRITABLE: EXIT.environment,\n MOSTRA_HOST_INVALID_PARAMS: EXIT.usage,\n MOSTRA_HOST_REQUEST_ID_REUSED: EXIT.conflict,\n MOSTRA_HOST_CURSOR_COMPACTED: EXIT.failure,\n MOSTRA_HOST_SUBSCRIPTION_UNKNOWN: EXIT.usage,\n MOSTRA_SUBMIT_ALREADY: EXIT.conflict,\n MOSTRA_SUBMIT_REVISION_MOVED: EXIT.conflict,\n MOSTRA_FIELD_CONFLICT: EXIT.conflict,\n MOSTRA_FIELD_MUTATION_ID_REUSED: EXIT.conflict,\n MOSTRA_PUBLISH_ID_CONFLICT: EXIT.failure,\n MOSTRA_HOME_INTEGRITY: EXIT.failure,\n MOSTRA_HOME_NOT_ALWAYS_ON: EXIT.ok,\n MOSTRA_VERIFY_CRASHED: EXIT.environment,\n};\n\n/** The exit code a diagnostic ends a command with. An unknown area is an environment error. */\nexport function exitCodeFor(code: string): ExitCode {\n const exact = BY_CODE[code];\n if (exact !== undefined) return exact;\n const area = /^MOSTRA_([A-Z0-9]+)_/.exec(code)?.[1];\n return (area !== undefined ? BY_AREA[area as DiagnosticArea] : undefined) ?? EXIT.environment;\n}\n","/**\n * The command line, read against the command definitions (D140 item 13): the global flags, the\n * command path, its arguments and flags. Every failure is `MOSTRA_CLI_USAGE` or\n * `MOSTRA_CLI_UNKNOWN_COMMAND`, so `--json` mode reports it like any other error.\n */\nimport { parseArgs } from \"node:util\";\nimport { createDiagnostic, RpcError } from \"@mostra/protocol\";\nimport { type CommandDef, commandName, type FlagDef } from \"./command.ts\";\n\n/** The flags every command takes (INTERFACES §9). */\nexport const GLOBAL_FLAGS: readonly FlagDef[] = [\n {\n name: \"json\",\n kind: \"boolean\",\n summary: \"Print one JSON envelope on stdout (NDJSON for streams).\",\n },\n {\n name: \"home\",\n kind: \"string\",\n value: \"<dir>\",\n summary: \"Use this Mostra home instead of MOSTRA_HOME or the default.\",\n },\n {\n name: \"cwd\",\n kind: \"string\",\n value: \"<dir>\",\n summary: \"Resolve relative paths from this directory.\",\n },\n {\n name: \"timeout\",\n kind: \"duration\",\n value: \"<d>\",\n summary: \"Give up on the instance after this long (exit 4), such as 30s or 5m.\",\n },\n {\n name: \"help\",\n kind: \"boolean\",\n summary: \"Show this command's help; with --json, its definition.\",\n },\n];\n\n/** What the command line asks for. */\nexport type Parsed =\n | { readonly kind: \"version\" }\n | { readonly kind: \"help\"; readonly command?: CommandDef; readonly group?: string }\n | {\n readonly kind: \"run\";\n readonly command: CommandDef;\n readonly args: Record<string, string | readonly string[] | undefined>;\n readonly flags: Record<string, string | number | boolean | readonly string[] | undefined>;\n };\n\n/** The global flags' values, read before anything else so a usage error still honors them. */\nexport interface GlobalFlags {\n readonly json: boolean;\n readonly home?: string;\n readonly cwd?: string;\n readonly timeoutMs?: number;\n}\n\n/** A usage error. */\nexport function usage(message: string): RpcError {\n return new RpcError(createDiagnostic(\"MOSTRA_CLI_USAGE\", { message }));\n}\n\nconst DURATION = /^([1-9][0-9]*)(ms|s|m|h|d)$/;\nconst UNIT_MS: Readonly<Record<string, number>> = {\n ms: 1,\n s: 1000,\n m: 60_000,\n h: 3_600_000,\n d: 86_400_000,\n};\n\n/** A duration flag's milliseconds: `30s`, `5m`, `2h`, `7d`, `500ms`. */\nexport function durationMs(value: string): number {\n const match = DURATION.exec(value);\n if (!match)\n throw usage(`\"${value}\" isn't a duration; use a number with ms, s, m, h or d, such as 30s.`);\n return Number(match[1]) * (UNIT_MS[match[2] as string] as number);\n}\n\n/**\n * Reads the global flags wherever they stand, before the command is known: `--json` anywhere\n * before `--` makes even a usage error a JSON envelope (D140 item 16).\n */\nexport function globalFlags(argv: readonly string[]): GlobalFlags {\n const end = argv.indexOf(\"--\");\n const words = end === -1 ? argv : argv.slice(0, end);\n const value = (name: string): string | undefined => {\n for (let index = 0; index < words.length; index += 1) {\n const word = words[index] as string;\n if (word === `--${name}`) return words[index + 1];\n if (word.startsWith(`--${name}=`)) return word.slice(name.length + 3);\n }\n return undefined;\n };\n const timeout = value(\"timeout\");\n let timeoutMs: number | undefined;\n try {\n timeoutMs = timeout === undefined ? undefined : durationMs(timeout);\n } catch {\n timeoutMs = undefined;\n }\n const home = value(\"home\");\n const cwd = value(\"cwd\");\n return {\n json: words.includes(\"--json\"),\n ...(home !== undefined ? { home } : {}),\n ...(cwd !== undefined ? { cwd } : {}),\n ...(timeoutMs !== undefined ? { timeoutMs } : {}),\n };\n}\n\n/** The command that names `words`' longest prefix. */\nfunction findCommand(\n commands: readonly CommandDef[],\n words: readonly string[],\n): { command: CommandDef; used: number } | undefined {\n let best: { command: CommandDef; used: number } | undefined;\n for (const command of commands) {\n const { path } = command;\n if (path.length <= words.length && path.every((word, index) => words[index] === word)) {\n if (!best || path.length > best.used) best = { command, used: path.length };\n }\n }\n return best;\n}\n\n/** The first words of every command: the groups and the single-word commands. */\nexport function topWords(commands: readonly CommandDef[]): string[] {\n return [...new Set(commands.map((command) => command.path[0] as string))].sort();\n}\n\n/**\n * The command path's candidates: the leading words that aren't flags, with the global flags (and\n * their values) that may stand before them skipped, and where each stands in `argv`.\n */\nfunction leadingWords(argv: readonly string[]): { words: string[]; pathAt: number[] } {\n const words: string[] = [];\n const pathAt: number[] = [];\n for (let index = 0; index < argv.length; index += 1) {\n const word = argv[index] as string;\n if (word === \"--json\" || word === \"--help\" || word === \"-h\") continue;\n if (word === \"--home\" || word === \"--cwd\" || word === \"--timeout\") {\n index += 1;\n continue;\n }\n if (/^--(home|cwd|timeout)=/.test(word)) continue;\n if (word.startsWith(\"-\")) break;\n words.push(word);\n pathAt.push(index);\n }\n return { words, pathAt };\n}\n\n/** The words a command line starts its command with (`[\"mcp\"]`, `[\"share\", \"stop\", …]`). */\nexport function commandWords(argv: readonly string[]): string[] {\n return leadingWords(argv).words;\n}\n\n/** Parses the command line against the definitions. Throws a usage diagnostic. */\nexport function parseCommandLine(commands: readonly CommandDef[], argv: readonly string[]): Parsed {\n const bare = argv.filter((word) => word !== \"--json\");\n if (bare.length === 1 && (bare[0] === \"--version\" || bare[0] === \"-v\"))\n return { kind: \"version\" };\n // The command path is the leading words that aren't flags; global flags may stand before it.\n const { words, pathAt } = leadingWords(argv);\n const helpAsked = argv.includes(\"--help\") || argv.includes(\"-h\");\n if (words.length === 0) {\n if (helpAsked || argv.every((word) => word === \"--json\")) return { kind: \"help\" };\n throw usage(`Name a command first; ${argv[0]} isn't one.`);\n }\n const found = findCommand(commands, words);\n if (!found) {\n const group = commands.filter((command) => command.path[0] === words[0]);\n if (group.length > 0) {\n if (helpAsked) return { kind: \"help\", group: words[0] as string };\n throw usage(\n `\"mostra ${words[0]}\" needs one of: ${group.map((command) => command.path.slice(1).join(\" \")).join(\", \")}.`,\n );\n }\n throw new RpcError(\n createDiagnostic(\"MOSTRA_CLI_UNKNOWN_COMMAND\", {\n message: `\"${words[0]}\" isn't a mostra command. The commands are: ${topWords(commands).join(\", \")}.`,\n }),\n );\n }\n const { command } = found;\n if (helpAsked) return { kind: \"help\", command };\n const used = new Set(pathAt.slice(0, found.used));\n const rest = argv.filter((_, index) => !used.has(index));\n const flagDefs = [...GLOBAL_FLAGS, ...(command.flags ?? [])];\n let parsed: ReturnType<typeof parseArgs>;\n try {\n parsed = parseArgs({\n args: [...rest],\n allowPositionals: true,\n strict: true,\n options: Object.fromEntries(\n flagDefs.map((flag) => [\n flag.name,\n { type: flag.kind === \"boolean\" ? \"boolean\" : \"string\" },\n ]),\n ) as Parameters<typeof parseArgs>[0] extends { options?: infer O } ? NonNullable<O> : never,\n });\n } catch (error) {\n throw usage(\n `${(error as Error).message.split(\". To specify\")[0]}. Run \"mostra ${commandName(command)} --help\".`,\n );\n }\n const flags: Record<string, string | number | boolean | readonly string[] | undefined> = {};\n for (const flag of command.flags ?? []) {\n const raw = parsed.values[flag.name];\n if (raw === undefined) continue;\n if (flag.kind === \"boolean\") {\n flags[flag.name] = raw === true;\n continue;\n }\n const text = String(raw);\n if (flag.choices && !flag.choices.includes(text)) {\n throw usage(`--${flag.name} takes one of ${flag.choices.join(\", \")}; \"${text}\" isn't one.`);\n }\n if (flag.kind === \"number\") {\n const number = Number(text);\n if (!Number.isInteger(number) || number < 0)\n throw usage(`--${flag.name} takes a whole number; \"${text}\" isn't one.`);\n flags[flag.name] = number;\n } else if (flag.kind === \"duration\") {\n durationMs(text);\n flags[flag.name] = text;\n } else if (flag.kind === \"list\") {\n flags[flag.name] = text\n .split(\",\")\n .map((item) => item.trim())\n .filter((item) => item.length > 0);\n } else flags[flag.name] = text;\n }\n const positionals = [...parsed.positionals];\n const args: Record<string, string | readonly string[] | undefined> = {};\n for (const arg of command.args ?? []) {\n if (arg.variadic) {\n if (positionals.length === 0 && !arg.optional)\n throw usage(`\"mostra ${commandName(command)}\" needs <${arg.name}…>.`);\n args[arg.name] = positionals.splice(0);\n continue;\n }\n const value = positionals.shift();\n if (value === undefined && !arg.optional)\n throw usage(`\"mostra ${commandName(command)}\" needs <${arg.name}>.`);\n args[arg.name] = value;\n }\n if (positionals.length > 0) {\n throw usage(\n `\"mostra ${commandName(command)}\" takes no argument \"${positionals[0]}\". Run \"mostra ${commandName(command)} --help\".`,\n );\n }\n if (typeof parsed.values[\"timeout\"] === \"string\") durationMs(parsed.values[\"timeout\"]);\n return { kind: \"run\", command, args, flags };\n}\n","/**\n * The npm bootstrap (RT-01, D142): a `mostra` installed from npm runs on whatever Node.js the\n * system has, so before anything else it finds the runtime bundle its release pins (from the\n * cache, or downloaded once, with progress on stderr) and runs the bundle's own `mostra` with the\n * same arguments on the bundle's private Node.js. Every command, telemetry included, then runs in\n * the bundle, and this process only waits and passes the exit code on.\n *\n * Inside a bundle, in a development checkout, or with `MOSTRA_BUNDLE`/`MOSTRA_RUNTIME_BIN` set,\n * there is nothing to bootstrap and the CLI runs in this process.\n *\n * This module runs on the system's Node.js, so it uses nothing newer than Node.js 22.19 and loads\n * none of the CLI's commands.\n */\nimport { spawn } from \"node:child_process\";\nimport { constants } from \"node:os\";\nimport { createDiagnostic, type Diagnostic, RpcError } from \"@mostra/protocol\";\nimport { enclosingBundle, type InstallProgress, readPins, resolveRuntime } from \"@mostra/sdk\";\nimport { exitCodeFor } from \"./exit.ts\";\nimport type { Environment } from \"./home.ts\";\nimport { commandWords } from \"./parse.ts\";\n\n/** How the bootstrap talks to the terminal. */\nexport interface BootstrapIo {\n readonly argv: readonly string[];\n readonly env: Environment;\n readonly stdout: (text: string) => void;\n readonly stderr: (text: string) => void;\n /** Whether stderr is a terminal: progress then rewrites one line. */\n readonly stderrTty: boolean;\n /**\n * Whether a terminal is attached (stdin, stdout or stderr is one). Ctrl-C there signals the\n * whole foreground process group, the bundle's `mostra` included, so SIGINT isn't forwarded:\n * a second one would cut short a command that stops gracefully on the first (`mostra dev`).\n */\n readonly terminal: boolean;\n}\n\n/** Whether this CLI should move into its pinned bundle before running a command. */\nexport function needsBootstrap(env: Environment): boolean {\n if (env[\"MOSTRA_BUNDLE\"] || env[\"MOSTRA_RUNTIME_BIN\"]) return false;\n if (enclosingBundle() !== undefined) return false;\n return readPins(env) !== undefined;\n}\n\n/**\n * Whether the command serves in this process instead of in the bundle (D164 item 7): `mostra mcp`\n * answers its client at once and installs the bundle in the background, since a client gives a\n * server only seconds to start (Codex 10 s) and a first install takes minutes.\n */\nexport function servesBeforeBundle(argv: readonly string[]): boolean {\n return commandWords(argv)[0] === \"mcp\";\n}\n\n/** Progress lines for a person waiting on the first download. */\nexport function progressReporter(\n io: Pick<BootstrapIo, \"stderr\" | \"stderrTty\">,\n): (progress: InstallProgress) => void {\n let lastPercent = -1;\n let lastStep = \"\";\n return (progress) => {\n if (progress.step === \"download\") {\n const percent = Math.floor((progress.received / progress.total) * 100);\n const mb = (bytes: number): string => `${Math.round(bytes / 1e6)} MB`;\n if (io.stderrTty) {\n if (percent !== lastPercent)\n io.stderr(\n `\\rmostra: downloading the Mostra runtime, ${mb(progress.received)} of ${mb(progress.total)} (${percent}%)`,\n );\n } else if (\n lastStep !== \"download\" ||\n Math.floor(percent / 25) > Math.floor(lastPercent / 25)\n ) {\n io.stderr(`mostra: downloading the Mostra runtime (${mb(progress.total)}): ${percent}%\\n`);\n }\n lastPercent = percent;\n lastStep = \"download\";\n return;\n }\n if (progress.step === lastStep) return;\n if (lastStep === \"download\" && io.stderrTty) io.stderr(\"\\n\");\n lastStep = progress.step;\n const words: Partial<Record<InstallProgress[\"step\"], string>> = {\n files: \"checking the runtime's files\",\n browser: \"fetching the browser verify uses\",\n };\n const said = words[progress.step];\n if (said !== undefined) io.stderr(`mostra: ${said}…\\n`);\n };\n}\n\n/** The envelope `--json` promises, for a bootstrap that fails before any command runs. */\nfunction failed(io: BootstrapIo, diagnostic: Diagnostic): number {\n io.stderr(`mostra: ${diagnostic.message}\\n`);\n if (diagnostic.hint) io.stderr(`mostra: ${diagnostic.hint}\\n`);\n if (io.argv.includes(\"--json\")) {\n io.stdout(`${JSON.stringify({ ok: false, error: diagnostic, warnings: [] })}\\n`);\n }\n return exitCodeFor(diagnostic.code);\n}\n\n/**\n * When this copy needs the bundle its release pins (`needsBootstrap`), runs the bundle's\n * `mostra` with `io.argv` and resolves with its exit code; otherwise, or for `mostra mcp`, which\n * installs the bundle itself while it serves (`servesBeforeBundle`), resolves `undefined`, and the\n * caller runs the command itself. Any failure, deciding included, is a diagnostic (one envelope\n * with `--json`) and its exit code. Signals this process gets are passed on to the child.\n */\nexport async function bootstrap(io: BootstrapIo): Promise<number | undefined> {\n try {\n // Deciding is inside the boundary too: pins that can't be read are a diagnostic, never a\n // stack trace (GPT review finding 3).\n if (!needsBootstrap(io.env) || servesBeforeBundle(io.argv)) return undefined;\n return await runInBundle(io);\n } catch (error) {\n // Whatever goes wrong, `--json` still gets exactly one envelope (D140 item 16).\n if (error instanceof RpcError) return failed(io, error.diagnostic);\n return failed(\n io,\n createDiagnostic(\"MOSTRA_HOST_INTERNAL_ERROR\", {\n message: `The npm bootstrap failed: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n }\n}\n\nasync function runInBundle(io: BootstrapIo): Promise<number> {\n const runtime = await resolveRuntime({ env: io.env, onProgress: progressReporter(io) });\n if (runtime.cliEntry === undefined) {\n throw new RpcError(\n createDiagnostic(\"MOSTRA_ENV_RUNTIME_MISSING\", {\n message: \"The runtime the bootstrap found has no CLI entry.\",\n }),\n );\n }\n const cli = runtime.cliEntry;\n return new Promise((resolve) => {\n const child = spawn(runtime.node, [cli, ...io.argv], {\n stdio: \"inherit\",\n env: io.env as NodeJS.ProcessEnv,\n });\n const forward = (signal: NodeJS.Signals): void => {\n if (signal === \"SIGINT\" && io.terminal) return; // the child got the terminal's own\n child.kill(signal);\n };\n const signals: NodeJS.Signals[] = [\"SIGINT\", \"SIGTERM\", \"SIGHUP\"];\n for (const signal of signals) process.on(signal, forward);\n let settled = false;\n const settle = (code: number): void => {\n if (settled) return;\n settled = true;\n for (const signal of signals) process.off(signal, forward);\n resolve(code);\n };\n child.on(\"error\", (error) =>\n settle(\n failed(\n io,\n createDiagnostic(\"MOSTRA_ENV_RUNTIME_MISSING\", {\n message: `The runtime bundle's CLI couldn't be started (${runtime.node}): ${error.message}`,\n }),\n ),\n ),\n );\n // A child ended by a signal exits as a shell reports it: 128 plus the signal's number.\n child.on(\"exit\", (code, signal) =>\n settle(code ?? 128 + (signal ? (constants.signals[signal] ?? 0) : 0)),\n );\n });\n}\n"],"mappings":";;;;;;;AAqJA,SAAgB,cAAc,SAAiC;CAC7D,OAAO;AACT;;AAGA,SAAgB,YAAY,SAA2C;CACrE,OAAO,QAAQ,KAAK,KAAK,GAAG;AAC9B;;;;ACnJA,MAAa,OAAO;;CAElB,IAAI;;CAEJ,SAAS;;CAET,OAAO;;CAEP,aAAa;;CAEb,SAAS;;CAET,cAAc;;CAEd,UAAU;AACZ;;AAMA,MAAM,UAAsD;CAC1D,UAAU,KAAK;CACf,OAAO,KAAK;CACZ,MAAM,KAAK;CACX,MAAM,KAAK;CACX,KAAK,KAAK;CACV,KAAK,KAAK;CACV,OAAO,KAAK;CACZ,QAAQ,KAAK;CACb,MAAM,KAAK;CAC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AAM,WAAW,WAAiC;GAChD,IAAI,WAAW,YAAY,GAAG,UAAU;GACxC,MAAM,KAAK,MAAM;EACnB;EACA,MAAM,UAA4B;GAAC;GAAU;GAAW;EAAQ;EAChE,KAAK,MAAM,UAAU,SAAS,QAAQ,GAAG,QAAQ,OAAO;EACxD,IAAI,UAAU;EACd,MAAM,UAAU,SAAuB;GACrC,IAAI,SAAS;GACb,UAAU;GACV,KAAK,MAAM,UAAU,SAAS,QAAQ,IAAI,QAAQ,OAAO;GACzD,QAAQ,IAAI;EACd;EACA,MAAM,GAAG,UAAU,UACjB,OACE,OACE,IACA,iBAAiB,8BAA8B,EAC7C,SAAS,iDAAiD,QAAQ,KAAK,KAAK,MAAM,UACpF,CAAC,CACH,CACF,CACF;EAEA,MAAM,GAAG,SAAS,MAAM,WACtB,OAAO,QAAQ,OAAO,SAAU,UAAU,QAAQ,WAAW,IAAK,EAAE,CACtE;CACF,CAAC;AACH"}
@@ -0,0 +1 @@
1
+ export { t as bootstrap } from "./bootstrap-Dc-SQHRF.js";
@@ -187,6 +187,26 @@ function detectHarness(env) {
187
187
  if (set(declared) || set(env["AGENT"])) return "other";
188
188
  return "none";
189
189
  }
190
+ /**
191
+ * The known agent an MCP client is, by the `clientInfo.name` it sends (D140 item 8, D164 item 4),
192
+ * as each was observed (VERIFIED_FACTS, WP-15): Claude Code sends `claude-code`, Codex
193
+ * `codex-mcp-client`. Any other name is `other`; the name itself is never sent, since it can name
194
+ * a private tool.
195
+ */
196
+ const MCP_CLIENTS = {
197
+ "claude-code": "claude-code",
198
+ "codex-mcp-client": "codex"
199
+ };
200
+ /** `mcp.session`'s fields for a client: its agent's ID, and its version only for a known one. */
201
+ function mcpSessionFields(client) {
202
+ const known = Object.hasOwn(MCP_CLIENTS, client.name) ? MCP_CLIENTS[client.name] : void 0;
203
+ if (known === void 0) return { client: "other" };
204
+ const version = client.version;
205
+ return version !== void 0 && /^[0-9A-Za-z.+-]{1,32}$/.test(version) ? {
206
+ client: known,
207
+ clientVersion: version
208
+ } : { client: known };
209
+ }
190
210
  /** The duration buckets of `cli.command`. */
191
211
  const DURATIONS = [
192
212
  "<1s",
@@ -316,7 +336,8 @@ const PATH_VARIABLES = [
316
336
  "MOSTRA_TEST_BUNDLE_PINS",
317
337
  "MOSTRA_TAILSCALE",
318
338
  "MOSTRA_CLOUDFLARED",
319
- "MOSTRA_TEST_TUNNELS"
339
+ "MOSTRA_TEST_TUNNELS",
340
+ "MOSTRA_MCP_WORKSPACE"
320
341
  ];
321
342
  /** `env` with every relative path variable resolved against `cwd`. */
322
343
  function detachedEnvironment(env, cwd = process.cwd()) {
@@ -891,6 +912,6 @@ function startFlusher(store, env, now) {
891
912
  } catch {}
892
913
  }
893
914
  //#endregion
894
- export { detachedEnvironment as a, durationBucket as c, buildEndpoint as d, decide as f, packageRoot as g, fromSource as h, detachedDirectory as i, minute as l, cliVersion as m, startFlusher as n, TelemetryEvent as o, truthy as p, TelemetryStore as r, catalogCodes as s, flush as t, detectHarness as u };
915
+ export { packageRoot as _, detachedEnvironment as a, durationBucket as c, mcpSessionFields as d, buildEndpoint as f, fromSource as g, cliVersion as h, detachedDirectory as i, minute as l, truthy as m, startFlusher as n, TelemetryEvent as o, decide as p, TelemetryStore as r, catalogCodes as s, flush as t, detectHarness as u };
895
916
 
896
- //# sourceMappingURL=flush-CBN3AU9X.js.map
917
+ //# sourceMappingURL=flush-C16w3JL8.js.map