@mostra/cli 0.10.0 → 0.12.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-_iCl_HaO.js → bootstrap-3_Tdfdg7.js} +3 -2
  3. package/dist/bootstrap-3_Tdfdg7.js.map +1 -0
  4. package/dist/bootstrap-C9a2gSWf.js +1 -0
  5. package/dist/{flush-znWmNZA1.js → flush-TPaIdwjy.js} +3 -1
  6. package/dist/flush-TPaIdwjy.js.map +1 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +2 -2
  9. package/dist/reference/cli.md +178 -2
  10. package/dist/reference/diagnostics.json +108 -0
  11. package/dist/reference/errors/MOSTRA_ACTION_PAUSED.md +23 -0
  12. package/dist/reference/errors/MOSTRA_REMOTE_HOME_MOVING.md +23 -0
  13. package/dist/reference/errors/MOSTRA_REMOTE_HOME_SUSPENDED.md +23 -0
  14. package/dist/reference/errors/MOSTRA_REMOTE_LIMIT_REACHED.md +23 -0
  15. package/dist/reference/errors/MOSTRA_REMOTE_NO_INSTANCE.md +23 -0
  16. package/dist/reference/errors/MOSTRA_REMOTE_OPERATOR_UNAVAILABLE.md +23 -0
  17. package/dist/reference/errors/MOSTRA_REMOTE_PAUSED_BY_OPERATOR.md +23 -0
  18. package/dist/reference/errors/MOSTRA_REMOTE_UNDER_REVIEW.md +23 -0
  19. package/dist/reference/errors/MOSTRA_SUBMIT_PAUSED.md +23 -0
  20. package/dist/reference/errors/MOSTRA_TEAM_PRESENCE_RATE_LIMITED.md +23 -0
  21. package/dist/reference/errors/MOSTRA_TEAM_ROSTER_POLICY.md +23 -0
  22. package/dist/reference/errors/MOSTRA_TEAM_ROSTER_TOO_LARGE.md +23 -0
  23. package/dist/reference/self-hosting.md +130 -0
  24. package/dist/{run-Aq4HVIY0.js → run-CtR0PFMj.js} +349 -231
  25. package/dist/run-CtR0PFMj.js.map +1 -0
  26. package/dist/run-NWeQcyh9.js +1 -0
  27. package/dist/skill/SKILL.md +7 -3
  28. package/dist/skill/references/answers.md +3 -1
  29. package/dist/skill/references/mcp.md +8 -3
  30. package/dist/skill/references/sharing.md +1 -0
  31. package/dist/skill/references/teams.md +78 -0
  32. package/dist/telemetry/flush-main.js +1 -1
  33. package/package.json +5 -5
  34. package/src/commands/admin.ts +2 -2
  35. package/src/commands/index.ts +7 -1
  36. package/src/commands/interaction.ts +43 -2
  37. package/src/commands/remote.ts +99 -3
  38. package/src/commands/sharing.ts +19 -1
  39. package/src/commands/team.ts +191 -0
  40. package/src/detached.ts +2 -0
  41. package/src/docs.ts +12 -217
  42. package/src/exit.ts +2 -0
  43. package/src/mcp.ts +3 -21
  44. package/dist/bootstrap-BStzS_41.js +0 -1
  45. package/dist/bootstrap-_iCl_HaO.js.map +0 -1
  46. package/dist/flush-znWmNZA1.js.map +0 -1
  47. package/dist/run-Aq4HVIY0.js.map +0 -1
  48. package/dist/run-D1U_RFEP.js +0 -1
@@ -1,13 +1,13 @@
1
- import { a as GLOBAL_FLAGS, c as parseCommandLine, d as EXIT, f as exitCodeFor, l as topWords, m as defineCommand, o as durationMs, p as commandName, r as progressReporter, s as globalFlags, u as usage } from "./bootstrap-_iCl_HaO.js";
2
- import { _ as packageRoot, a as detachedEnvironment, c as durationBucket, d as mcpSessionFields, f as buildEndpoint, g as fromSource, h as cliVersion, i as detachedDirectory, l as minute, m as truthy, n as startFlusher, o as TelemetryEvent, p as decide, r as TelemetryStore, s as catalogCodes, u as detectHarness } from "./flush-znWmNZA1.js";
1
+ import { a as GLOBAL_FLAGS, c as parseCommandLine, d as EXIT, f as exitCodeFor, l as topWords, m as defineCommand, o as durationMs, p as commandName, r as progressReporter, s as globalFlags, u as usage } from "./bootstrap-3_Tdfdg7.js";
2
+ import { _ as packageRoot, a as detachedEnvironment, c as durationBucket, d as mcpSessionFields, f as buildEndpoint, g as fromSource, h as cliVersion, i as detachedDirectory, l as minute, m as truthy, n as startFlusher, o as TelemetryEvent, p as decide, r as TelemetryStore, s as catalogCodes, u as detectHarness } from "./flush-TPaIdwjy.js";
3
3
  import { spawn } from "node:child_process";
4
4
  import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, readlinkSync, rmSync, statSync, writeFileSync } from "node:fs";
