mirrorbook 0.3.0 → 0.5.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 (3) hide show
  1. package/SKILL.md +12 -2
  2. package/dist/cli.js +64 -7
  3. package/package.json +1 -1
package/SKILL.md CHANGED
@@ -19,7 +19,7 @@ npx mirrorbook deploy ./dist --slug my-demo --wait --json
19
19
  - Markdown (GitHub-flavored) and plain text are rendered into a readable web page. For stdin the format is auto-detected; pass `--format html|markdown|text` to be explicit. The quickest way to publish something you just wrote: `echo "$CONTENT" | npx mirrorbook deploy - --format markdown --slug my-notes --json`.
20
20
  - Re-deploying the same `--slug` publishes a new version; it's safe to retry.
21
21
  - If the slug is taken by someone else, a 4-character suffix is added (`demo` → `demo-k3x9`) and `slugAdjusted` is `true`. Always read the final `url`/`slug` from the output. Re-deploying with the original `--slug demo` keeps updating that same `demo-k3x9` site. Pass `--strict-slug` to fail (exit 2, `slug_taken`) instead.
22
- - Output (with `--json`): `{"url","previewUrl","slug","deploymentId","status","error","errorCode","errorParams","number","created","requestedSlug","slugAdjusted"}`.
22
+ - Output (with `--json`): `{"url","previewUrl","slug","deploymentId","status","error","errorCode","errorParams","number","created","requestedSlug","slugAdjusted","lockTitle","lockMessage"}`.
23
23
  - When `status` is `failed`, `errorCode` says why: `missing_index` (no index.html at the zip root), `zip_invalid`, `zip_path_invalid`, `zip_encrypted`, `file_too_large`, `unzipped_too_large`, `too_many_files`, `quota_exceeded`, `upload_missing`, `file_read_failed`, `owner_missing`, `processing_failed`.
24
24
  - Sites go live as soon as processing finishes (`status: "approved"`); admins review afterwards and may take a version down (`rejected`). A new account needs admin approval once before it can publish (exit 3, `pending_approval`).
25
25
  - Each account has a site limit (default 10) and a storage quota (default 100 MB); going over exits with 4 (`quota_exceeded`).
@@ -30,6 +30,16 @@ Versions: every deploy gets a number (`#1`, `#2`, …, in the `number` field). T
30
30
 
31
31
  Password protection: `--password <pw> [--expires 7d|12h|2026-12-31|never]` on `deploy` (or `access <slug> --password … --expires …` later) makes the site unlisted and asks visitors for the password. After the expiry the site can't be opened until a new expiry or password is set. `access <slug> --remove-password` drops it, `access <slug> --public` makes the site public again. Prefer the `MIRRORBOOK_SITE_PASSWORD` env var over `--password` to keep it out of shell history.
32
32
 
33
+ Password page copy: the gate visitors see before entering the password is customisable with `--lock-title <text>` (max 80 chars, becomes the page title and the bold heading) and `--lock-message <text>` (max 300 chars, the line above the password box — good place for "how to get the password"). Both work on `deploy` and on `access`:
34
+
35
+ ```bash
36
+ npx mirrorbook access my-demo --lock-title "Team preview" --lock-message "Password is in #general"
37
+ npx mirrorbook deploy ./dist --slug my-demo --password "$PW" --lock-title "…" --lock-message "…"
38
+ npx mirrorbook access my-demo --clear-lock # back to the default copy
39
+ ```
40
+
41
+ The copy only appears on password-protected sites — setting it on a site with no password stores it but visitors never see it (the CLI prints a `note:` line in that case). Passing the option alone is enough to change it; you don't need to re-supply `--password`.
42
+
33
43
  Install this skill for Claude Code with `npx mirrorbook skill --install` (or `--dir ./.claude/skills` for one project); `mirrorbook skill` prints it.
34
44
 
35
- Other commands: `access <slug>`, `ls`, `status <slug>` (lists versions), `rollback <slug> <version>` (alias `set-default`; version is `3`, `#3`, or a deployment id), `rm-version <slug> <version> --yes`, `rm <slug> --yes`, `whoami`. Add `--json` to any of them.
45
+ Other commands: `pull <slug> [version] [-o file.zip]` (download a version's files as a zip; owner only, defaults to the live version), `access <slug>`, `ls`, `status <slug>` (lists versions), `rollback <slug> <version>` (alias `set-default`; version is `3`, `#3`, or a deployment id), `rm-version <slug> <version> --yes`, `rm <slug> --yes`, `whoami`. Add `--json` to any of them.
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  // src/cli.ts
4
4
  import { spawn } from "child_process";
5
- import { cp, mkdir as mkdir3, readFile as readFile4 } from "fs/promises";
5
+ import { cp, mkdir as mkdir3, readFile as readFile4, writeFile as writeFile3 } from "fs/promises";
6
6
  import { homedir as homedir3, hostname, platform } from "os";
7
7
  import path4 from "path";
8
8
  import { fileURLToPath as fileURLToPath2 } from "url";
@@ -108,7 +108,24 @@ function createClient(apiUrl, token) {
108
108
  }
109
109
  return json;
110
110
  }
