@mostra/cli 0.9.0 → 0.10.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 (45) hide show
  1. package/dist/bin.js +2 -2
  2. package/dist/bootstrap-BStzS_41.js +1 -0
  3. package/dist/{bootstrap-Dc-SQHRF.js → bootstrap-_iCl_HaO.js} +3 -2
  4. package/dist/bootstrap-_iCl_HaO.js.map +1 -0
  5. package/dist/{flush-C16w3JL8.js → flush-znWmNZA1.js} +11 -3
  6. package/dist/flush-znWmNZA1.js.map +1 -0
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +2 -2
  10. package/dist/reference/cli.md +144 -4
  11. package/dist/reference/diagnostics.json +90 -0
  12. package/dist/reference/errors/MOSTRA_ARTIFACT_BUNDLE_INVALID.md +23 -0
  13. package/dist/reference/errors/MOSTRA_HOME_NETWORK_FILESYSTEM.md +23 -0
  14. package/dist/reference/errors/MOSTRA_REMOTE_CONFIG_INVALID.md +23 -0
  15. package/dist/reference/errors/MOSTRA_REMOTE_LOGIN_FAILED.md +23 -0
  16. package/dist/reference/errors/MOSTRA_REMOTE_NOT_OWNER_INSTANCE.md +23 -0
  17. package/dist/reference/errors/MOSTRA_REMOTE_OWNER_OFFLINE.md +23 -0
  18. package/dist/reference/errors/MOSTRA_REMOTE_QUEUE_FULL.md +23 -0
  19. package/dist/reference/errors/MOSTRA_REMOTE_RATE_LIMITED.md +23 -0
  20. package/dist/reference/errors/MOSTRA_REMOTE_SIGN_IN_REQUIRED.md +23 -0
  21. package/dist/reference/errors/MOSTRA_REMOTE_UNREACHABLE.md +23 -0
  22. package/dist/{run-DdYT3iHQ.js → run-Aq4HVIY0.js} +234 -15
  23. package/dist/run-Aq4HVIY0.js.map +1 -0
  24. package/dist/run-D1U_RFEP.js +1 -0
  25. package/dist/skill/SKILL.md +3 -3
  26. package/dist/skill/references/answers.md +36 -0
  27. package/dist/skill/references/mcp.md +3 -3
  28. package/dist/skill/references/sharing.md +54 -4
  29. package/dist/telemetry/flush-main.js +1 -1
  30. package/package.json +5 -5
  31. package/src/client.ts +1 -1
  32. package/src/commands/admin.ts +11 -1
  33. package/src/commands/authoring.ts +85 -3
  34. package/src/commands/index.ts +16 -3
  35. package/src/commands/remote.ts +113 -0
  36. package/src/commands/sharing.ts +33 -6
  37. package/src/commands/viewing.ts +20 -2
  38. package/src/detached.ts +2 -0
  39. package/src/exit.ts +2 -0
  40. package/src/telemetry/store.ts +15 -4
  41. package/dist/bootstrap-Dc-SQHRF.js.map +0 -1
  42. package/dist/bootstrap-aaE5wFo9.js +0 -1
  43. package/dist/flush-C16w3JL8.js.map +0 -1
  44. package/dist/run-Bw4_6kcW.js +0 -1
  45. package/dist/run-DdYT3iHQ.js.map +0 -1
@@ -0,0 +1 @@
1
+ export { t as run } from "./run-Aq4HVIY0.js";
@@ -4,7 +4,7 @@ description: Communicate visually with the user through Mostra. Use whenever sho
4
4
  license: Apache-2.0
5
5
  compatibility: Needs a shell that runs `mostra` (or `npx` with Node.js 22.19 or later) on macOS, Linux or Windows, x64 or arm64.
6
6
  metadata:
7
- version: "0.9.0"
7
+ version: "0.10.0"
8
8
  ---
9
9
 
10
10
  # Mostra
@@ -13,7 +13,7 @@ Mostra turns a React page you write into an **artifact**: a web page a person op
13
13
 
14
14
  ## Running Mostra
15
15
 
16
- Run `mostra <command>`. When `mostra` isn't on the `PATH`, run `npx -y @mostra/cli@0.9.0 <command>` everywhere this Skill says `mostra`; the first run downloads Mostra's own runtime (no global Node.js needed beyond `npx`). Every command takes `--json` (one JSON envelope on stdout, logs on stderr) and `--help`. `mostra docs <topic>` prints the reference, including every diagnostic code's page (`mostra docs MOSTRA_FIELD_DUPLICATE_ID`). `mostra list` lists the artifacts you've published, and `mostra status` shows the running instance.
16
+ Run `mostra <command>`. When `mostra` isn't on the `PATH`, run `npx -y @mostra/cli@0.10.0 <command>` everywhere this Skill says `mostra`; the first run downloads Mostra's own runtime (no global Node.js needed beyond `npx`). Every command takes `--json` (one JSON envelope on stdout, logs on stderr) and `--help`. `mostra docs <topic>` prints the reference, including every diagnostic code's page (`mostra docs MOSTRA_FIELD_DUPLICATE_ID`). `mostra list` lists the artifacts you've published, and `mostra status` shows the running instance.
17
17
 