5
- import { extname, isAbsolute, join, resolve, win32 } from "node:path";
6
- import { ARTIFACT_PROGRESS, CLI_CLIENT_NAME, DEFAULT_DOCS_BASE, DEV_NOTIFY, FieldOp, HOST_PROTOCOL_REVISIONS, LineSplitter, MutationId, RpcError, RpcPeer, artifactCreateMethod, artifactExportMethod, artifactGetMethod, artifactImportMethod, artifactListMethod, artifactPublishMethod, artifactVerifyMethod, createDiagnostic, depsAddMethod, devStartMethod, devStopMethod, diagnosticCatalog, encodeLine, gcRunMethod, instanceCheckMethod, instanceStatusMethod, livePushMethod, mostraInitializeMethod, mostraShutdownMethod, remoteLoginMethod, remoteLoginWaitMethod, remoteLogoutMethod, resultsGetMethod, secretDeleteMethod, secretListMethod, secretSetMethod, shareListMethod, shareStartMethod, shareStopMethod, stateGetMethod, statePatchMethod, viewDefaultMethod, viewLaunchMethod, viewRevokeMethod, viewRotateMethod, viewUrlMethod, waitMethod } from "@mostra/protocol";
5
+ import { isAbsolute, join, resolve, win32 } from "node:path";
6
+ import { ARTIFACT_PROGRESS, CLI_CLIENT_NAME, DEFAULT_DOCS_BASE, DEV_NOTIFY, FieldOp, HOST_PROTOCOL_REVISIONS, LineSplitter, MutationId, RESULTS_LIST_MAX, RespondentSpec, RpcError, RpcPeer, artifactCreateMethod, artifactExportMethod, artifactGetMethod, artifactImportMethod, artifactListMethod, artifactPauseMethod, artifactPublishMethod, artifactVerifyMethod, createDiagnostic, depsAddMethod, devStartMethod, devStopMethod, diagnosticCatalog, encodeLine, gcRunMethod, instanceCheckMethod, instanceStatusMethod, livePushMethod, mostraInitializeMethod, mostraShutdownMethod, remoteLinkMethod, remoteLoginMethod, remoteLoginWaitMethod, remoteLogoutMethod, resultsGetMethod, resultsListMethod, rosterAddMethod, rosterGetMethod, rosterRemoveMethod, secretDeleteMethod, secretListMethod, secretSetMethod, shareListMethod, shareStartMethod, shareStopMethod, stateGetMethod, statePatchMethod, viewDefaultMethod, viewLaunchMethod, viewRevokeMethod, viewRotateMethod, viewUrlMethod, waitMethod } from "@mostra/protocol";
7
7
  import { checkBrowser, checkFiles, connectControl, enclosingBundle, readBundle, readSetup, resolveRuntime } from "@mostra/sdk";
8
+ import { MCP_GUIDE_LINKS, MCP_PATH, createHttpEndpoint, createMcpServerFactory, defaultWorkspaceRoot, docsIndex, fileDocs, indexMarkdown, localWorkspace, nearestTopics, topicMarkdown } from "@mostra/mcp";
8
9
  import { homedir, tmpdir } from "node:os";
9
10
  import { randomBytes, randomUUID } from "node:crypto";
10
- import { MCP_PATH, createHttpEndpoint, createMcpServerFactory, defaultWorkspaceRoot, localWorkspace } from "@mostra/mcp";
11
11
  import { isIP } from "node:net";
12
12
  import { serve } from "@hono/node-server";
13
13
  import { serveStdio } from "@modelcontextprotocol/server/stdio";
@@ -30,190 +30,9 @@ function skillDir() {
30
30
  const bundled = join(packageRoot(), "dist", "skill");
31
31
  return !fromSource() && existsSync(bundled) ? bundled : join(packageRoot(), "..", "..", "skills", "mostra");
32
32
  }