111
+ async function download(p) {
112
+ const headers = { "user-agent": "mirrorbook-cli/0.1" };
113
+ if (token) headers.authorization = `Bearer ${token}`;
114
+ let res;
115
+ try {
116
+ res = await fetch(`${apiUrl}/api${p}`, { headers });
117
+ } catch (e) {
118
+ throw new CliError("network", `Can't reach ${apiUrl}: ${e.message}`, 1);
119
+ }
120
+ if (!res.ok) {
121
+ const json = await res.json().catch(() => ({}));
122
+ const code = json.error?.code ?? "http_error";
123
+ throw new CliError(code, json.error?.message ?? `HTTP ${res.status}`, exitFor(res.status, code), res.status);
124
+ }
125
+ return Buffer.from(await res.arrayBuffer());
126
+ }
111
127
  return {
128
+ download: (slug, id) => download(`/sites/${encodeURIComponent(slug)}/deployments/${encodeURIComponent(id)}/download`),
112
129
  me: () => call("GET", "/me"),
113
130
  deviceStart: (clientName) => call(
114
131
  "POST",
@@ -229,7 +246,7 @@ import { fileURLToPath } from "url";
229
246
  // package.json
230
247
  var package_default = {
231
248
  name: "mirrorbook",
232
- version: "0.3.0",
249
+ version: "0.5.0",
233
250
  description: "Publish HTML to a shareable URL. Agent-friendly: non-interactive, --json output, stable exit codes.",
234
251
  type: "module",
235
252
  bin: {
@@ -530,7 +547,18 @@ function parseExpiry(v, now = Date.now()) {
530
547
  if (Number.isNaN(at.getTime())) throw new CliError("usage", `Can't read expiry "${v}". Use 7d, 12h, 30m, or a date like 2026-12-31`, EXIT.usage);
531
548
  return at.toISOString();
532
549
  }
550
+ var LOCK_TITLE_MAX = 80;
551
+ var LOCK_MESSAGE_MAX = 300;
552
+ function checkLockLength(o) {
553
+ if (o.clearLock && (o.lockTitle !== void 0 || o.lockMessage !== void 0))
554
+ throw new CliError("usage", "--clear-lock can't be combined with --lock-title / --lock-message", EXIT.usage);
555
+ if (o.lockTitle && o.lockTitle.length > LOCK_TITLE_MAX)
556
+ throw new CliError("usage", `--lock-title is ${o.lockTitle.length} characters; the limit is ${LOCK_TITLE_MAX}`, EXIT.usage);
557
+ if (o.lockMessage && o.lockMessage.length > LOCK_MESSAGE_MAX)
558
+ throw new CliError("usage", `--lock-message is ${o.lockMessage.length} characters; the limit is ${LOCK_MESSAGE_MAX}`, EXIT.usage);
559
+ }
533
560
  async function applyAccess(api, slug, o) {
561
+ checkLockLength(o);
534
562
  const password = o.password ?? process.env.MIRRORBOOK_SITE_PASSWORD;
535
563
  const body = {};
536
564
  if (o.public) body.visibility = "public";
@@ -540,11 +568,26 @@ async function applyAccess(api, slug, o) {
540
568
  if (password) body.password = password;
541
569
  }
542
570
  if (o.expires && !o.public && !o.removePassword) body.passwordExpiresAt = o.expires === "never" ? null : parseExpiry(o.expires);
571
+ if (o.clearLock) {
572
+ body.lockTitle = "";
573
+ body.lockMessage = "";
574
+ } else {
575
+ if (o.lockTitle !== void 0) body.lockTitle = o.lockTitle;
576
+ if (o.lockMessage !== void 0) body.lockMessage = o.lockMessage;
577
+ }
543
578
  if (!Object.keys(body).length) return null;
544
579
  return (await api.updateSite(slug, body)).site;
545
580
  }
546
581
  var accessLine = (s) => s.passwordProtected ? `password-protected${s.passwordExpiresAt ? `, expires ${s.passwordExpiresAt.slice(0, 16).replace("T", " ")} UTC` : ", no expiry"}` : s.visibility === "unlisted" ? "unlisted" : "public";
547
- program.command("deploy").description("Publish a directory, .zip, .html, .md, or .txt file. Markdown and text are turned into a web page. Re-deploying the same slug publishes a new version.").argument("<path>", "directory (with index.html or README.md), a .zip/.html/.md/.txt file, or - for stdin").option("-s, --slug <slug>", "subdomain: <slug>.mirrorbook.store (random if omitted; a suffix is added if it's taken)").option("--strict-slug", "fail with exit code 2 instead of adding a suffix when the slug is taken").option("-t, --title <title>", "site title").addOption(new Option("-f, --format <format>", "treat the input as html, markdown, or text (default: from the file extension; stdin is auto-detected)").choices(["html", "markdown", "text"])).option("-w, --wait", "wait until processing finishes").option("--timeout <sec>", "max seconds to wait", "300").option("--password <password>", "protect the site with a password (makes it unlisted; env MIRRORBOOK_SITE_PASSWORD avoids shell history)").option("--expires <when>", "how long the password stays valid: 7d, 12h, a date like 2026-12-31, or never").action(async (input, o) => {
582
+ var lockLines = (s) => {
583
+ if (!s.lockTitle && !s.lockMessage) return [];
584
+ return [
585
+ ` lock: ${s.lockTitle ? JSON.stringify(s.lockTitle) : "(default title)"}${s.lockMessage ? ` / ${JSON.stringify(s.lockMessage)}` : ""}`,
586
+ // 文案只挂在密码页上,没有密码的站点访客永远看不到,提示一下免得白设
587
+ ...s.passwordProtected ? [] : [" note: no password set, so visitors never see this copy"]
588
+ ];
589
+ };
590
+ program.command("deploy").description("Publish a directory, .zip, .html, .md, or .txt file. Markdown and text are turned into a web page. Re-deploying the same slug publishes a new version.").argument("<path>", "directory (with index.html or README.md), a .zip/.html/.md/.txt file, or - for stdin").option("-s, --slug <slug>", "subdomain: <slug>.mirrorbook.store (random if omitted; a suffix is added if it's taken)").option("--strict-slug", "fail with exit code 2 instead of adding a suffix when the slug is taken").option("-t, --title <title>", "site title").addOption(new Option("-f, --format <format>", "treat the input as html, markdown, or text (default: from the file extension; stdin is auto-detected)").choices(["html", "markdown", "text"])).option("-w, --wait", "wait until processing finishes").option("--timeout <sec>", "max seconds to wait", "300").option("--password <password>", "protect the site with a password (makes it unlisted; env MIRRORBOOK_SITE_PASSWORD avoids shell history)").option("--expires <when>", "how long the password stays valid: 7d, 12h, a date like 2026-12-31, or never").option("--lock-title <text>", `title shown on the password page (max ${LOCK_TITLE_MAX} chars)`).option("--lock-message <text>", `message shown above the password box, e.g. how to get the password (max ${LOCK_MESSAGE_MAX} chars)`).option("--clear-lock", "restore the default password page copy").action(async (input, o) => {
548
591
  const api = await client();
549
592
  const { blob, name, files, format } = await pack(input, o.format);
550
593
  const form = new FormData();
@@ -564,18 +607,22 @@ program.command("deploy").description("Publish a directory, .zip, .html, .md, or
564
607
  ...slugAdjusted && requestedSlug ? [` note: ${requestedSlug} is taken, using ${site.slug}. Re-deploying with --slug ${requestedSlug} updates this same site.`] : [],
565
608
  ` url: ${site.url}`,
566
609
  ...site.passwordProtected ? [` access: ${accessLine(site)}`] : [],
610
+ ...lockLines(site),
567
611
  ` preview: ${deployment.previewUrl}`,
568
612
  ` status: ${describe(deployment)}`
569
613
  ].join("\n"),
570
- { url: site.url, visibility: site.visibility, passwordProtected: site.passwordProtected, passwordExpiresAt: site.passwordExpiresAt, previewUrl: deployment.previewUrl, slug: site.slug, siteId: site.id, deploymentId: deployment.id, status: deployment.status, error: deployment.error, errorCode: deployment.errorCode, errorParams: deployment.errorParams, number: deployment.number, created, requestedSlug, slugAdjusted }
614
+ { url: site.url, visibility: site.visibility, passwordProtected: site.passwordProtected, passwordExpiresAt: site.passwordExpiresAt, lockTitle: site.lockTitle, lockMessage: site.lockMessage, previewUrl: deployment.previewUrl, slug: site.slug, siteId: site.id, deploymentId: deployment.id, status: deployment.status, error: deployment.error, errorCode: deployment.errorCode, errorParams: deployment.errorParams, number: deployment.number, created, requestedSlug, slugAdjusted }
571
615
  );
572
616
  process.exitCode = deploymentExit(deployment);
573
617
  });
574
- program.command("access").description("Set or change who can open a site: a password (with an expiry), or back to public").argument("<slug>").option("--password <password>", "set or change the password (makes the site unlisted; env MIRRORBOOK_SITE_PASSWORD avoids shell history)").option("--expires <when>", "password validity: 7d, 12h, a date like 2026-12-31, or never. After it, the site can't be opened until you set a new one").option("--remove-password", "remove the password (the site stays unlisted)").option("--public", "make the site public again (also removes the password)").action(async (slug, o) => {
618
+ program.command("access").description("Set or change who can open a site: a password (with an expiry), the password page copy, or back to public").argument("<slug>").option("--password <password>", "set or change the password (makes the site unlisted; env MIRRORBOOK_SITE_PASSWORD avoids shell history)").option("--expires <when>", "password validity: 7d, 12h, a date like 2026-12-31, or never. After it, the site can't be opened until you set a new one").option("--remove-password", "remove the password (the site stays unlisted)").option("--public", "make the site public again (also removes the password)").option("--lock-title <text>", `title shown on the password page (max ${LOCK_TITLE_MAX} chars)`).option("--lock-message <text>", `message shown above the password box, e.g. how to get the password (max ${LOCK_MESSAGE_MAX} chars)`).option("--clear-lock", "restore the default password page copy").action(async (slug, o) => {
575
619
  const api = await client();
576
620
  const site = await applyAccess(api, slug, o);
577
- if (!site) throw new CliError("usage", "Nothing to change. Pass --password, --expires, --remove-password, or --public", EXIT.usage);
578
- out(`${site.slug}: ${accessLine(site)}`, { slug: site.slug, visibility: site.visibility, passwordProtected: site.passwordProtected, passwordExpiresAt: site.passwordExpiresAt });
621
+ if (!site) throw new CliError("usage", "Nothing to change. Pass --password, --expires, --remove-password, --public, --lock-title, --lock-message, or --clear-lock", EXIT.usage);
622
+ out(
623
+ [`${site.slug}: ${accessLine(site)}`, ...lockLines(site)].join("\n"),
624
+ { slug: site.slug, visibility: site.visibility, passwordProtected: site.passwordProtected, passwordExpiresAt: site.passwordExpiresAt, lockTitle: site.lockTitle, lockMessage: site.lockMessage }
625
+ );
579
626
  });
580
627
  program.command("ls").description("List your sites").action(async () => {
581
628
  const { sites } = await (await client()).sites();
@@ -609,6 +656,16 @@ program.command("rollback").alias("set-default").description("Make an approved v
609
656
  await api.rollback(slug, d.id);
610
657
  out(`${slug} now serves #${d.number}`, { ok: true, slug, deploymentId: d.id, number: d.number });
611
658
  });
659
+ program.command("pull").description("Download a version's files as a zip (owner only; defaults to the live version)").argument("<slug>").argument("[version]", "version number (3 or #3) or deployment id; default: the live version").option("-o, --output <file>", "where to save the zip (default: ./<slug>-v<N>.zip)").action(async (slug, ref, o) => {
660
+ const api = await client();
661
+ const { site, deployments } = await api.site(slug);
662
+ const d = ref ? await resolveVersion(api, slug, ref) : deployments.find((x) => x.id === site.activeDeploymentId);
663
+ if (!d) throw new CliError("not_found", `${slug} has no live version. Pass a version number`, EXIT.usage);
664
+ const file = path4.resolve(o.output ?? `${slug}-v${d.number}.zip`);
665
+ const buf = await api.download(slug, d.id);
666
+ await writeFile3(file, buf);
667
+ out(`Saved ${slug} #${d.number} to ${file} (${buf.length} bytes)`, { ok: true, slug, deploymentId: d.id, number: d.number, file, bytes: buf.length });
668
+ });
612
669
  program.command("rm-version").description("Delete one version (not the default one)").argument("<slug>").argument("<version>", "version number (3 or #3) or deployment id").option("-y, --yes", "skip the confirmation (required when not a TTY)").action(async (slug, ref, o) => {
613
670
  const api = await client();
614
671
  const d = await resolveVersion(api, slug, ref);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mirrorbook",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Publish HTML to a shareable URL. Agent-friendly: non-interactive, --json output, stable exit codes.",
5
5
  "type": "module",
6
6
  "bin": {