18
18
  When Mostra's tools are in your tool list (`artifact_create`, `artifact_verify` and the rest), use them instead: each step below has its tool, and everything else here holds unchanged. See [references/mcp.md](references/mcp.md).
19
19
 
@@ -57,7 +57,7 @@ Each step ends when its check holds. Don't hand a link out before step 4 passes.
57
57
  Mostra draws the Submit button in its own frame around your page; `useSubmitControl` names it, and `required` fields block it until they're answered. Make it look considered: [references/design.md](references/design.md) has a baseline stylesheet and the rules for pages people answer. *Done when* every answer you need is a field with a label.
58
58
  4. **Verify until it passes.** `mostra verify <dir> --screenshots always`. It type-checks, builds, renders the page headlessly, clicks through it, runs an accessibility check and screenshots it at 1280×800 and 390×844. Fix every error, then **open both screenshots and look at them** (about 1,300 and 450 image tokens). Warnings that start with "Observed only" describe what verify saw; judge them, and leave working code alone. *Done when* the status is `pass` and the screenshots show what you meant at both sizes. More in [references/verify.md](references/verify.md).
59
59
  5. **Publish.** `mostra publish <dir>` prints the version and the capability URL. Publishing again after an edit makes a new version; open pages offer the person the new one, and answers carry over by field ID. *Done when* you have the link.
60
- 6. **Hand the link over.** Say who is asking and why, what the page is for, and roughly how long it takes. On this machine, `mostra open <dir>` opens it in the browser. For a phone or another person, see [references/sharing.md](references/sharing.md): one link is one person's draft, so give each person their own link. *Done when* the person has the link and knows what to do.
60
+ 6. **Hand the link over.** Say who is asking and why, what the page is for, and roughly how long it takes. For the person at this machine, `mostra open <dir> --browser` opens it in their browser, and its output says when none could be opened. For a phone or another person, see [references/sharing.md](references/sharing.md): one link is one person's draft, so give each person their own link. *Done when* the person has the link and knows what to do.
61
61
  7. **Wait for the answer.** `mostra wait <dir> --until submitted --timeout 10m`. Exit code 0 means submitted; 5 means still waiting, with nothing lost: wait again, or continue other work and check later. *Done when* it exits 0.
62
62
  8. **Read the results.** `mostra results <dir>` prints the submission as Markdown (`--format json` for JSON). Act on it. *Done when* you've used every answer.
63
63
 
@@ -6,6 +6,7 @@
6
6
  - Forms with react-hook-form
7
7
  - The trusted Submit and `useSubmit`
8
8
  - Submission policies
9
+ - Counts by choice
9
10
  - Signals
10
11
  - Choosing between candidates
11
12
  - Waiting
@@ -111,6 +112,41 @@ Request one in the manifest's `submission`; the host running Mostra decides (`mo
111
112
  | epochs | `{ policy: "epochs" }` | Rounds: the person submits, you reply with a new version, they submit again. Each round is kept and linked |
112
113
  | none | `{ policy: "none" }` | No Submit at all: dashboards, task lists, pages that talk through shared state, actions and signals ([long-lived.md](long-lived.md)) |
113
114
 