33
- function titleOf(file) {
34
- const first = readFileSync(file, "utf8").split("\n").find((line) => line.startsWith("# "));
35
- return first ? first.slice(2).trim() : "";
36
- }
37
- /** Every topic, the pages first and then the codes, sorted. */
38
- function docsIndex(dir = referenceDir()) {
39
- const base = DEFAULT_DOCS_BASE.replace(/\/+$/, "");
40
- const pages = [];
41
- for (const topic of ["cli", "telemetry"]) {
42
- const file = join(dir, `${topic}.md`);
43
- if (existsSync(file)) pages.push({
44
- topic,
45
- title: titleOf(file),
46
- url: `${base}/${topic}`,
47
- file
48
- });
49
- }
50
- const errorsDir = join(dir, "errors");
51
- const errors = (existsSync(errorsDir) ? readdirSync(errorsDir).filter((name) => /^MOSTRA_[A-Z0-9_]+\.md$/.test(name)).sort() : []).map((name) => {
52
- const code = name.slice(0, -3);
53
- const file = join(errorsDir, name);
54
- return {
55
- topic: code,
56
- title: titleOf(file),
57
- url: `${base}/errors/${code}`,
58
- file
59
- };
60
- });
61
- return [
62
- ...pages,
63
- ...guideTopics(skillDir(), base),
64
- ...errors
65
- ];
66
- }
67
- const byName = (a, b) => a.name < b.name ? -1 : 1;
68
- /** Every file below `root`'s `prefix`, relative to `root`, sorted. */
69
- function filesBelow(root, prefix) {
70
- return readdirSync(join(root, prefix), { withFileTypes: true }).sort(byName).flatMap((entry) => {
71
- const path = `${prefix}/${entry.name}`;
72
- return entry.isDirectory() ? filesBelow(root, path) : [path];
73
- });
74
- }
75
- /**
76
- * The Skill as topics: `guide` (its SKILL.md), `guide/<name>` for each reference,
77
- * `guide/<file>` for each asset (the baseline stylesheet), and `guide/examples/<name>` for each
78
- * example, every file of it.
79
- */
80
- function guideTopics(dir, base) {
81
- const skill = join(dir, "SKILL.md");
82
- if (!existsSync(skill)) return [];
83
- const topics = [{
84
- topic: "guide",
85
- title: "Using Mostra",
86
- url: `${base}/guide`,
87
- file: skill
88
- }];
89
- const references = join(dir, "references");
90
- if (existsSync(references)) for (const name of readdirSync(references).filter((entry) => entry.endsWith(".md")).sort()) {
91
- const file = join(references, name);
92
- const slug = name.slice(0, -3);
93
- topics.push({
94
- topic: `guide/${slug}`,
95
- title: titleOf(file),
96
- url: `${base}/guide/${slug}`,
97
- file
98
- });
99
- }
100
- const assets = join(dir, "assets");
101
- if (!existsSync(assets)) return topics;
102
- for (const entry of readdirSync(assets, { withFileTypes: true }).sort(byName)) {
103
- if (!entry.isFile()) continue;
104
- topics.push({
105
- topic: `guide/${entry.name}`,
106
- title: entry.name,
107
- url: `${base}/guide/${entry.name}`,
108
- file: join(assets, entry.name),
109
- files: [entry.name]
110
- });
111
- }
112
- const examples = join(assets, "examples");
113
- if (!existsSync(examples)) return topics;
114
- for (const entry of readdirSync(examples, { withFileTypes: true }).sort(byName)) {
115
- if (!entry.isDirectory()) continue;
116
- const files = filesBelow(assets, `examples/${entry.name}`);
117
- if (files.length === 0) continue;
118
- topics.push({
119
- topic: `guide/examples/${entry.name}`,
120
- title: `Example: ${entry.name}`,
121
- url: `${base}/guide/examples/${entry.name}`,
122
- file: join(assets, files[0]),
123
- files
124
- });
125
- }
126
- return topics;
127
- }
128
- const FENCE_LANGUAGES = {
129
- ".css": "css",
130
- ".json": "json",
131
- ".md": "md",
132
- ".mdx": "mdx",
133
- ".ts": "ts",
134
- ".tsx": "tsx"
135
- };
136
- /** How the guide's relative links read through the CLI, before each of its pages. */
137
- const GUIDE_LINKS = "> Read through `mostra docs`: a link to `references/<name>.md` is `mostra docs guide/<name>`, `assets/<file>` is `mostra docs guide/<file>`, and `assets/examples/<name>/` is `mostra docs guide/examples/<name>`.";
138
- /** The same for the guide read through `mostra mcp` (D164): topics of `docs_search`, or resources. */
139
- const MCP_GUIDE_LINKS = "> Read through Mostra's MCP server: a link to `references/<name>.md` is the topic `guide/<name>`, `assets/<file>` is `guide/<file>`, and `assets/examples/<name>/` is `guide/examples/<name>`; read one with docs_search (`topic`) or the resource `mostra://docs/<topic>`. Where the guide runs a `mostra` command, use the tool of the same step (artifact_verify for `mostra verify`, artifact_wait for `mostra wait`).";
140
- /**
141
- * A topic's Markdown. A guide page loses its frontmatter and says how its links read (through the
142
- * CLI by default, or `links`); a guide topic made of files shows each one as code under its path.
143
- */
144
- function topicMarkdown(topic, dir = skillDir(), links = GUIDE_LINKS) {
145
- if (topic.files !== void 0) {
146
- const parts = topic.files.map((path) => {
147
- const text = readFileSync(join(dir, "assets", path), "utf8");
148
- const fence = text.includes("```") ? "````" : "```";
149
- const body = text.endsWith("\n") ? text : `${text}\n`;
150
- return `## \`${path}\`\n\n${fence}${FENCE_LANGUAGES[extname(path)] ?? ""}\n${body}${fence}\n`;
151
- });
152
- return [
153
- `# ${topic.title}`,
154
- "",
155
- links,
156
- "",
157
- ...parts
158
- ].join("\n");
159
- }
160
- const text = readFileSync(topic.file, "utf8");
161
- if (topic.topic !== "guide" && !topic.topic.startsWith("guide/")) return text;
162
- return [
163
- links,
164
- "",
165
- text.replace(/^---\n[\s\S]*?\n---\n+/, "")
166
- ].join("\n");
167
- }
168
- /** The index as Markdown: what `mostra docs` prints without a topic. */
169
- function indexMarkdown(topics) {
170
- const pages = topics.filter((topic) => !topic.topic.startsWith("MOSTRA_") && !topic.topic.startsWith("guide"));
171
- const guide = topics.filter((topic) => topic.topic === "guide" || topic.topic.startsWith("guide/"));
172
- const codes = topics.filter((topic) => topic.topic.startsWith("MOSTRA_"));
173
- return [
174
- "# Mostra reference",
175
- "",
176
- "Run `mostra docs <topic>` to read one. Diagnostic codes are topics too.",
177
- "",
178
- ...pages.map((topic) => `- \`${topic.topic}\`: ${topic.title}`),
179
- "",
180
- ...guide.length > 0 ? [
181
- "## Writing artifacts",
182
- "",
183
- ...guide.map((topic) => `- \`${topic.topic}\`: ${topic.title}`),
184
- ""
185
- ] : [],
186
- "## Diagnostic codes",
187
- "",
188
- ...codes.map((topic) => `- \`${topic.topic}\`: ${topic.title}`),
189
- ""
190
- ].join("\n");
191
- }
192
- /** The topics nearest an unknown one, for its usage error. */
193
- function nearestTopics(wanted, topics, count = 3) {
194
- const target = wanted.toUpperCase();
195
- return topics.map((topic) => {
196
- const name = topic.topic.toUpperCase();
197
- const contains = name.includes(target) || target.includes(name) ? 0 : 1;
198
- return {
199
- topic: topic.topic,
200
- score: contains * 100 + distance(name, target)
201
- };
202
- }).sort((a, b) => a.score - b.score || (a.topic < b.topic ? -1 : 1)).slice(0, count).map((item) => item.topic);
203
- }
204
- /** Levenshtein distance. */
205
- function distance(a, b) {
206
- const row = Array.from({ length: b.length + 1 }, (_, index) => index);
207
- for (let i = 1; i <= a.length; i += 1) {
208
- let previous = row[0];
209
- row[0] = i;
210
- for (let j = 1; j <= b.length; j += 1) {
211
- const current = row[j];
212
- row[j] = Math.min(row[j] + 1, row[j - 1] + 1, previous + (a[i - 1] === b[j - 1] ? 0 : 1));
213
- previous = current;
214
- }
215
- }
216
- return row[b.length];
33
+ /** Every topic of the reference this CLI ships, the pages first and then the codes, sorted. */
34
+ function docsIndex$1(dir = referenceDir()) {
35
+ return docsIndex(dir, skillDir());
217
36
  }
218
37
  //#endregion
219
38
  //#region src/home.ts
@@ -2060,7 +1879,7 @@ const docsCommand = defineCommand({
2060
1879
  local: true,
2061
1880
  quiet: true,
2062
1881
  async run(context) {
2063
- const topics = docsIndex();
1882
+ const topics = docsIndex$1();
2064
1883
  const wanted = context.args["topic"];
2065
1884
  if (typeof wanted !== "string") {
2066
1885
  const markdown = indexMarkdown(topics);
@@ -2080,7 +1899,7 @@ const docsCommand = defineCommand({
2080
1899
  }
2081
1900
  const found = topics.find((topic) => topic.topic === wanted || topic.topic === wanted.toUpperCase());
2082
1901
  if (!found) throw usage(`No topic "${wanted}". The nearest: ${nearestTopics(wanted, topics).join(", ")}. Run "mostra docs" for the index.`);
2083
- const markdown = topicMarkdown(found);
1902
+ const markdown = topicMarkdown(found, skillDir());
2084
1903
  return {
2085
1904
  result: {
2086
1905
  topic: found.topic,
@@ -2639,7 +2458,7 @@ const waitCommand = defineCommand({
2639
2458
  name: "until",
2640
2459
  kind: "string",
2641
2460
  value: "<condition>",
2642
- summary: "submitted, signal:<name>, state:<fieldId> or event:<type>."
2461
+ summary: "submitted, submitted:all (every expected respondent), submitted:<N>, signal:<name>, state:<fieldId> or event:<type>."
2643
2462
  },
2644
2463
  {
2645
2464
  name: "after",
@@ -2704,18 +2523,32 @@ const resultsCommand = defineCommand({
2704
2523
  name: "artifact",
2705
2524
  summary: "The artifact: its source path or its ID."
2706
2525
  }],
2707
- flags: [{
2708
- name: "submission",
2709
- kind: "string",
2710
- value: "<id>",
2711
- summary: "This submission instead of the latest."
2712
- }, {
2713
- name: "format",
2714
- kind: "string",
2715
- value: "<format>",
2716
- choices: ["md", "json"],
2717
- summary: "Markdown or JSON. Default: Markdown, or JSON with --json."
2718
- }],
2526
+ flags: [
2527
+ {
2528
+ name: "submission",
2529
+ kind: "string",
2530
+ value: "<id>",
2531
+ summary: "This submission instead of the latest."
2532
+ },
2533
+ {
2534
+ name: "all",
2535
+ kind: "boolean",
2536
+ summary: "Every submission, oldest first (a survey's, a team's), instead of the latest."
2537
+ },
2538
+ {
2539
+ name: "after",
2540
+ kind: "string",
2541
+ value: "<cursor>",
2542
+ summary: "With --all, only submissions after this cursor."
2543
+ },
2544
+ {
2545
+ name: "format",
2546
+ kind: "string",
2547
+ value: "<format>",
2548
+ choices: ["md", "json"],
2549
+ summary: "Markdown or JSON. Default: Markdown, or JSON with --json."
2550
+ }
2551
+ ],
2719
2552
  output: {
2720
2553
  type: "Results",
2721
2554
  topic: "cli"
@@ -2725,8 +2558,34 @@ const resultsCommand = defineCommand({
2725
2558
  async run(context) {
2726
2559
  const format = flag(context, "format") ?? (context.json ? "json" : "md");
2727
2560
  const submission = flag(context, "submission");
2561
+ const artifactArg = artifactRef(arg(context, "artifact"), context.cwd);
2562
+ if (context.flags["all"] === true) {
2563
+ if (submission !== void 0) throw usage("--all reads every submission: drop --submission.");
2564
+ const results = [];
2565
+ let after = flag(context, "after");
2566
+ for (;;) {
2567
+ const page = await context.call(resultsListMethod, {
2568
+ artifact: artifactArg,
2569
+ format,
2570
+ limit: RESULTS_LIST_MAX,
2571
+ ...after !== void 0 ? { after } : {}
2572
+ });
2573
+ results.push(...page.results);
2574
+ after = page.cursor;
2575
+ if (!page.more) break;
2576
+ }
2577
+ const human = format === "md" ? results.length === 0 ? "No submissions.\n" : `${results.map((one) => one.markdown.trimEnd()).join("\n\n---\n\n")}\n` : pretty(results);
2578
+ return {
2579
+ result: {
2580
+ results,
2581
+ cursor: after
2582
+ },
2583
+ human
2584
+ };
2585
+ }
2586
+ if (flag(context, "after") !== void 0) throw usage("--after reads from a cursor with --all.");
2728
2587
  const result = await context.call(resultsGetMethod, {
2729
- artifact: artifactRef(arg(context, "artifact"), context.cwd),
2588
+ artifact: artifactArg,
2730
2589
  format,
2731
2590
  ...submission !== void 0 ? { submission } : {}
2732
2591
  });
@@ -3472,28 +3331,11 @@ function daemonInstance(options) {
3472
3331
  }
3473
3332
  /** The bundled reference (`mostra docs`), read as the MCP server's docs. */
3474
3333
  function bundledDocs() {
3475
- let topics;
3476
- const all = () => {
3477
- topics ??= docsIndex();
3478
- return topics;
3479
- };
3480
- const cache = /* @__PURE__ */ new Map();
3481
- return {
3482
- topics: () => all().map((topic) => ({
3483
- topic: topic.topic,
3484
- title: topic.title,
3485
- url: topic.url
3486
- })),
3487
- read(topic) {
3488
- const cached = cache.get(topic);
3489
- if (cached !== void 0) return cached;
3490
- const found = all().find((entry) => entry.topic === topic);
3491
- if (found === void 0) return void 0;
3492
- const markdown = topicMarkdown(found, skillDir(), MCP_GUIDE_LINKS);
3493
- cache.set(topic, markdown);
3494
- return markdown;
3495
- }
3496
- };
3334
+ return fileDocs({
3335
+ referenceDir: referenceDir(),
3336
+ skillDir: skillDir(),
3337
+ links: MCP_GUIDE_LINKS
3338
+ });
3497
3339
  }
3498
3340
  /** The daemon instance, with the runtime's install started at once (D164 item 7). */
3499
3341
  function startInstance(options) {
@@ -3758,8 +3600,9 @@ const mcpCommand = defineCommand({
3758
3600
  * remote server by the OAuth device authorization grant, so `mostra share --cloud` can host its
3759
3601
  * artifacts there, and signs out again. The instance keeps the refresh token in the home,
3760
3602
  * owner-only; signing out keeps its instance link, so the artifacts it shared stay its own at the
3761
- * next sign-in, unless `--forget`. Clients of `remote/login`, `remote/login.wait` and
3762
- * `remote/logout`.
3603
+ * next sign-in, unless `--forget`. With `--key-file`, a machine links with a key the server's
3604
+ * operator issued instead (`remote/link`, D167). Clients of `remote/login`, `remote/login.wait`,
3605
+ * `remote/link` and `remote/logout`.
3763
3606
  */
3764
3607
  /** How long `mostra login` waits for the person to approve, in all (the code lives 10 minutes). */
3765
3608
  const LOGIN_WAIT_MS = 6e5;
@@ -3778,6 +3621,10 @@ const loginCommand = defineCommand({
3778
3621
  name: "default",
3779
3622
  kind: "boolean",
3780
3623
  summary: "Make this machine the account's default, the one chat apps create pages on. Default: the first machine linked."
3624
+ }, {
3625
+ name: "key-file",
3626
+ kind: "string",
3627
+ summary: "Link with a key the server's operator issued for an account, read from this file, instead of a person's sign-in (for an always-on machine)."
3781
3628
  }],
3782
3629
  output: {
3783
3630
  type: "RemoteLoginWaitResult",
@@ -3787,6 +3634,28 @@ const loginCommand = defineCommand({
3787
3634
  example: "login https://api.example.com",
3788
3635
  async run(context) {
3789
3636
  const server = context.args["server"];
3637
+ const keyFile = flag(context, "key-file");
3638
+ if (keyFile !== void 0) {
3639
+ if (typeof server !== "string") throw usage("Name the server the key is for: mostra login <server> --key-file <file>.");
3640
+ let key;
3641
+ try {
3642
+ key = readFileSync(resolve(context.cwd, keyFile), "utf8").trim();
3643
+ } catch (error) {
3644
+ throw usage(`--key-file ${keyFile} can't be read (${error.code ?? "error"}).`);
3645
+ }
3646
+ const linked = await context.call(remoteLinkMethod, {
3647
+ server: server.replace(/\/+$/, ""),
3648
+ key,
3649
+ ...context.flags["default"] === true ? { default: true } : {}
3650
+ });
3651
+ return {
3652
+ result: {
3653
+ status: "signed-in",
3654
+ ...linked
3655
+ },
3656
+ human: `Linked to ${linked.server} for ${linked.account.name ?? linked.account.id} with the operator's key. This machine is ${linked.instanceId}.\n`
3657
+ };
3658
+ }
3790
3659
  const started = await context.call(remoteLoginMethod, {
3791
3660
  ...typeof server === "string" ? { server: server.replace(/\/+$/, "") } : {},
3792
3661
  ...context.flags["default"] === true ? { default: true } : {}
@@ -3846,6 +3715,64 @@ const logoutCommand = defineCommand({
3846
3715
  };
3847
3716
  }
3848
3717
  });
3718
+ /** `mostra pause <artifact> [--reason <text>]` (D165 item 14). */
3719
+ const pauseCommand = defineCommand({
3720
+ path: ["pause"],
3721
+ summary: "Pause an artifact: its pages stay viewable and its links valid, but it takes no answers and runs no actions until resumed.",
3722
+ args: [{
3723
+ name: "artifact",
3724
+ summary: "The artifact: its source path or its ID."
3725
+ }],
3726
+ flags: [{
3727
+ name: "reason",
3728
+ kind: "string",
3729
+ summary: "Why, shown to the page's viewers beside the paused notice."
3730
+ }],
3731
+ output: {
3732
+ type: "ArtifactPauseResult",
3733
+ topic: "cli"
3734
+ },
3735
+ exits: [EXIT.failure, EXIT.environment],
3736
+ example: "pause ./survey --reason \"Closed for review until Monday\"",
3737
+ async run(context) {
3738
+ const reason = flag(context, "reason");
3739
+ const result = await context.call(artifactPauseMethod, {
3740
+ artifact: artifactRef(arg(context, "artifact"), context.cwd),
3741
+ paused: true,
3742
+ ...reason !== void 0 ? { reason } : {}
3743
+ });
3744
+ return {
3745
+ result,
3746
+ human: result.by === "operator" ? "Paused. The server's operator paused it too, and only the operator resumes that.\n" : "Paused. Pages stay viewable; answers and actions wait until mostra resume.\n"
3747
+ };
3748
+ }
3749
+ });
3750
+ /** `mostra resume <artifact>` (D165 item 14). */
3751
+ const resumeCommand = defineCommand({
3752
+ path: ["resume"],
3753
+ summary: "Resume a paused artifact: it takes answers and runs actions again.",
3754
+ args: [{
3755
+ name: "artifact",
3756
+ summary: "The artifact: its source path or its ID."
3757
+ }],
3758
+ output: {
3759
+ type: "ArtifactPauseResult",
3760
+ topic: "cli"
3761
+ },
3762
+ exits: [EXIT.failure, EXIT.environment],
3763
+ example: "resume ./survey",
3764
+ async run(context) {
3765
+ const result = await context.call(artifactPauseMethod, {
3766
+ artifact: artifactRef(arg(context, "artifact"), context.cwd),
3767
+ paused: false
3768
+ });
3769
+ return {
3770
+ result,
3771
+ human: result.paused ? "Still paused: the server's operator paused it, and only the operator resumes that.\n" : "Resumed. The artifact takes answers and runs actions again.\n",
3772
+ ...result.paused ? { exit: EXIT.failure } : {}
3773
+ };
3774
+ }
3775
+ });
3849
3776
  //#endregion
3850
3777
  //#region src/commands/sharing.ts
3851
3778
  /**
@@ -3941,6 +3868,12 @@ const shareCommand = defineCommand({
3941
3868
  value: "<name>",
3942
3869
  summary: "The display name of --viewer."
3943
3870
  },
3871
+ {
3872
+ name: "respondent",
3873
+ kind: "list",
3874
+ value: "<ref,…>",
3875
+ summary: "With --cloud, the people you expect answers from, by your own key for each: each gets a personal link (mostra roster)."
3876
+ },
3944
3877
  {
3945
3878
  name: "request-id",
3946
3879
  kind: "string",
@@ -3975,6 +3908,9 @@ const shareCommand = defineCommand({
3975
3908
  const viewerName = flag(context, "viewer-name");
3976
3909
  const requestId = flag(context, "request-id");
3977
3910
  if (viewerName !== void 0 && viewerRef === void 0) throw usage("--viewer-name needs --viewer.");
3911
+ const respondents = context.flags["respondent"];
3912
+ if (respondents !== void 0 && !cloud) throw usage("--respondent names people on a hosted share: add --cloud, or use mostra roster add.");
3913
+ if (respondents !== void 0 && viewerRef !== void 0) throw usage("Give --viewer for one person's link, or --respondent for each one's: not both.");
3978
3914
  const share = await context.call(shareStartMethod, {
3979
3915
  artifact,
3980
3916
  via,
@@ -3985,16 +3921,18 @@ const shareCommand = defineCommand({
3985
3921
  ref: viewerRef,
3986
3922
  ...viewerName !== void 0 ? { name: viewerName } : {}
3987
3923
  } } : {},
3924
+ ...respondents !== void 0 ? { respondents: respondents.map((ref) => ({ ref })) } : {},
3988
3925
  ...requestId !== void 0 ? { requestId } : {}
3989
3926
  });
3990
3927
  context.record({
3991
3928
  event: "share.done",
3992
3929
  fields: { kind: via }
3993
3930
  });
3931
+ const personal = (share.respondents ?? []).map((entry) => `${entry.ref} ${entry.link.url}\n`);
3994
3932
  const until = share.expiresAt ? `until ${share.expiresAt}` : "until you stop it";
3995
3933
  return {
3996
3934
  result: share,
3997
- human: `${share.url}\nShared through ${THROUGH[via]}, ${until}.\n${via === "tailnet" ? tailnetReach(share) : ""}Stop it with: mostra share stop ${share.shareId}\n`
3935
+ human: `${share.url}\nShared through ${THROUGH[via]}, ${until}.\n${via === "tailnet" ? tailnetReach(share) : ""}${personal.length > 0 ? `Personal links:\n${personal.join("")}` : ""}Stop it with: mostra share stop ${share.shareId}\n`
3998
3936
  };
3999
3937
  }
4000
3938
  });
@@ -4055,6 +3993,181 @@ const shareListCommand = defineCommand({
4055
3993
  }
4056
3994
  });
4057
3995
  //#endregion
3996
+ //#region src/commands/team.ts
3997
+ /**
3998
+ * Teams (D121, D168): `roster get|add|remove`, thin clients of `roster/*`. A respondent is named by
3999
+ * the caller's own stable key for them (`ref`, an email or an account ID) and gets a personal link
4000
+ * that acts as them; `mostra wait --until submitted:all` waits for every one of them.
4001
+ */
4002
+ /** One line per respondent and the round's tally: what `roster get` prints. */
4003
+ function rosterText(roster) {
4004
+ const { counts } = roster;
4005
+ const head = counts.total === 0 ? "No expected respondents.\n" : `Round ${roster.round}: ${counts.submitted} of ${counts.total} submitted, ${counts.drafting} drafting, ${counts.notOpened} not opened${roster.complete ? " (complete)" : ""}.\n`;
4006
+ const width = Math.max(0, ...roster.respondents.map((one) => one.ref.length));
4007
+ return `${head}${roster.respondents.map((one) => ` ${one.status.padEnd(10)} ${one.ref.padEnd(width)}${one.name !== void 0 ? ` ${one.name}` : ""}\n`).join("")}`;
4008
+ }
4009
+ /** `mostra roster get <artifact>`. */
4010
+ const rosterGetCommand = defineCommand({
4011
+ path: ["roster", "get"],
4012
+ summary: "Show who an artifact expects answers from and where each stands: not opened, drafting or submitted.",
4013
+ args: [{
4014
+ name: "artifact",
4015
+ summary: "The artifact: its source path or its ID."
4016
+ }],
4017
+ output: {
4018
+ type: "Roster",
4019
+ topic: "cli"
4020
+ },
4021
+ exits: [EXIT.failure],
4022
+ example: "roster get ./retro",
4023
+ async run(context) {
4024
+ const result = await context.call(rosterGetMethod, { artifact: artifactRef(arg(context, "artifact"), context.cwd) });
4025
+ return {
4026
+ result,
4027
+ human: rosterText(result)
4028
+ };
4029
+ }
4030
+ });
4031
+ /** `mostra roster add <artifact> [ref…]`. */
4032
+ const rosterAddCommand = defineCommand({
4033
+ path: ["roster", "add"],
4034
+ summary: "Name the people an artifact expects answers from; each gets a personal link that acts as them.",
4035
+ args: [{
4036
+ name: "artifact",
4037
+ summary: "The artifact: its source path or its ID."
4038
+ }, {
4039
+ name: "ref",
4040
+ summary: "Each respondent, by your own stable key for them (an email, an account ID).",
4041
+ optional: true,
4042
+ variadic: true
4043
+ }],
4044
+ flags: [
4045
+ {
4046
+ name: "name",
4047
+ kind: "string",
4048
+ value: "<name>",
4049
+ summary: "The display name of the one respondent given."
4050
+ },
4051
+ {
4052
+ name: "email",
4053
+ kind: "string",
4054
+ value: "<address>",
4055
+ summary: "Where a remote server that sends invitations writes to the one respondent given."
4056
+ },
4057
+ {
4058
+ name: "file",
4059
+ kind: "string",
4060
+ value: "<path>",
4061
+ summary: "Read respondents from a JSON file: [{ ref, name?, email? }]."
4062
+ },
4063
+ {
4064
+ name: "stdin",
4065
+ kind: "boolean",
4066
+ summary: "Read respondents as JSON from stdin."
4067
+ },
4068
+ {
4069
+ name: "scope",
4070
+ kind: "list",
4071
+ value: "<a,b>",
4072
+ summary: "The personal links' scopes: view, draft, submit, review, signal, action:*. Default: all."
4073
+ },
4074
+ {
4075
+ name: "ttl",
4076
+ kind: "duration",
4077
+ value: "<d>",
4078
+ summary: "How long the personal links work, such as 7d. Default: no limit."
4079
+ },
4080
+ {
4081
+ name: "request-id",
4082
+ kind: "string",
4083
+ value: "<id>",
4084
+ summary: "Make a retry return the first attempt's links."
4085
+ }
4086
+ ],
4087
+ output: {
4088
+ type: "RosterAddResult",
4089
+ topic: "cli"
4090
+ },
4091
+ exits: [EXIT.failure],
4092
+ example: "roster add ./retro ada@example.com grace@example.com",
4093
+ readsStdin: (flags) => flags["stdin"] === true,
4094
+ async run(context) {
4095
+ const refs = context.args["ref"] ?? [];
4096
+ const name = flag(context, "name");
4097
+ const email = flag(context, "email");
4098
+ const fromJson = context.flags["file"] !== void 0 || context.flags["stdin"] === true;
4099
+ let respondents;
4100
+ if (fromJson) {
4101
+ if (refs.length > 0 || name !== void 0 || email !== void 0) throw usage("Give respondents either as arguments or with --file or --stdin, not both.");
4102
+ const parsed = RespondentSpec.array().min(1).safeParse(await jsonInput(context, "respondents"));
4103
+ if (!parsed.success) throw usage("The respondents must be a non-empty JSON array of { ref, name?, email? }.");
4104
+ respondents = parsed.data;
4105
+ } else {
4106
+ if (refs.length === 0) throw usage("Name at least one respondent, or give --file or --stdin.");
4107
+ if ((name !== void 0 || email !== void 0) && refs.length !== 1) throw usage("--name and --email describe one respondent: give one ref with them.");
4108
+ respondents = refs.map((ref) => ({
4109
+ ref,
4110
+ ...name !== void 0 ? { name } : {},
4111
+ ...email !== void 0 ? { email } : {}
4112
+ }));
4113
+ }
4114
+ const scopes = context.flags["scope"];
4115
+ const ttl = flag(context, "ttl");
4116
+ const requestId = flag(context, "request-id");
4117
+ const result = await context.call(rosterAddMethod, {
4118
+ artifact: artifactRef(arg(context, "artifact"), context.cwd),
4119
+ respondents,
4120
+ ...scopes !== void 0 ? { scopes } : {},
4121
+ ...ttl !== void 0 ? { ttl } : {},
4122
+ ...requestId !== void 0 ? { requestId } : {}
4123
+ });
4124
+ const width = Math.max(0, ...result.links.map((entry) => entry.ref.length));
4125
+ return {
4126
+ result,
4127
+ human: `${result.links.map((entry) => `${entry.ref.padEnd(width)} ${entry.link.url}\n`).join("")}Send each person their own link. Wait for everyone with: mostra wait ${arg(context, "artifact")} --until submitted:all\n`
4128
+ };
4129
+ }
4130
+ });
4131
+ /** `mostra roster remove <artifact> <ref…>`. */
4132
+ const rosterRemoveCommand = defineCommand({
4133
+ path: ["roster", "remove"],
4134
+ summary: "Stop expecting answers from respondents; their links, drafts and submissions stay as they are.",
4135
+ args: [{
4136
+ name: "artifact",
4137
+ summary: "The artifact: its source path or its ID."
4138
+ }, {
4139
+ name: "ref",
4140
+ summary: "Each respondent to remove, by their ref.",
4141
+ variadic: true
4142
+ }],
4143
+ flags: [{
4144
+ name: "request-id",
4145
+ kind: "string",
4146
+ value: "<id>",
4147
+ summary: "Make a retry return the first attempt's result."
4148
+ }],
4149
+ output: {
4150
+ type: "RosterRemoveResult",
4151
+ topic: "cli"
4152
+ },
4153
+ exits: [EXIT.failure],
4154
+ example: "roster remove ./retro grace@example.com",
4155
+ async run(context) {
4156
+ const refs = context.args["ref"] ?? [];
4157
+ if (refs.length === 0) throw usage("Name at least one respondent to remove.");
4158
+ const requestId = flag(context, "request-id");
4159
+ const result = await context.call(rosterRemoveMethod, {
4160
+ artifact: artifactRef(arg(context, "artifact"), context.cwd),
4161
+ refs: [...refs],
4162
+ ...requestId !== void 0 ? { requestId } : {}
4163
+ });
4164
+ return {
4165
+ result,
4166
+ human: `${result.removed.length === 0 ? "No one removed.\n" : `Removed ${result.removed.join(", ")}.\n`}${rosterText(result.roster)}`
4167
+ };
4168
+ }
4169
+ });
4170
+ //#endregion
4058
4171
  //#region src/commands/viewing.ts
4059
4172
  /**
4060
4173
  * `mostra open`: the artifact's link on stdout, and a browser opened on a one-time launch URL that
@@ -4232,6 +4345,11 @@ const COMMANDS = [
4232
4345
  shareListCommand,
4233
4346
  loginCommand,
4234
4347
  logoutCommand,
4348
+ pauseCommand,
4349
+ resumeCommand,
4350
+ rosterAddCommand,
4351
+ rosterGetCommand,
4352
+ rosterRemoveCommand,
4235
4353
  waitCommand,
4236
4354
  resultsCommand,
4237
4355
  stateGetCommand,
@@ -4699,4 +4817,4 @@ async function runRuntime(io, args, stdio) {
4699
4817
  //#endregion
4700
4818
  export { COMMANDS as a, referenceMarkdown as i, commandDefinition as n, commandHelp as r, run as t };
4701
4819
 
4702
- //# sourceMappingURL=run-Aq4HVIY0.js.map
4820
+ //# sourceMappingURL=run-CtR0PFMj.js.map