@mostra/cli 0.7.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 (64) 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 +35 -2
  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-DO9Y3Dtm.js → run-DdYT3iHQ.js} +1137 -763
  20. package/dist/run-DdYT3iHQ.js.map +1 -0
  21. package/dist/skill/SKILL.md +120 -0
  22. package/dist/skill/assets/examples/dashboard/index.tsx +161 -0
  23. package/dist/skill/assets/examples/dashboard/live.ts +25 -0
  24. package/dist/skill/assets/examples/dashboard/styles.css +125 -0
  25. package/dist/skill/assets/examples/decision/index.tsx +95 -0
  26. package/dist/skill/assets/examples/decision/styles.css +125 -0
  27. package/dist/skill/assets/examples/inbox/actions.ts +23 -0
  28. package/dist/skill/assets/examples/inbox/index.tsx +109 -0
  29. package/dist/skill/assets/examples/inbox/styles.css +125 -0
  30. package/dist/skill/assets/studio.css +125 -0
  31. package/dist/skill/references/answers.md +181 -0
  32. package/dist/skill/references/design.md +154 -0
  33. package/dist/skill/references/libraries.md +167 -0
  34. package/dist/skill/references/long-lived.md +148 -0
  35. package/dist/skill/references/mcp.md +63 -0
  36. package/dist/skill/references/page.md +131 -0
  37. package/dist/skill/references/server.md +146 -0
  38. package/dist/skill/references/sharing.md +72 -0
  39. package/dist/skill/references/verify.md +71 -0
  40. package/dist/telemetry/flush-main.js +1 -1
  41. package/package.json +12 -5
  42. package/src/bootstrap.ts +16 -3
  43. package/src/command.ts +13 -3
  44. package/src/commands/admin.ts +5 -4
  45. package/src/commands/dev.ts +60 -44
  46. package/src/commands/index.ts +4 -2
  47. package/src/commands/interaction.ts +19 -1
  48. package/src/commands/mcp.ts +128 -0
  49. package/src/detached.ts +1 -0
  50. package/src/docs.ts +141 -7
  51. package/src/help.ts +1 -1
  52. package/src/home.ts +5 -3
  53. package/src/mcp.ts +448 -0
  54. package/src/parse.ts +20 -6
  55. package/src/run.ts +24 -13
  56. package/src/telemetry/harness.ts +24 -0
  57. package/src/telemetry/index.ts +75 -48
  58. package/dist/bootstrap-DfEe_yPr.js +0 -113
  59. package/dist/bootstrap-DfEe_yPr.js.map +0 -1
  60. package/dist/exit-CBIf8nAU.js +0 -79
  61. package/dist/exit-CBIf8nAU.js.map +0 -1
  62. package/dist/flush-CBN3AU9X.js.map +0 -1
  63. package/dist/run-DKNRTR1j.js +0 -1
  64. package/dist/run-DO9Y3Dtm.js.map +0 -1