115
+ ### Approvals that do something
116
+
117
+ When approving should make something happen (place the order, write the config, send the mail), keep the approval a submission: it is the durable record of who approved what, it arrives in `mostra results`, and the person presses one trusted button.
118
+
119
+ 1. Use `once` and name the trusted Submit for the effect: `useSubmitControl({ label: "Approve and place the order", confirm: "Place the order for 3 laptops?" })`.
120
+ 2. `mostra wait <dir> --until submitted`, read `mostra results <dir>`, then do the effect yourself.
121
+ 3. Publish a new version, or set shared state, that says it's done, so the person sees the outcome.
122
+
123
+ When the effect must happen the moment they press, even while you aren't waiting, run it from the page with `useAction(fn, { key })` (a key makes it happen once, [server.md](server.md)), and still submit with the trusted Submit: `results` lists the run under `actions`. Choosing `none` with a signal instead leaves no submission and no trusted control, so nothing records the approval.
124
+
125
+ ## Counts by choice
126
+
127
+ To show everyone how a fixed-choice question is going ("12 for Ship, 4 for Wait"), name the field in the manifest's `tally`. Mostra counts each submission's answer as it is accepted and sends the counts to every open page, with no server code:
128
+
129
+ ```tsx
130
+ import { defineArtifact, useField, useLive } from "@mostra/react";
131
+
132
+ export const artifact = defineArtifact({
133
+ title: "Ship the redesign?",
134
+ submission: { policy: "once", scope: "per-viewer" },
135
+ tally: [{ field: "decision", choices: ["ship", "wait", "drop"], minTotal: 5 }],
136
+ });
137
+
138
+ function Decision() {
139
+ const [decision, setDecision] = useField("decision", "");
140
+ const tally = useLive("$tally/decision"); // data: { counts?: { ship, wait, drop }, total }
141
+ // …radio buttons for the three choices…
142
+ return <p>{tally.data?.counts ? `${tally.data.counts.ship} for Ship` : `${tally.data?.total ?? 0} answers so far`}</p>;
143
+ }
144
+ ```
145
+
146
+ - Counts are of answers, never of people, and only of the listed `choices` (2 to 50): any other value counts nothing, so what someone typed never shows. Counts only grow.
147
+ - Below `minTotal` (default 0) a page gets only `total`, so with a handful of answers no one can tell how each person answered.
148
+ - The field is a viewer field (each person's own answer), and the counts come from submissions, so the policy must submit (`once` per viewer or `epochs`).
149
+
114
150
  ## Signals
115
151
 
116
152
  A signal tells you something happened without submitting: "Ping the agent", "I'm stuck", "Regenerate this section".
@@ -22,7 +22,7 @@ Use Mostra's tools when they're in your tool list (`artifact_create`, `artifact_
22
22
  | Write | your own file tools | `artifact_write` (whole files), `artifact_patch` (exact replacements or a unified diff) |
23
23
  | Verify | `mostra verify <dir>` | `artifact_verify`; `screenshots: "always"` returns both screenshots as images |
24
24
  | Publish | `mostra publish <dir>` | `artifact_publish`; its `url` is the default link |
25
- | Hand out the link | `mostra open <dir>` | `artifact_open` |
25
+ | Hand out the link | `mostra open <dir> --browser` | `artifact_open` |
26
26
  | Wait | `mostra wait <dir> --until submitted` | `artifact_wait` with `until: "submitted"` |
27
27
  | Read the answers | `mostra results <dir>` | `artifact_results` (Markdown; `format: "json"` for the full structure) |
28
28
 
@@ -54,10 +54,10 @@ Links open on this computer only. To reach someone elsewhere, share it as [shari
54
54
 
55
55
  ## Adding the server to a client
56
56
 
57
- A client starts the server as `mostra mcp` over stdio, or `npx -y @mostra/cli@0.9.0 mcp` where `mostra` isn't installed. Its configuration names that command, for example:
57
+ A client starts the server as `mostra mcp` over stdio, or `npx -y @mostra/cli@0.10.0 mcp` where `mostra` isn't installed. Its configuration names that command, for example:
58
58
 
59
59
  ```json
60
- { "mcpServers": { "mostra": { "command": "npx", "args": ["-y", "@mostra/cli@0.9.0", "mcp"] } } }
60
+ { "mcpServers": { "mostra": { "command": "npx", "args": ["-y", "@mostra/cli@0.10.0", "mcp"] } } }
61
61
  ```
62
62
 
63
63
  For a client that speaks only HTTP, `mostra mcp --http` serves Streamable HTTP on `127.0.0.1` and prints its URL and a token on stderr; every request sends `Authorization: Bearer <token>` (set `MOSTRA_MCP_TOKEN` to choose it). `--workspace <dir>` chooses where new artifacts go.
@@ -4,14 +4,16 @@
4
4
 
5
5
  - The link
6
6
  - One person, one link
7
- - The three setups: local, tailnet share, public share
7
+ - The four setups: local, tailnet share, public share, hosted
8
+ - Hosted on a server
8
9
  - Behind a public quick tunnel
9
10
  - Managing links and shares
11
+ - Moving a version to another machine
10
12
  - Asking people well
11
13
 
12
14
  ## The link
13
15
 
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.
16
+ `mostra publish` prints the artifact's **default link**; `mostra open <dir>` prints it again; `--browser` also opens it in this machine's browser (without it, only a terminal opens one), and stderr says when no browser opened. 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
17
 
16
18
  The default link doesn't expire and stays the same across versions. It opens on this machine only (`http://127.0.0.1:…`).
17
19
 
@@ -28,19 +30,56 @@ mostra open ./retro --new --viewer grace@example.com --viewer-name "Grace Hopper
28
30
 
29
31
  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
32
 
31
- ## The three setups
33
+ ## The four setups
32
34
 
33
35
  | Setup | Who can open it | Command |
34
36
  |---|---|---|
35
- | **Local** | Only this machine's browser | `mostra open <dir>` |
37
+ | **Local** | Only this machine's browser | `mostra open <dir> --browser` |
36
38
  | **Tailnet share** | People and devices in your Tailscale network, such as your phone | `mostra share <dir> --tailnet` |
37
39
  | **Public share** | Anyone with the link, on any device | `mostra share <dir> --public` |
40
+ | **Hosted** | Anyone with the link, even while this machine sleeps | `mostra share <dir> --cloud` |
38
41
 
39
42
  - **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
43
  - **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
44
  - 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
45
  - 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
46
 
47
+ ## Hosted on a server
48
+
49
+ `mostra share <dir> --cloud` puts the latest version on a remote server this machine signed in to, and prints a link there. The page keeps taking answers while this machine is off: they wait on the server and reach `mostra wait` and `mostra results` here when Mostra runs again, the same as local answers. Every later `mostra publish` of the artifact goes to the server too.
50
+
51
+ ```sh
52
+ mostra login https://api.example.com # once per machine: open the address it prints and approve the code
53
+ mostra share ./x --cloud # host it there; prints the hosted link
54
+ mostra status # the servers this machine is linked to, and whether they're connected
55
+ mostra logout # sign out; hosted pages keep working, answers wait for the next login
56
+ ```
57
+
58
+ - The person answering sees "Your answer was sent." once the server has it, and nothing about this machine. You see the delivery states.
59
+ - Only the source, its versions and its secrets stay on this machine; the server holds the built page and what people enter.
60
+ - Several machines can sign in to one account. The one that shared a page receives its answers. `mostra login <server> --default` makes this machine the one pages created from a chat app go to.
61
+ - `mostra share stop` and `mostra share list` include hosted shares.
62
+
63
+ ### Actions on a hosted page
64
+
65
+ A hosted page's actions run on this machine, with its secrets, while it is connected. The manifest's `hosted` key says how they behave on the server:
66
+
67
+ ```tsx
68
+ export const artifact = defineArtifact({
69
+ title: "Proposal",
70
+ hosted: {
71
+ actions: "link", // who may press them: "signed-in" (default) or anyone with the link
72
+ offline: { actions: "queue", limit: "24h" }, // while this machine is off: wait ("queue", default) or fail at once ("fail")
73
+ },
74
+ });
75
+ ```
76
+
77
+ - By default only people the link names (`--viewer`) or who signed in may run actions; `actions: "link"` lets anyone with the link run them.
78
+ - While this machine is off, a pressed action waits: `useAction`'s `status` is `"waiting"`, and it runs once, in order, when Mostra runs here again. Past `limit` (at most `7d`) a run that never started fails. Under `"fail"` it fails at once.
79
+ - If the connection drops while an action runs and this machine never reports how it ended within the limit, its `status` becomes `"unknown"`: it may have happened, so show that rather than "failed". `run()` rejects with `MOSTRA_REMOTE_OWNER_OFFLINE`; the real end replaces `unknown` if it arrives later.
80
+ - A plain server function (called directly, not through `useAction`) answers `MOSTRA_REMOTE_OWNER_OFFLINE` while this machine is off.
81
+ - Live values show the last value, with `ownerOffline` set, while this machine is off.
82
+
44
83
  ## Behind a public quick tunnel
45
84
 
46
85
  Over a Cloudflare quick tunnel the page runs in a slightly different mode, and nothing in your code needs to change for it:
@@ -61,6 +100,17 @@ mostra open ./x --revoke <tokenId> # stop a link
61
100
 
62
101
  `--json` output carries each link's `tokenId`.
63
102
 
103
+ ## Moving a version to another machine
104
+
105
+ A published version can move whole to another Mostra home, where it is the same version with the same IDs, and its actions run there:
106
+
107
+ ```sh
108
+ mostra export ./x --out ./x.tar.zst # the latest version; --version 2 for another
109
+ mostra run ./x.tar.zst # on the other machine: imports it and prints its link
110
+ ```
111
+
112
+ The bundle holds the version's builds, manifest, lockfile and source, never secrets: set the secrets its actions read on the other machine with `mostra secret set`. Answers stay in the home where people gave them.
113
+
64
114
  ## Asking people well
65
115
 
66
116
  The link arrives as a message from you, so write it like one:
@@ -1,4 +1,4 @@
1
- import { r as TelemetryStore, t as flush } from "../flush-C16w3JL8.js";
1
+ import { r as TelemetryStore, t as flush } from "../flush-znWmNZA1.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.9.0",
3
+ "version": "0.10.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",
@@ -36,16 +36,16 @@
36
36
  "dependencies": {
37
37
  "@hono/node-server": "2.1.5",
38
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
+ "@mostra/mcp": "0.10.0",
40
+ "@mostra/protocol": "0.10.0",
41
+ "@mostra/sdk": "0.10.0",
42
42
  "zod": "4.6.7"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@modelcontextprotocol/client": "2.4.0",
46
46
  "@modelcontextprotocol/conformance": "0.1.16",
47
47
  "@modelcontextprotocol/conformance-next": "npm:@modelcontextprotocol/conformance@0.2.0-alpha.12",
48
- "@mostra/runtime": "0.9.0",
48
+ "@mostra/runtime": "0.10.0",
49
49
  "@mostra/tools": "0.0.0",
50
50
  "@types/node": "24.19.2",
51
51
  "tsdown": "0.23.1",
package/src/client.ts CHANGED
@@ -37,7 +37,7 @@ export interface InstanceSummary {
37
37
  /** Its process ID. */
38
38
  readonly pid: number;
39
39
  /** `daemon`, or `host` for an instance a host spawned (telemetry sends nothing then, D140). */
40
- readonly mode: "host" | "daemon";
40
+ readonly mode: "host" | "daemon" | "hosted";
41
41
  /** The runtime's release. */
42
42
  readonly version: string;
43
43
  /** Whether this command started the daemon. */
@@ -163,7 +163,17 @@ export const statusCommand: CommandDef = defineCommand({
163
163
  return { result: detail, human: `${detail.id} ${detail.title}\n${versions}` };
164
164
  }
165
165
  const status = await context.call(instanceStatusMethod, {});
166
- return { result: status, human: pretty(status) };
166
+ // Each remote server this home is linked to, by its state (INTERFACES §18.7).
167
+ const links = (status.links ?? [])
168
+ .map(
169
+ (link) =>
170
+ `${link.server} ${link.state}${link.default ? " default" : ""}${link.pendingPushes > 0 ? ` ${link.pendingPushes} pushes waiting` : ""}${link.lastError ? ` (${link.lastError})` : ""}\n`,
171
+ )
172
+ .join("");
173
+ return {
174
+ result: status,
175
+ human: `${pretty(status)}${links ? `\nRemote servers:\n${links}` : ""}`,
176
+ };
167
177
  },
168
178
  });
169
179
 
@@ -1,12 +1,15 @@
1
1
  /**
2
- * Authoring: `new`, `verify`, `publish` and `add`, thin clients of `artifact/create`,
3
- * `artifact/verify`, `artifact/publish` and `deps/add` (INTERFACES §6).
2
+ * Authoring: `new`, `verify`, `publish`, `export`, `run` and `add`, thin clients of
3
+ * `artifact/create`, `artifact/verify`, `artifact/publish`, `artifact/export`, `artifact/import`
4
+ * and `deps/add` (INTERFACES §6, §15).
4
5
  */
5
6
  import { randomUUID } from "node:crypto";
6
7
  import { resolve } from "node:path";
7
8
  import {
8
9
  ARTIFACT_PROGRESS,
9
10
  artifactCreateMethod,
11
+ artifactExportMethod,
12
+ artifactImportMethod,
10
13
  artifactPublishMethod,
11
14
  artifactVerifyMethod,
12
15
  depsAddMethod,
@@ -16,7 +19,7 @@ import {
16
19
  import { type CommandDef, defineCommand } from "../command.ts";
17
20
  import { EXIT } from "../exit.ts";
18
21
  import { usage } from "../parse.ts";
19
- import { arg, flag, sourceRef } from "./shared.ts";
22
+ import { arg, artifactRef, flag, sourceRef } from "./shared.ts";
20
23
 
21
24
  /** `mostra new <dir>`. */
22
25
  export const newCommand: CommandDef = defineCommand({
@@ -197,6 +200,85 @@ export const publishCommand: CommandDef = defineCommand({
197
200
  },
198
201
  });
199
202
 
203
+ /** `mostra export <artifact> --as bundle --out <path>`. */
204
+ export const exportCommand: CommandDef = defineCommand({
205
+ path: ["export"],
206
+ summary: "Write a published version out of the home, as a portable bundle another home can run.",
207
+ args: [{ name: "artifact", summary: "The artifact: its source path or its ID." }],
208
+ flags: [
209
+ {
210
+ name: "as",
211
+ kind: "string",
212
+ value: "<class>",
213
+ choices: ["bundle"],
214
+ default: "bundle",
215
+ summary: "What to write: `bundle`, the version's builds, manifest, lockfile and source.",
216
+ },
217
+ {
218
+ name: "out",
219
+ kind: "string",
220
+ value: "<path>",
221
+ summary: "Where: a new directory, or one archive when it ends in .tar.zst.",
222
+ },
223
+ {
224
+ name: "version",
225
+ kind: "string",
226
+ value: "<number|id>",
227
+ summary: "The version. Default: the latest.",
228
+ },
229
+ ],
230
+ output: { type: "ArtifactExportResult", topic: "cli" },
231
+ exits: [EXIT.failure],
232
+ example: "export ./sidebar-review --out ./sidebar-review.tar.zst",
233
+ async run(context) {
234
+ const out = flag(context, "out");
235
+ if (out === undefined) throw usage('"mostra export" needs --out <path>.');
236
+ const version = flag(context, "version");
237
+ const result = await context.call(artifactExportMethod, {
238
+ artifact: artifactRef(arg(context, "artifact"), context.cwd),
239
+ as: "bundle",
240
+ out: resolve(context.cwd, out),
241
+ ...(version !== undefined
242
+ ? { version: /^\d+$/.test(version) ? Number(version) : version }
243
+ : {}),
244
+ });
245
+ return {
246
+ result,
247
+ human: `Exported ${result.versionId} to ${result.files.join(", ")}\n`,
248
+ };
249
+ },
250
+ });
251
+
252
+ /** `mostra run <bundle>`. */
253
+ export const runCommand: CommandDef = defineCommand({
254
+ path: ["run"],
255
+ summary:
256
+ "Make a bundle `mostra export` wrote a version of this home, with the same IDs, and print its link.",
257
+ args: [{ name: "bundle", summary: "The bundle: its directory or its .tar.zst archive." }],
258
+ flags: [
259
+ {
260
+ name: "request-id",
261
+ kind: "string",
262
+ value: "<id>",
263
+ summary: "Make a retry return the first attempt's receipt.",
264
+ },
265
+ ],
266
+ output: { type: "PublishReceipt", topic: "cli" },
267
+ exits: [EXIT.failure],
268
+ example: "run ./sidebar-review.tar.zst",
269
+ async run(context) {
270
+ const requestId = flag(context, "request-id");
271
+ const receipt = await context.call(artifactImportMethod, {
272
+ bundle: resolve(context.cwd, arg(context, "bundle")),
273
+ ...(requestId !== undefined ? { requestId } : {}),
274
+ });
275
+ return {
276
+ result: receipt,
277
+ human: `${receipt.reused ? "Already here" : "Imported"}: version ${receipt.version} (${receipt.versionId}) of ${receipt.artifactId}\n${receipt.url ?? ""}\n`,
278
+ };
279
+ },
280
+ });
281
+
200
282
  /** `mostra add <package…>`. */
201
283
  export const addCommand: CommandDef = defineCommand({
202
284
  path: ["add"],
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * Every command of `mostra` (D60, D140 item 13), in the order help lists them. Commands later
3
- * packages own (`review export`, `export`, `plugin`, `term`, `run`) join this list with their
4
- * packages, never as placeholders; `share` joined with WP-13 and `mcp` with WP-15.
3
+ * packages own (`review export`, `plugin`, `term`) join this list with their
4
+ * packages, never as placeholders; `share` joined with WP-13, `mcp` with WP-15, and `export` (its `bundle` class) and `run`
5
+ * with WP-29.
5
6
  */
6
7
  import type { CommandDef } from "../command.ts";
7
8
  import {
@@ -24,7 +25,14 @@ import {
24
25
  telemetryOnCommand,
25
26
  telemetryStatusCommand,
26
27
  } from "./admin.ts";
27
- import { addCommand, newCommand, publishCommand, verifyCommand } from "./authoring.ts";
28
+ import {
29
+ addCommand,
30
+ exportCommand,
31
+ newCommand,
32
+ publishCommand,
33
+ runCommand,
34
+ verifyCommand,
35
+ } from "./authoring.ts";
28
36
  import { devCommand } from "./dev.ts";
29
37
  import {
30
38
  pushCommand,
@@ -35,6 +43,7 @@ import {
35
43
  waitCommand,
36
44
  } from "./interaction.ts";
37
45
  import { mcpCommand } from "./mcp.ts";
46
+ import { loginCommand, logoutCommand } from "./remote.ts";
38
47
  import { shareCommand, shareListCommand, shareStopCommand } from "./sharing.ts";
39
48
  import { openCommand } from "./viewing.ts";
40
49
 
@@ -48,6 +57,8 @@ export const COMMANDS: readonly CommandDef[] = [
48
57
  shareCommand,
49
58
  shareStopCommand,
50
59
  shareListCommand,
60
+ loginCommand,
61
+ logoutCommand,
51
62
  waitCommand,
52
63
  resultsCommand,
53
64
  stateGetCommand,
@@ -55,6 +66,8 @@ export const COMMANDS: readonly CommandDef[] = [
55
66
  statePatchCommand,
56
67
  pushCommand,
57
68
  addCommand,
69
+ exportCommand,
70
+ runCommand,
58
71
  secretSetCommand,
59
72
  secretListCommand,
60
73
  secretRmCommand,
@@ -0,0 +1,113 @@
1
+ /**
2
+ * `mostra login` and `mostra logout` (INTERFACES §18.7, D165 items 2, 15): this home signs in to a
3
+ * remote server by the OAuth device authorization grant, so `mostra share --cloud` can host its
4
+ * artifacts there, and signs out again. The instance keeps the refresh token in the home,
5
+ * owner-only; signing out keeps its instance link, so the artifacts it shared stay its own at the
6
+ * next sign-in, unless `--forget`. Clients of `remote/login`, `remote/login.wait` and
7
+ * `remote/logout`.
8
+ */
9
+ import { remoteLoginMethod, remoteLoginWaitMethod, remoteLogoutMethod } from "@mostra/protocol";
10
+ import { type CommandDef, defineCommand } from "../command.ts";
11
+ import { EXIT } from "../exit.ts";
12
+
13
+ /** How long `mostra login` waits for the person to approve, in all (the code lives 10 minutes). */
14
+ const LOGIN_WAIT_MS = 10 * 60_000;
15
+ /** Each wait asks the instance for this long, so a slow approval never meets a request timeout. */
16
+ const LOGIN_STEP_MS = 30_000;
17
+
18
+ /** `mostra login [<server>] [--default]`. */
19
+ export const loginCommand: CommandDef = defineCommand({
20
+ path: ["login"],
21
+ summary:
22
+ "Sign this machine's Mostra in to a remote server, so mostra share --cloud can host pages there.",
23
+ args: [
24
+ {
25
+ name: "server",
26
+ summary:
27
+ "The server's address, such as https://api.example.com. Default: the server signed in to last.",
28
+ optional: true,
29
+ },
30
+ ],
31
+ flags: [
32
+ {
33
+ name: "default",
34
+ kind: "boolean",
35
+ summary:
36
+ "Make this machine the account's default, the one chat apps create pages on. Default: the first machine linked.",
37
+ },
38
+ ],
39
+ output: { type: "RemoteLoginWaitResult", topic: "cli" },
40
+ exits: [EXIT.failure, EXIT.environment],
41
+ example: "login https://api.example.com",
42
+ async run(context) {
43
+ const server = context.args["server"];
44
+ const started = await context.call(remoteLoginMethod, {
45
+ ...(typeof server === "string" ? { server: server.replace(/\/+$/, "") } : {}),
46
+ ...(context.flags["default"] === true ? { default: true } : {}),
47
+ });
48
+ const where = started.verificationUriComplete ?? started.verificationUri;
49
+ context.emit(
50
+ { kind: "code", ...started },
51
+ `Open ${where} and check that it shows the code ${started.userCode}, then approve.\nWaiting for you to approve…`,
52
+ );
53
+ const deadline = Date.now() + LOGIN_WAIT_MS;
54
+ for (;;) {
55
+ const waited = await context.call(remoteLoginWaitMethod, {
56
+ loginId: started.loginId,
57
+ timeoutMs: Math.max(0, Math.min(LOGIN_STEP_MS, deadline - Date.now())),
58
+ });
59
+ if (waited.status === "signed-in") {
60
+ return {
61
+ result: waited,
62
+ human: `Signed in to ${waited.server} as ${waited.account.name ?? waited.account.id}. This machine is ${waited.instanceId}.\n`,
63
+ };
64
+ }
65
+ if (Date.now() >= deadline) {
66
+ return {
67
+ result: waited,
68
+ human: "The code wasn't approved in time. Run mostra login again for a new one.\n",
69
+ exit: EXIT.timeout,
70
+ };
71
+ }
72
+ }
73
+ },
74
+ });
75
+
76
+ /** `mostra logout [<server>] [--forget]`. */
77
+ export const logoutCommand: CommandDef = defineCommand({
78
+ path: ["logout"],
79
+ summary:
80
+ "Sign this machine's Mostra out of a remote server; its hosted pages keep working, and their answers wait for the next sign-in.",
81
+ args: [
82
+ {
83
+ name: "server",
84
+ summary: "The server's address. Default: the server signed in to last.",
85
+ optional: true,
86
+ },
87
+ ],
88
+ flags: [
89
+ {
90
+ name: "forget",
91
+ kind: "boolean",
92
+ summary:
93
+ "Also forget this machine's link to the server: the pages it shared there are no longer its own.",
94
+ },
95
+ ],
96
+ output: { type: "RemoteLogoutResult", topic: "cli" },
97
+ exits: [EXIT.failure, EXIT.environment],
98
+ example: "logout",
99
+ async run(context) {
100
+ const server = context.args["server"];
101
+ const result = await context.call(remoteLogoutMethod, {
102
+ ...(typeof server === "string" ? { server: server.replace(/\/+$/, "") } : {}),
103
+ ...(context.flags["forget"] === true ? { forget: true } : {}),
104
+ });
105
+ return {
106
+ result,
107
+ human:
108
+ result.servers.length === 0
109
+ ? "This machine wasn't signed in to a server.\n"
110
+ : `Signed out of ${result.servers.join(", ")}.\n`,
111
+ };
112
+ },
113
+ });
@@ -2,7 +2,8 @@
2
2
  * `mostra share`: an artifact opened to people beyond this machine through a tunnel the daemon
3
3
  * runs (D47, D158): `--tailnet` (Tailscale Serve, inside your tailnet, with each person's
4
4
  * identity) or `--public` (a Cloudflare quick tunnel by default, or Tailscale Funnel with `--via
5
- * funnel`), whose link expires (1 hour by default, 7 days at most). The share lives in the
5
+ * funnel`), whose link expires (1 hour by default, 7 days at most); or `--cloud` (D165 item 15),
6
+ * hosted on a remote server this home signed in to, so the link works while this machine sleeps. The share lives in the
6
7
  * daemon, so the command returns at once with the link; `share stop` ends it and `share list`
7
8
  * shows what is shared. A client of `share/start`, `share/stop` and `share/list`.
8
9
  */
@@ -26,6 +27,7 @@ const THROUGH: Readonly<Record<ShareVia, string>> = {
26
27
  tailnet: "Tailscale Serve, inside your tailnet",
27
28
  funnel: "Tailscale Funnel, public",
28
29
  cloudflare: "a Cloudflare quick tunnel, public",
30
+ remote: "a remote server, hosted",
29
31
  };
30
32
 
31
33
  /**
@@ -58,9 +60,22 @@ function line(share: Share): string {
58
60
  export const shareCommand: CommandDef = defineCommand({
59
61
  path: ["share"],
60
62
  summary:
61
- "Open an artifact to people beyond this machine: inside your tailnet, or publicly with a link that expires.",
62
- args: [{ name: "artifact", summary: "The artifact: its source path or its ID." }],
63
+ "Open an artifact to people beyond this machine: inside your tailnet, publicly with a link that expires, or hosted on a server.",
64
+ args: [
65
+ { name: "artifact", summary: "The artifact: its source path or its ID." },
66
+ {
67
+ name: "server",
68
+ summary: "With --cloud: the server's address. Default: the server signed in to last.",
69
+ optional: true,
70
+ },
71
+ ],
63
72
  flags: [
73
+ {
74
+ name: "cloud",
75
+ kind: "boolean",
76
+ summary:
77
+ "Host it on a remote server you signed in to with mostra login: the link keeps working while this machine sleeps.",
78
+ },
64
79
  {
65
80
  name: "tailnet",
66
81
  kind: "boolean",
@@ -115,16 +130,26 @@ export const shareCommand: CommandDef = defineCommand({
115
130
  ],
116
131
  output: { type: "ShareStartResult", topic: "cli" },
117
132
  exits: [EXIT.failure, EXIT.environment],
118
- example: "share ./sidebar-review --public --ttl 2h",
133
+ example: "share ./sidebar-review --cloud",
119
134
  async run(context) {
120
135
  const artifact = artifactRef(arg(context, "artifact"), context.cwd);
121
136
  const tailnet = context.flags["tailnet"] === true;
122
137
  const publicly = context.flags["public"] === true;
123
- if (tailnet === publicly) throw usage("Give --tailnet or --public.");
138
+ const cloud = context.flags["cloud"] === true;
139
+ if ([tailnet, publicly, cloud].filter(Boolean).length !== 1)
140
+ throw usage("Give one of --tailnet, --public or --cloud.");
124
141
  const viaFlag = flag(context, "via");
125
142
  if (viaFlag !== undefined && !publicly)
126
143
  throw usage("--via chooses a public tunnel: add --public.");
127
- const via: ShareVia = tailnet ? "tailnet" : viaFlag === "funnel" ? "funnel" : "cloudflare";
144
+ const server = context.args["server"];
145
+ if (server !== undefined && !cloud) throw usage("A server names where --cloud hosts it.");
146
+ const via: ShareVia = cloud
147
+ ? "remote"
148
+ : tailnet
149
+ ? "tailnet"
150
+ : viaFlag === "funnel"
151
+ ? "funnel"
152
+ : "cloudflare";
128
153
  const ttl = flag(context, "ttl");
129
154
  const scopes = context.flags["scope"] as readonly string[] | undefined;
130
155
  const viewerRef = flag(context, "viewer");
@@ -135,6 +160,7 @@ export const shareCommand: CommandDef = defineCommand({
135
160
  const share = await context.call(shareStartMethod, {
136
161
  artifact,
137
162
  via,
163
+ ...(typeof server === "string" ? { server: server.replace(/\/+$/, "") } : {}),
138
164
  ...(ttl !== undefined ? { ttl: ttl as `${number}${"s" | "m" | "h" | "d"}` } : {}),
139
165
  ...(scopes !== undefined ? { scopes: scopes as CapabilityScope[] } : {}),
140
166
  ...(viewerRef !== undefined
@@ -144,6 +170,7 @@ export const shareCommand: CommandDef = defineCommand({
144
170
  });
145
171
  context.record({ event: "share.done", fields: { kind: via } });
146
172
  const until = share.expiresAt ? `until ${share.expiresAt}` : "until you stop it";
173
+ // A hosted page keeps working while this machine sleeps: its answers wait for it (D165).
147
174
  return {
148
175
  result: share,
149
176
  human: `${share.url}\nShared through ${THROUGH[via]}, ${until}.\n${via === "tailnet" ? tailnetReach(share) : ""}Stop it with: mostra share stop ${share.shareId}\n`,