@@ -0,0 +1,131 @@
1
+ # The artifact: files, manifest, pages and packages
2
+
3
+ ## Contents
4
+
5
+ - Files
6
+ - The manifest
7
+ - Pages
8
+ - Packages
9
+ - Styles and assets
10
+ - MDX
11
+ - Who and where: `useViewer`, `useArtifact`
12
+ - Sending the person elsewhere: `openLink`
13
+ - Pages written for Claude: `window.storage`
14
+
15
+ ## Files
16
+
17
+ An artifact is a directory (or a single `.tsx`, `.jsx` or `.mdx` file). No `package.json`, `tsconfig.json` or build configuration is needed; Mostra brings its own.
18
+
19
+ ```text
20
+ my-artifact/
21
+ index.tsx the entry: `export const artifact = defineArtifact({...})` and the page as the default export
22
+ AGENTS.md what `mostra new` wrote for agents editing this artifact
23
+ pages/ optional routes, see Pages
24
+ actions.ts any module whose first statement is "use server" (the name is free), see server.md
25
+ live.ts live data sources (this exact name), see long-lived.md
26
+ components/ anything else you import
27
+ public/ files served as they are, at /<name>
28
+ ```
29
+
30
+ A directory has exactly one entry: `index.tsx`, `index.jsx` or `index.mdx`. `node_modules`, `.git`, `.mostra`, editor backups and paths listed in a `.mostraignore` file stay out of the published source.
31
+
32
+ ## The manifest
33
+
34
+ ```tsx
35
+ import { defineArtifact } from "@mostra/react";
36
+
37
+ export const artifact = defineArtifact({
38
+ id: "art_01M66HS31X56AW7VKS2JV1C9N7", // written by `mostra new`; keep it
39
+ title: "Q4 hiring plan", // required when a manifest is present
40
+ description: "Approve or change the plan for next quarter.",
41
+ family: "proposal", // questionnaire, proposal, prototype, review, dashboard, deck, demo, inbox, tasks, or your own word
42
+ submission: { policy: "once" }, // see answers.md; the host running Mostra may override it
43
+ links: [{ rel: "round-of", artifact: "art_…" }],
44
+ limits: { heapMb: 1024, watchdogMs: 10000, idleMinutes: 10 },
45
+ });
46
+ ```
47
+
48
+ - Every value is a literal (`as const` and `satisfies` are fine). Mostra reads the manifest without running your code; a computed value is `MOSTRA_MANIFEST_NOT_LITERAL`.
49
+ - `artifact.title` and the other fields are usable in the page (`<h1>{artifact.title}</h1>`).
50
+ - An artifact without an `id` is bound to its directory at its first publish. Copying a directory that carries an `id` makes two sources claim one artifact (`MOSTRA_PUBLISH_ID_CONFLICT`): give the copy a new one with `mostra new`.
51
+ - An entry without any manifest publishes with defaults, titled after its directory.
52
+
53
+ ## Pages
54
+
55
+ With a `pages/` directory every `.tsx`, `.jsx` or `.mdx` file in it is a route:
56
+
57
+ | File | Route |
58
+ |---|---|
59
+ | `pages/index.tsx` | `/` |
60
+ | `pages/settings.tsx` | `/settings` |
61
+ | `pages/reports/index.tsx` | `/reports` |
62
+ | `pages/reports/[id].tsx` | `/reports/:id` |
63
+ | `pages/docs/[...rest].tsx` | `/docs/*` |
64
+
65
+ The entry's default export then becomes the layout every page renders inside, receiving the page as `children`. Link between pages with React Router's `Link` (`import { Link, useParams } from "react-router"`). Fields work the same on every page: they belong to the artifact, not to a route.
66
+
67
+ ## Packages
68
+
69
+ - Import any npm package by name. Packages in the warm set ([libraries.md](libraries.md)) resolve instantly; any other is installed on demand at the newest release at least a day old, pinned exactly, and frozen into the version at publish.
70
+ - `mostra add <package>[@version] --artifact <dir>` pins a version yourself, before you import it.
71
+ - Imports must stay inside the artifact: `../shared/x` is refused (`MOSTRA_BUILD_UNRESOLVED`). Use `@/components/x` for a path from the artifact's root.
72
+ - A package without types is a warning (`MOSTRA_TYPE_UNTYPED_PACKAGE`); declare a module or ignore it.
73
+ - Offline, only packages already in Mostra's store resolve (`MOSTRA_DEP_OFFLINE` names the missing one).
74
+
75
+ ## Styles and assets
76
+
77
+ - Tailwind CSS 4 is always on: write utility classes, with no configuration file. Theme values live in CSS (`@theme`), as in [design.md](design.md).
78
+ - Import your own CSS from the page (`import "./styles.css"`). A stylesheet that defines `@theme` or `@layer base` starts with `@import "tailwindcss";`.
79
+ - Files in `public/` are served at the root: `public/logo.svg` is `/logo.svg`. Use root-relative paths.
80
+ - Fonts and images load from the artifact; a page makes no third-party request unless you write one.
81
+
82
+ ## MDX
83
+
84
+ `index.mdx` (or any page in `pages/`) is Markdown with JSX. The manifest is YAML frontmatter with the same fields:
85
+
86
+ ```mdx
87
+ ---
88
+ title: Release notes for 2.4
89
+ family: proposal
90
+ ---
91
+
92
+ import { Approve } from "./approve";
93
+
94
+ # What changed
95
+
96
+ <Approve />
97
+ ```
98
+
99
+ GitHub-flavoured Markdown (tables, task lists) works. MDX isn't type-checked.
100
+
101
+ ## Who and where
102
+
103
+ ```tsx
104
+ import { useArtifact, useViewer } from "@mostra/react";
105
+
106
+ function Greeting() {
107
+ const viewer = useViewer(); // { id, name?, source: "local" | "tailnet" | "token" | "host" }
108
+ const page = useArtifact(); // { id, versionId, version, viewId, mode: "live" | "static" | "mcp-app" | "verify" }
109
+ return <p>{viewer.name ? `Hello, ${viewer.name}.` : "Hello."} This is version {page.version}.</p>;
110
+ }
111
+ ```
112
+
113
+ `useViewer().name` is the person's name when the link or tailnet knows it. `mode` is `verify` while verify renders the page and `live` when a person opens it.
114
+
115
+ ## Sending the person elsewhere
116
+
117
+ The page runs in a frame that can't navigate the person's tab, so it can never replace Mostra's trusted controls. Use `openLink`, which opens `http:`, `https:`, `mailto:` and `tel:` URLs in a new tab:
118
+
119
+ ```tsx
120
+ import { openLink } from "@mostra/react";
121
+
122
+ function PullRequestLink() {
123
+ return <button onClick={() => void openLink("https://github.com/acme/app/pull/42")}>Open the pull request</button>;
124
+ }
125
+ ```
126
+
127
+ Plain `<a href target="_blank">` links work too.
128
+
129
+ ## Pages written for Claude
130
+
131
+ A page that uses Claude artifacts' `window.storage` works unchanged: `get`, `set`, `delete` and `list`, each with `shared`. Personal keys are the person's saved fields (`storage.<key>`), shared keys are the artifact's shared state. A value is at most 1 MiB. For new code, prefer `useField`, which verify understands and results label.
@@ -0,0 +1,146 @@
1
+ # Server code: actions, secrets and side effects
2
+
3
+ ## Contents
4
+
5
+ - Server functions
6
+ - Actions: `useAction`
7
+ - Side effects that happen once
8
+ - Secrets
9
+ - What server code can use: `@mostra/server`
10
+ - Verify and `dryRun()`
11
+ - Limits and crashes
12
+
13
+ ## Server functions
14
+
15
+ Any module whose first statement is `"use server"` runs on this machine, in a worker process of its own, with full Node.js: files, processes, the network, any npm package. It exports only async functions (async generators too). The page imports them like ordinary functions; Mostra sends the call to the worker.
16
+
17
+ ```ts
18
+ // actions.ts
19
+ "use server";
20
+ import { readFile } from "node:fs/promises";
21
+
22
+ export async function loadReport(name: string) {
23
+ return JSON.parse(await readFile(`data/${name}.json`, "utf8")); // relative to the artifact's directory
24
+ }
25
+ ```
26
+
27
+ ```tsx
28
+ // index.tsx
29
+ import { useState } from "react";
30
+ import { loadReport } from "./actions";
31
+
32
+ function Report() {
33
+ const [report, setReport] = useState<unknown>();
34
+ return <button onClick={async () => setReport(await loadReport("q3"))}>Load the Q3 report</button>;
35
+ }
36
+ ```
37
+
38
+ - Arguments and results are what React's Server Functions accept: JSON values, `Date`, `Map`, `Set`, `BigInt`, typed arrays, `FormData`, `File`, promises, plus async iterables as results. Functions and class instances don't cross (`MOSTRA_ACTION_UNSERIALIZABLE`).
39
+ - A thrown error reaches the page as a `MostraError` with `code: "MOSTRA_ACTION_THREW"` and the error's message; its stack goes to the run's log.
40
+ - Calling a function directly is a plain call: nothing is recorded, and a reload forgets it. Use it to read things. For anything that changes the world, use an action.
41
+
42
+ ## Actions: `useAction`
43
+
44
+ `useAction` makes every call a recorded **run** with progress, a log, a final state, and cancellation:
45
+
46
+ ```tsx
47
+ import { useAction } from "@mostra/react";
48
+ import { sendReply } from "./actions";
49
+
50
+ function Reply({ email, body }: { email: { id: string }; body: string }) {
51
+ const send = useAction(sendReply, { key: `reply-${email.id}` });
52
+ return (
53
+ <button disabled={send.isPending || send.status === "succeeded"} onClick={() => void send.run(email.id, body)}>
54
+ {send.status === "succeeded" ? "Sent" : send.isPending ? send.progress?.message ?? "Sending…" : "Send"}
55
+ </button>
56
+ );
57
+ }
58
+ ```
59
+
60
+ - **Without a `key`**, a second call while the first runs joins it, so a double click runs once.
61
+ - **With a `key`**, the run happens at most once, ever: every click, tab, reload and viewer with that key joins the same run and sees its progress and result. A run that failed stays failed; a new attempt needs a new key (`reply-${email.id}-retry-1`).
62
+ - The handle has `status` (`idle`, `queued`, `running`, `succeeded`, `failed`, `cancelled`), `isPending`, `data`, `error` (`{ code, message }`), `progress` (`{ fraction?, message? }`), `log`, `partial` (the items an async-iterable result yielded so far), `runId` and `cancel()`.
63
+ - `run()` resolves with the result or rejects with a `MostraError` whose `code` says why (`MOSTRA_ACTION_THREW`, `MOSTRA_ACTION_CANCELLED`, `MOSTRA_ACTION_INTERRUPTED`, `MOSTRA_RUNTIME_WORKER_PARKED`).
64
+ - A run keeps going when the tab closes. A page that loads later finds a keyed run again by its key.
65
+ - Results list the runs started in the submitting view, so you can see what the person did.
66
+
67
+ ## Side effects that happen once
68
+
69
+ A run cut off by a crash or a restart ends `failed` with `MOSTRA_ACTION_INTERRUPTED`, and Mostra never retries it: the email may or may not have gone. So for any external side effect, pass an idempotency key the provider understands, derived from the run's key, so the provider drops a repeat:
70
+
71
+ ```ts
72
+ "use server";
73
+ import { abortSignal, progress, secret } from "@mostra/server";
74
+
75
+ export async function sendReply(emailId: string, body: string) {
76
+ progress({ message: "Sending…" });
77
+ const response = await fetch("https://api.mail.example/v1/send", {
78
+ method: "POST",
79
+ headers: {
80
+ authorization: `Bearer ${secret("MAIL_TOKEN")}`,
81
+ "idempotency-key": `reply-${emailId}`, // the same key the page gave useAction
82
+ "content-type": "application/json",
83
+ },
84
+ body: JSON.stringify({ inReplyTo: emailId, body }),
85
+ signal: abortSignal, // cancel() aborts the request
86
+ });
87
+ if (!response.ok) throw new Error(`The mail service answered ${response.status}`);
88
+ return { sent: true };
89
+ }
90
+ ```
91
+
92
+ ## Secrets
93
+
94
+ Keep keys and tokens out of the source. Mostra stores each one in its home, read from stdin:
95
+
96
+ ```sh
97
+ mostra secret set MAIL_TOKEN --artifact ./inbox < mail-token.txt # this artifact only
98
+ mostra secret set CALENDAR_KEY < calendar-key.txt # every artifact in this home
99
+ mostra secret list --artifact ./inbox # names only, never values
100
+ mostra secret rm MAIL_TOKEN --artifact ./inbox # remove it
101
+ ```
102
+
103
+ Server code reads it with `secret("MAIL_TOKEN")`, synchronously; a missing one throws `MOSTRA_SECRET_MISSING`. Mostra redacts every value it hands out from logs, run logs, errors, events, results and live values, so returning or logging one shows `[redacted]`. A secret is the person's to store: ask them to run `mostra secret set` themselves, and never ask for the value in the conversation or in a page field.
104
+
105
+ ## What server code can use
106
+
107
+ Import these from `@mostra/server` inside a `"use server"` function or a live source:
108
+
109
+ | Function | Does |
110
+ |---|---|
111
+ | `progress({ fraction?, message? })` | Shows progress on the page's run |
112
+ | `log(line)` | Adds a line to the run's log (`console.log` goes there too) |
113
+ | `abortSignal` | Aborts when the run is cancelled; pass it to `fetch` and child processes |
114
+ | `secret(name)` | Reads a secret |
115
+ | `viewer()` | The person who called: `{ id, name? }` |
116
+ | `signal(name, payload?)` | Raises a signal you can `mostra wait <dir> --until signal:<name>` for |
117
+ | `emit("host.<name>", payload?)` | An event for the program hosting Mostra; pages never see it |
118
+ | `state.get(id)`, `state.set(id, value)`, `state.patch(ops)` | Reads and writes the artifact's shared fields ([long-lived.md](long-lived.md)) |
119
+ | `dryRun()` | True only while verify exercises the page |
120
+ | `defineLive` | Defines a live source in `live.ts` ([long-lived.md](long-lived.md)) |
121
+
122
+ Errors these throw are `MostraServerError`s with a `code`.
123
+
124
+ ## Verify and `dryRun()`
125
+
126
+ Verify clicks through the page but never runs a server function unless that function opts in by checking `dryRun()`:
127
+
128
+ ```ts
129
+ "use server";
130
+ import { dryRun } from "@mostra/server";
131
+
132
+ export async function archiveEmail(emailId: string) {
133
+ if (dryRun()) return { archived: emailId }; // verify: nothing archived, a realistic answer
134
+ // …archive it for real, then:
135
+ return { archived: emailId };
136
+ }
137
+ ```
138
+
139
+ A function that doesn't opt in is refused in verify, its click gets `MOSTRA_VERIFY_ACTION_SKIPPED` (a hint), and the verdict lists it under skipped actions. Opt in when the page's behavior after the action matters to what verify should see; keep real side effects behind the check.
140
+
141
+ ## Limits and crashes
142
+
143
+ - Arguments and results up to 16 MiB each, a run's log 1 MB, signals 64 KiB.
144
+ - A worker has a 1 GiB heap and is stopped when its event loop is blocked for 10 s; change them in the manifest's `limits` (`heapMb`, `watchdogMs`).
145
+ - A crashed worker restarts with backoff. After more than five crashes in ten minutes it stops (`MOSTRA_RUNTIME_WORKER_PARKED`, and the page says the server code keeps crashing); publish a fix to clear it.
146
+ - Workers stop after 10 idle minutes and start again on the next call. Keep nothing in module variables that must survive; use shared state or files.
@@ -0,0 +1,72 @@
1
+ # Sharing: links, people and devices
2
+
3
+ ## Contents
4
+
5
+ - The link
6
+ - One person, one link
7
+ - The three setups: local, tailnet share, public share
8
+ - Behind a public quick tunnel
9
+ - Managing links and shares
10
+ - Asking people well
11
+
12
+ ## The link
13
+
14
+ `mostra publish` prints the artifact's **default link**; `mostra open <dir>` prints it again and opens it in a browser when run at a terminal (`--no-browser` only prints it). The link is a capability URL: whoever holds it can view, answer, submit and run the page's actions. The secret is after the `#`, so it never reaches a server log, but treat the whole link like a password.
15
+
16
+ The default link doesn't expire and stays the same across versions. It opens on this machine only (`http://127.0.0.1:…`).
17
+
18
+ ## One person, one link
19
+
20
+ A link without a named person acts as one person: everyone who holds the default link shares one draft and one `once` submission. When several people should answer, mint one link per person:
21
+
22
+ ```sh
23
+ mostra open ./retro --new --viewer ada@example.com --viewer-name "Ada Lovelace" --no-browser
24
+ mostra open ./retro --new --viewer grace@example.com --viewer-name "Grace Hopper" --no-browser
25
+ ```
26
+
27
+ `--viewer` is your own stable key for the person (an email, a user ID); the same key always means the same person, and results name them. Use `{ policy: "once", scope: "per-viewer" }` so each of them submits once.
28
+
29
+ Other options of `mostra open <dir> --new`: `--ttl 24h` (the link expires), `--scope view` (look but not answer; also `draft`, `submit`, `review`, `signal`, `action:*`), `--version 3` (only that version).
30
+
31
+ ## The three setups
32
+
33
+ | Setup | Who can open it | Command |
34
+ |---|---|---|
35
+ | **Local** | Only this machine's browser | `mostra open <dir>` |
36
+ | **Tailnet share** | People and devices in your Tailscale network, such as your phone | `mostra share <dir> --tailnet` |
37
+ | **Public share** | Anyone with the link, on any device | `mostra share <dir> --public` |
38
+
39
+ - **Tailnet share** uses Tailscale Serve. Each person is their tailnet identity, so results name them without `--viewer`. The link doesn't expire unless you give `--ttl`. The output names the two ports the tailnet's access policy must allow, and the viewer's device must run Tailscale.
40
+ - **Public share** uses a Cloudflare quick tunnel by default (no account needed), or Tailscale Funnel with `--via funnel` (the URL shows your device's tailnet name). The link lasts 1 hour unless `--ttl` says otherwise, 7 days at most. Each public link is a visitor of its own: their answers never mix with yours or anyone else's, and results show them as "Shared link" unless you pass `--viewer`.
41
+ - Both drive tools installed on this machine (`tailscale`, `cloudflared`); when one is missing or signed out, the command says how to install or enable it (`MOSTRA_SHARE_TOOL_MISSING`, `MOSTRA_SHARE_TOOL_NOT_READY`, `MOSTRA_SHARE_NOT_ENABLED`).
42
+ - A share keeps Mostra running while it lasts. A quick tunnel can't keep its address across a restart, so a public Cloudflare share ends when Mostra restarts; tailnet and Funnel shares come back.
43
+
44
+ ## Behind a public quick tunnel
45
+
46
+ Over a Cloudflare quick tunnel the page runs in a slightly different mode, and nothing in your code needs to change for it:
47
+
48
+ - updates arrive by polling rather than streaming, so other people's edits and live values show up a second or two later;
49
+ - a streamed result (an async iterable) arrives in one piece at the end;
50
+ - the page can't register a service worker of its own (`MOSTRA_HYGIENE_FRAME_SESSION`).
51
+
52
+ ## Managing links and shares
53
+
54
+ ```sh
55
+ mostra share list # active shares, with their links
56
+ mostra share list --all # ended ones too, and why
57
+ mostra share stop <shareId> # or the artifact, for all of its shares; the link stops working
58
+ mostra open ./x --rotate <tokenId> # replace a link that leaked; the old one stops working
59
+ mostra open ./x --revoke <tokenId> # stop a link
60
+ ```
61
+
62
+ `--json` output carries each link's `tokenId`.
63
+
64
+ ## Asking people well
65
+
66
+ The link arrives as a message from you, so write it like one:
67
+
68
+ - Say who is asking and why ("I'm the coding agent working on the checkout redesign; I need your call between two layouts").
69
+ - Say what the page asks of them and how long it takes.
70
+ - Give a real deadline only if there is one.
71
+ - Ask for no passwords, keys or codes on a page; collect secrets through `mostra secret set` instead.
72
+ - Post a link somewhere public only if the page is meant for anyone.
@@ -0,0 +1,71 @@
1
+ # Verify: the verdict, screenshots and the dev preview
2
+
3
+ ## Contents
4
+
5
+ - What verify does
6
+ - Reading the verdict
7
+ - Errors, warnings and hints
8
+ - Screenshots and the ARIA snapshot
9
+ - Regressions between versions
10
+ - Publish and verify
11
+ - The dev preview: `mostra dev`
12
+
13
+ ## What verify does
14
+
15
+ `mostra verify <dir>` checks the artifact's current source without publishing it, in a sandbox that touches no one's answers and calls no host:
16
+
17
+ 1. **prepare** and **compile**: reads the manifest, resolves and installs packages, type-checks (TypeScript in strict mode, or with the artifact's own `tsconfig.json` settings), builds.
18
+ 2. **boot** and **render**: opens the page in a headless Chromium at 1280 × 800 and 390 × 844, with a fixed clock and reduced motion, waits until it's still (and until the calls, runs and live values it loads at mount have arrived), records page errors, console errors and failed requests, runs axe, takes an ARIA snapshot and a screenshot per size.
19
+ 3. **smoke**: clicks and types through the page's controls (up to 200 interactions or 60 s), checking that each does something and that nothing breaks. Server functions run only when they opt in through `dryRun()` ([server.md](server.md)); live sources run for real, and secrets resolve as they would.
20
+ 4. **regression**: compares with the last published version that passed ([below](#regressions-between-versions)).
21
+
22
+ It takes 10 to 30 s.
23
+
24
+ ## Reading the verdict
25
+
26
+ The human output prints `verify: pass` or `verify: fail`, each diagnostic with its hint, and the screenshots worth looking at. Exit code 0 is pass, 1 is fail. With `--json`, the result is:
27
+
28
+ ```json
29
+ {
30
+ "status": "pass",
31
+ "artifact": { "id": "art_…", "path": "…", "sourceDigest": "…", "envDigest": "…", "versionId": "ver_…" },
32
+ "diagnostics": [{ "code": "MOSTRA_…", "severity": "error", "message": "…", "hint": "…", "location": { "file": "index.tsx", "line": 12, "column": 7 }, "docs": "…" }],
33
+ "screenshots": [{ "viewport": "desktop", "path": "…/desktop.png", "width": 1280, "height": 800, "tokensEstimate": { "claude": 1334, "gpt": 1200, "gemini": 1120 }, "returned": false }],
34
+ "aria": [{ "viewport": "desktop", "path": "…/desktop.aria.yml", "summary": "3 headings, 1 button, 1 textbox, landmarks: main" }],
35
+ "smoke": { "interactions": 3, "skippedActions": [], "stateChanges": 3 },
36
+ "regressions": {},
37
+ "timingsMs": { "build": 36, "typecheck": 538, "render": 9548, "smoke": 2492, "total": 13898 }
38
+ }
39
+ ```
40
+
41
+ `status` is `fail` exactly when there is an error. Diagnostics come errors first; identical ones fold into one with a `count`. `mostra docs <CODE>` prints any code's page with an example fix.
42
+
43
+ ## Errors, warnings and hints
44
+
45
+ | Severity | Means | Examples |
46
+ |---|---|---|
47
+ | error | Something is definitely broken; publish refuses it | type and build errors, uncaught page errors, console errors, failed requests to the page's own origin, a blank page, a page that never gets ready, duplicate or unstable field IDs, a manifest that can't be read |
48
+ | warning | Worth checking; publish allows it | axe's serious findings, failed requests to other sites, a failing live source, a package without types, a secret the page needed that isn't set, every regression, a control with no visible effect |
49
+ | hint | Information | an input not bound to a field (`MOSTRA_FIELD_UNBOUND`, fine for a search box or a draft you don't want saved), an action skipped in verify, axe's minor findings, the smoke test's budget, no baseline yet |
50
+
51
+ Warnings that begin with **"Observed only"** (`MOSTRA_SMOKE_NO_EFFECT`, `MOSTRA_REGRESSION_*`) report what verify saw, such as a button whose click changed nothing visible or a page that changed since the last version. Look at the screenshot and decide; when the behavior is what you intended, change nothing.
52
+
53
+ Fix errors at their location, run verify again, and repeat until it passes. Fix the first error first: later ones are often its consequences.
54
+
55
+ ## Screenshots and the ARIA snapshot
56
+
57
+ Screenshots are always taken. `--screenshots on-failure` (the default) marks them `returned` only when verify fails; `always` marks them every time; `never` never does. The human output lists the returned ones. **Look at them before you publish**, on every round: verify can't tell you that the page looks wrong, only that it works. The design checks in [design.md](design.md#reading-your-screenshots) say what to look for.
58
+
59
+ The ARIA snapshot (`.aria.yml`) is the page as a screen reader sees it: headings, buttons, inputs and their names. Read it when you can't look at images: it shows what text and controls the page actually rendered.
60
+
61
+ ## Regressions between versions
62
+
63
+ From the second version on, verify renders the last published version that passed, in the same run, and compares: the ARIA snapshot, the pixels at each size, and the contract (fields, actions, live sources and pages that disappeared). A field you removed leaves people's answers behind, so `MOSTRA_REGRESSION_FIELD_REMOVED` is worth a second look; a layout change you made on purpose is expected.
64
+
65
+ ## Publish and verify
66
+
67
+ `mostra publish` reuses the verdict of the same source, or runs verify itself. It refuses a source whose verdict has errors (`MOSTRA_PUBLISH_VERIFY_FAILED`). `--force` publishes anyway and records the failing codes on the version; it never publishes a source that didn't build. Use it only when you know why the error doesn't matter. When the headless browser isn't available (`MOSTRA_ENV_BROWSER_MISSING`), verify still type-checks and builds, and the code's page says how to install the browser.
68
+
69
+ ## The dev preview: `mostra dev`
70
+
71
+ `mostra dev <dir>` serves the unpublished source with hot reload on this machine until Ctrl-C, and prints a link. Edits appear in the browser as you save; changed server code restarts its worker. Answers and submissions there go to a scratch store that's thrown away, and actions run for real with the real secrets. Nobody but you sees it: use it while building, then verify and publish.
@@ -1,4 +1,4 @@
1
- import { r as TelemetryStore, t as flush } from "../flush-CBN3AU9X.js";
1
+ import { r as TelemetryStore, t as flush } from "../flush-C16w3JL8.js";
2
2
  //#region src/telemetry/flush-main.ts
3
3
  /**
4
4
  * The flusher process (D140 item 6): `node flush-main.js <config dir>`, started detached by the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mostra/cli",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "The mostra command: author, verify, publish, share and wait on agent artifacts, as a thin client of the Mostra host protocol.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "The Mostra Authors",
@@ -34,17 +34,24 @@
34
34
  "provenance": true
35
35
  },
36
36
  "dependencies": {
37
- "@mostra/protocol": "0.7.0",
38
- "@mostra/sdk": "0.7.0",
37
+ "@hono/node-server": "2.1.5",
38
+ "@modelcontextprotocol/server": "2.4.0",
39
+ "@mostra/mcp": "0.9.0",
40
+ "@mostra/protocol": "0.9.0",
41
+ "@mostra/sdk": "0.9.0",
39
42
  "zod": "4.6.7"
40
43
  },
41
44
  "devDependencies": {
42
- "@mostra/runtime": "0.7.0",
45
+ "@modelcontextprotocol/client": "2.4.0",
46
+ "@modelcontextprotocol/conformance": "0.1.16",
47
+ "@modelcontextprotocol/conformance-next": "npm:@modelcontextprotocol/conformance@0.2.0-alpha.12",
48
+ "@mostra/runtime": "0.9.0",
43
49
  "@mostra/tools": "0.0.0",
44
50
  "@types/node": "24.19.2",
45
51
  "tsdown": "0.23.1",
46
52
  "typescript": "7.0.2",
47
- "vitest": "5.0.5"
53
+ "vitest": "5.0.5",
54
+ "yaml": "2.9.1"
48
55
  },
49
56
  "bin": {
50
57
  "mostra": "./dist/bin.js"
package/src/bootstrap.ts CHANGED
@@ -17,6 +17,7 @@ import { createDiagnostic, type Diagnostic, RpcError } from "@mostra/protocol";
17
17
  import { enclosingBundle, type InstallProgress, readPins, resolveRuntime } from "@mostra/sdk";
18
18
  import { exitCodeFor } from "./exit.ts";
19
19
  import type { Environment } from "./home.ts";
20
+ import { commandWords } from "./parse.ts";
20
21
 
21
22
  /** How the bootstrap talks to the terminal. */
22
23
  export interface BootstrapIo {
@@ -41,8 +42,19 @@ export function needsBootstrap(env: Environment): boolean {
41
42
  return readPins(env) !== undefined;
42
43
  }
43
44
 
45
+ /**
46
+ * Whether the command serves in this process instead of in the bundle (D164 item 7): `mostra mcp`
47
+ * answers its client at once and installs the bundle in the background, since a client gives a
48
+ * server only seconds to start (Codex 10 s) and a first install takes minutes.
49
+ */
50
+ export function servesBeforeBundle(argv: readonly string[]): boolean {
51
+ return commandWords(argv)[0] === "mcp";
52
+ }
53
+
44
54
  /** Progress lines for a person waiting on the first download. */
45
- function progressReporter(io: BootstrapIo): (progress: InstallProgress) => void {
55
+ export function progressReporter(
56
+ io: Pick<BootstrapIo, "stderr" | "stderrTty">,
57
+ ): (progress: InstallProgress) => void {
46
58
  let lastPercent = -1;
47
59
  let lastStep = "";
48
60
  return (progress) => {
@@ -88,7 +100,8 @@ function failed(io: BootstrapIo, diagnostic: Diagnostic): number {
88
100
 
89
101
  /**
90
102
  * When this copy needs the bundle its release pins (`needsBootstrap`), runs the bundle's
91
- * `mostra` with `io.argv` and resolves with its exit code; otherwise resolves `undefined`, and the
103
+ * `mostra` with `io.argv` and resolves with its exit code; otherwise, or for `mostra mcp`, which
104
+ * installs the bundle itself while it serves (`servesBeforeBundle`), resolves `undefined`, and the
92
105
  * caller runs the command itself. Any failure, deciding included, is a diagnostic (one envelope
93
106
  * with `--json`) and its exit code. Signals this process gets are passed on to the child.
94
107
  */
@@ -96,7 +109,7 @@ export async function bootstrap(io: BootstrapIo): Promise<number | undefined> {
96
109
  try {
97
110
  // Deciding is inside the boundary too: pins that can't be read are a diagnostic, never a
98
111
  // stack trace (GPT review finding 3).
99
- if (!needsBootstrap(io.env)) return undefined;
112
+ if (!needsBootstrap(io.env) || servesBeforeBundle(io.argv)) return undefined;
100
113
  return await runInBundle(io);
101
114
  } catch (error) {
102
115
  // Whatever goes wrong, `--json` still gets exactly one envelope (D140 item 16).
package/src/command.ts CHANGED
@@ -70,6 +70,11 @@ export interface CommandContext {
70
70
  readonly home: string;
71
71
  /** Records a telemetry event of this command (D140 item 8), when telemetry allows it. */
72
72
  record(event: TelemetryEventInput): void;
73
+ /**
74
+ * Queues the events recorded so far, for a command that runs until it is stopped (`mcp`);
75
+ * `hostInstance` says whether the instance it reached was host-spawned (then nothing is sent).
76
+ */
77
+ checkpoint(hostInstance: boolean): void;
73
78
  /**
74
79
  * The session with the home's instance, starting its daemon unless `autostart` is false; then
75
80
  * `undefined` when none runs. `call` uses the same session.
@@ -91,7 +96,7 @@ export interface CommandContext {
91
96
  /** A command-specific telemetry event: its name and its own fields. */
92
97
  export interface TelemetryEventInput {
93
98
  /** The event's name. */
94
- readonly event: "verify.result" | "publish.done" | "share.done";
99
+ readonly event: "verify.result" | "publish.done" | "share.done" | "mcp.session";
95
100
  /** Its own fields; the schema keeps only the published ones. */
96
101
  readonly fields: Readonly<Record<string, unknown>>;
97
102
  }
@@ -106,6 +111,8 @@ export interface CommandOutcome {
106
111
  readonly exit?: number;
107
112
  /** The command wrote its own stdout (`host`): the runner prints no envelope and no text. */
108
113
  readonly raw?: boolean;
114
+ /** The instance the command reached on a session of its own was host-spawned (`mcp`). */
115
+ readonly hostInstance?: boolean;
109
116
  }
110
117
 
111
118
  /** One command. */
@@ -130,8 +137,11 @@ export interface CommandDef {
130
137
  readonly local?: boolean;
131
138
  /** It writes a stream of events before its result (NDJSON in `--json` mode). */
132
139
  readonly streams?: boolean;
133
- /** Telemetry and its question leave it alone (`telemetry`, `docs`, D140 item 11). */
134
- readonly quiet?: boolean;
140
+ /**
141
+ * Telemetry and its question leave it alone (`telemetry`, `docs`, D140 item 11), or, as a
142
+ * function of its flags, when it runs on someone's behalf (`mcp --embedded`, D148).
143
+ */
144
+ readonly quiet?: boolean | ((flags: CommandContext["flags"]) => boolean);
135
145
  /** Does the command's work. */
136
146
  run(context: CommandContext): Promise<CommandOutcome>;
137
147
  }
@@ -4,7 +4,7 @@
4
4
  * files, except `doctor`, which reads what it needs to explain why an instance can't start.
5
5
  */
6
6
  import { spawn } from "node:child_process";
7
- import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
7
+ import { existsSync, readdirSync, statSync } from "node:fs";
8
8
  import { join } from "node:path";
9
9
  import {
10
10
  artifactGetMethod,
@@ -23,7 +23,7 @@ import {
23
23
  } from "@mostra/protocol";
24
24
  import { checkBrowser, checkFiles, enclosingBundle, readBundle, readSetup } from "@mostra/sdk";
25
25
  import { type CommandContext, type CommandDef, defineCommand } from "../command.ts";
26
- import { docsIndex, indexMarkdown, nearestTopics } from "../docs.ts";
26
+ import { docsIndex, indexMarkdown, nearestTopics, topicMarkdown } from "../docs.ts";
27
27
  import { EXIT, exitCodeFor } from "../exit.ts";
28
28
  import { embeddedHome, locateRuntime, readHomeMarks } from "../home.ts";
29
29
  import { usage } from "../parse.ts";
@@ -670,7 +670,8 @@ async function alwaysOnCheck(context: CommandContext): Promise<DoctorCheck> {
670
670
  /** `mostra docs [topic]`. */
671
671
  export const docsCommand: CommandDef = defineCommand({
672
672
  path: ["docs"],
673
- summary: "Print Mostra's reference: the CLI, telemetry, and every diagnostic code's page.",
673
+ summary:
674
+ "Print Mostra's reference: the guide to writing artifacts, the CLI, telemetry, and every diagnostic code's page.",
674
675
  args: [
675
676
  { name: "topic", summary: "A topic or a diagnostic code. Default: the index.", optional: true },
676
677
  ],
@@ -702,7 +703,7 @@ export const docsCommand: CommandDef = defineCommand({
702
703
  `No topic "${wanted}". The nearest: ${nearestTopics(wanted, topics).join(", ")}. Run "mostra docs" for the index.`,
703
704
  );
704
705
  }
705
- const markdown = readFileSync(found.file, "utf8");
706
+ const markdown = topicMarkdown(found);
706
707
  return { result: { topic: found.topic, markdown, url: found.url }, human: markdown };
707
708
  },
708
709
  });