mirrorbook 0.1.2 → 0.3.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.
- package/SKILL.md +5 -1
- package/dist/cli.js +138 -4
- package/package.json +1 -1
package/SKILL.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: mirrorbook
|
|
3
|
-
description: Publish a static HTML page, folder, or zip to a public URL
|
|
3
|
+
description: Publish a static HTML page, folder, or zip to a public URL (<slug>.mirrorbook.store) via mirrorbook.mixdao.world with the `mirrorbook` CLI. Use when the user wants to share, host, or deploy an HTML file or a built static site.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Publishing HTML with mirrorbook
|
|
7
7
|
|
|
8
8
|
Sign in once with `npx mirrorbook login https://mirrorbook.mixdao.world`. It prints a URL and a code, opens the browser, and waits until the user approves. Ask the user to approve it; don't try to approve it yourself. In CI, set `MIRRORBOOK_TOKEN` (and `MIRRORBOOK_API_URL` for a non-default server) instead.
|
|
9
9
|
|
|
10
|
+
**Workflow.** After login, and before choosing a slug, run `npx mirrorbook ls --json` to see the user's existing sites. If the content clearly belongs to one of them (matching title or purpose), re-deploy to that slug to publish a new version; otherwise pick a new slug. Only ask the user when it is ambiguous, and offer the real slugs from `ls` as options. After deploying, report the final `url`, and mention `previewUrl` and `rollback` if the user may want to compare versions.
|
|
11
|
+
|
|
10
12
|
Several servers can be saved: `mirrorbook servers` lists them, `mirrorbook use <name>` switches, `--server <name>` picks one for a single command.
|
|
11
13
|
|
|
12
14
|
```bash
|
|
@@ -28,4 +30,6 @@ Versions: every deploy gets a number (`#1`, `#2`, …, in the `number` field). T
|
|
|
28
30
|
|
|
29
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.
|
|
30
32
|
|
|
33
|
+
Install this skill for Claude Code with `npx mirrorbook skill --install` (or `--dir ./.claude/skills` for one project); `mirrorbook skill` prints it.
|
|
34
|
+
|
|
31
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.
|
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
4
|
import { spawn } from "child_process";
|
|
5
|
-
import {
|
|
5
|
+
import { cp, mkdir as mkdir3, readFile as readFile4 } from "fs/promises";
|
|
6
|
+
import { homedir as homedir3, hostname, platform } from "os";
|
|
7
|
+
import path4 from "path";
|
|
8
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
6
9
|
import { createInterface } from "readline/promises";
|
|
7
10
|
import { Command, Option } from "commander";
|
|
8
11
|
|
|
@@ -217,10 +220,16 @@ async function pack(input, format) {
|
|
|
217
220
|
return { blob: new Blob([buf]), name: path2.basename(input), format: f };
|
|
218
221
|
}
|
|
219
222
|
|
|
223
|
+
// src/update.ts
|
|
224
|
+
import { readFile as readFile3, mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
|
|
225
|
+
import { homedir as homedir2 } from "os";
|
|
226
|
+
import path3 from "path";
|
|
227
|
+
import { fileURLToPath } from "url";
|
|
228
|
+
|
|
220
229
|
// package.json
|
|
221
230
|
var package_default = {
|
|
222
231
|
name: "mirrorbook",
|
|
223
|
-
version: "0.
|
|
232
|
+
version: "0.3.0",
|
|
224
233
|
description: "Publish HTML to a shareable URL. Agent-friendly: non-interactive, --json output, stable exit codes.",
|
|
225
234
|
type: "module",
|
|
226
235
|
bin: {
|
|
@@ -237,7 +246,8 @@ var package_default = {
|
|
|
237
246
|
scripts: {
|
|
238
247
|
dev: "tsx src/cli.ts",
|
|
239
248
|
build: "tsup",
|
|
240
|
-
typecheck: "tsc -p ."
|
|
249
|
+
typecheck: "tsc -p .",
|
|
250
|
+
prepack: "tsup"
|
|
241
251
|
},
|
|
242
252
|
devDependencies: {
|
|
243
253
|
"@mirrorbook/shared": "workspace:*"
|
|
@@ -248,10 +258,108 @@ var package_default = {
|
|
|
248
258
|
}
|
|
249
259
|
};
|
|
250
260
|
|
|
261
|
+
// src/update.ts
|
|
262
|
+
var CACHE = path3.join(path3.dirname(configPath), "update.json");
|
|
263
|
+
var DAY = 24 * 60 * 60 * 1e3;
|
|
264
|
+
var UPDATE_COMMAND = "npm i -g mirrorbook@latest";
|
|
265
|
+
var SKILL_COMMAND = "mirrorbook skill --install";
|
|
266
|
+
function isNewer(latest, current) {
|
|
267
|
+
const n = (v) => (v.split("-")[0] ?? "").split(".").map((x) => Number.parseInt(x, 10) || 0);
|
|
268
|
+
const [a, b] = [n(latest), n(current)];
|
|
269
|
+
for (let i = 0; i < 3; i++) if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) > (b[i] ?? 0);
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
async function readCache() {
|
|
273
|
+
try {
|
|
274
|
+
return JSON.parse(await readFile3(CACHE, "utf8"));
|
|
275
|
+
} catch {
|
|
276
|
+
return void 0;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
async function writeCache(c) {
|
|
280
|
+
try {
|
|
281
|
+
await mkdir2(path3.dirname(CACHE), { recursive: true, mode: 448 });
|
|
282
|
+
await writeFile2(CACHE, JSON.stringify(c));
|
|
283
|
+
} catch {
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
async function fetchLatest(timeoutMs) {
|
|
287
|
+
try {
|
|
288
|
+
const res = await fetch("https://registry.npmjs.org/mirrorbook/latest", { signal: AbortSignal.timeout(timeoutMs) });
|
|
289
|
+
if (!res.ok) return void 0;
|
|
290
|
+
return (await res.json()).version;
|
|
291
|
+
} catch {
|
|
292
|
+
return void 0;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
async function staleSkills() {
|
|
296
|
+
let bundled;
|
|
297
|
+
try {
|
|
298
|
+
bundled = await readFile3(fileURLToPath(new URL("../SKILL.md", import.meta.url)), "utf8");
|
|
299
|
+
} catch {
|
|
300
|
+
return { installed: [], stale: [] };
|
|
301
|
+
}
|
|
302
|
+
const candidates = [path3.join(homedir2(), ".claude", "skills", "mirrorbook", "SKILL.md"), path3.resolve(".claude", "skills", "mirrorbook", "SKILL.md")];
|
|
303
|
+
const installed = [];
|
|
304
|
+
const stale = [];
|
|
305
|
+
for (const p of candidates) {
|
|
306
|
+
try {
|
|
307
|
+
const text = await readFile3(p, "utf8");
|
|
308
|
+
installed.push(p);
|
|
309
|
+
if (text !== bundled) stale.push(p);
|
|
310
|
+
} catch {
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return { installed, stale };
|
|
314
|
+
}
|
|
315
|
+
async function checkUpdate() {
|
|
316
|
+
const latest = await fetchLatest(5e3);
|
|
317
|
+
if (latest) await writeCache({ ...await readCache(), checkedAt: Date.now(), latest });
|
|
318
|
+
const skill = await staleSkills();
|
|
319
|
+
return {
|
|
320
|
+
current: package_default.version,
|
|
321
|
+
latest: latest ?? null,
|
|
322
|
+
updateAvailable: latest ? isNewer(latest, package_default.version) : false,
|
|
323
|
+
updateCommand: UPDATE_COMMAND,
|
|
324
|
+
skill: { installed: skill.installed, stale: skill.stale, updateCommand: SKILL_COMMAND },
|
|
325
|
+
error: latest ? null : "could not reach the npm registry"
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
async function passiveNotice() {
|
|
329
|
+
if (process.env.MIRRORBOOK_NO_UPDATE_CHECK === "1") return;
|
|
330
|
+
const now = Date.now();
|
|
331
|
+
let cache = await readCache() ?? { checkedAt: 0 };
|
|
332
|
+
if (now - cache.checkedAt > DAY) {
|
|
333
|
+
const latest = await fetchLatest(1500);
|
|
334
|
+
cache = { ...cache, checkedAt: now, latest: latest ?? cache.latest };
|
|
335
|
+
await writeCache(cache);
|
|
336
|
+
}
|
|
337
|
+
const lines = [];
|
|
338
|
+
if (cache.latest && isNewer(cache.latest, package_default.version)) lines.push(`mirrorbook ${cache.latest} is available (you have ${package_default.version}). Update: ${UPDATE_COMMAND}`);
|
|
339
|
+
const { stale } = await staleSkills();
|
|
340
|
+
if (stale.length) lines.push(`The installed mirrorbook skill is out of date (${stale.join(", ")}). Refresh: ${SKILL_COMMAND}`);
|
|
341
|
+
if (!lines.length || cache.notifiedAt && now - cache.notifiedAt < DAY) return;
|
|
342
|
+
await writeCache({ ...cache, notifiedAt: now });
|
|
343
|
+
process.stderr.write(`
|
|
344
|
+
${lines.map((l) => `notice: ${l}`).join("\n")}
|
|
345
|
+
`);
|
|
346
|
+
}
|
|
347
|
+
|
|
251
348
|
// src/cli.ts
|
|
252
349
|
var program = new Command().name("mirrorbook").description("Publish HTML to a shareable URL on mirrorbook.mixdao.world").version(package_default.version).addOption(new Option("--json", "print one JSON object to stdout (also MIRRORBOOK_JSON=1)").default(process.env.MIRRORBOOK_JSON === "1")).option("-n, --server <name>", "use a saved server for this command (env MIRRORBOOK_SERVER); see `mirrorbook servers`").option("--api-url <url>", "server URL, overrides the saved one (env MIRRORBOOK_API_URL)").option("--token <token>", "API token, overrides the saved one (env MIRRORBOOK_TOKEN)").showHelpAfterError().addHelpText(
|
|
253
350
|
"after",
|
|
254
351
|
`
|
|
352
|
+
Recommended workflow:
|
|
353
|
+
First time login \u2192 ls \u2192 deploy
|
|
354
|
+
Update a site ls (find the existing slug) \u2192 deploy <path> --slug <slug> --wait \u2192 status <slug>
|
|
355
|
+
Share privately deploy <path> --slug <slug> --password <pw> --expires 7d (or: access <slug> ...)
|
|
356
|
+
Went wrong status <slug> \u2192 rollback <slug> <version>
|
|
357
|
+
Use with AI agents mirrorbook skill --install (installs the usage guide into Claude Code)
|
|
358
|
+
After upgrading mirrorbook update (new CLI version? skill out of date? prints the fix commands)
|
|
359
|
+
|
|
360
|
+
Always run \`mirrorbook ls\` before picking a slug: re-deploying an existing slug publishes a new
|
|
361
|
+
version of that site, a new slug creates a new site.
|
|
362
|
+
|
|
255
363
|
Exit codes: 0 ok \xB7 1 error \xB7 2 usage \xB7 3 auth \xB7 4 quota \xB7 5 deployment failed or rejected
|
|
256
364
|
|
|
257
365
|
Examples:
|
|
@@ -260,6 +368,8 @@ Examples:
|
|
|
260
368
|
$ cat page.html | mirrorbook deploy - --slug quick-note
|
|
261
369
|
$ mirrorbook deploy notes.md --slug my-notes # Markdown \u2192 web page
|
|
262
370
|
$ pbpaste | mirrorbook deploy - --format markdown
|
|
371
|
+
$ mirrorbook ls # existing sites and their slugs
|
|
372
|
+
$ mirrorbook skill --install # let Claude Code use this CLI automatically
|
|
263
373
|
$ mirrorbook servers # saved servers; switch with \`mirrorbook use <name>\`
|
|
264
374
|
$ MIRRORBOOK_TOKEN=mb_xxx MIRRORBOOK_API_URL=https://mirrorbook.mixdao.world mirrorbook ls --json`
|
|
265
375
|
);
|
|
@@ -385,6 +495,29 @@ program.command("use").description("Switch the current server").argument("<name>
|
|
|
385
495
|
await saveConfig(cfg);
|
|
386
496
|
out(`Now using ${name} (${cfg.servers[name].url})`, { ok: true, server: name, url: cfg.servers[name].url });
|
|
387
497
|
});
|
|
498
|
+
program.command("skill").description("Print the agent skill (SKILL.md) for this CLI, or install it for Claude Code with --install").option("--install", "copy SKILL.md to ~/.claude/skills/mirrorbook/ (Claude Code loads it automatically)").option("--dir <dir>", "install into <dir>/mirrorbook/ instead, e.g. ./.claude/skills for this project only").action(async (o) => {
|
|
499
|
+
const src = fileURLToPath2(new URL("../SKILL.md", import.meta.url));
|
|
500
|
+
if (!o.install && !o.dir) {
|
|
501
|
+
const text = await readFile4(src, "utf8");
|
|
502
|
+
if (g().json) out("", { path: src, content: text });
|
|
503
|
+
else process.stdout.write(text);
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
const dest = path4.join(o.dir ? path4.resolve(o.dir) : path4.join(homedir3(), ".claude", "skills"), "mirrorbook");
|
|
507
|
+
await mkdir3(dest, { recursive: true });
|
|
508
|
+
await cp(src, path4.join(dest, "SKILL.md"));
|
|
509
|
+
out(`Installed skill to ${dest}/SKILL.md. Restart Claude Code to pick it up.`, { ok: true, path: path4.join(dest, "SKILL.md") });
|
|
510
|
+
});
|
|
511
|
+
program.command("update").description("Check npm for a newer mirrorbook and whether the installed Claude Code skill is out of date").action(async () => {
|
|
512
|
+
const r = await checkUpdate();
|
|
513
|
+
const lines = [`mirrorbook ${r.current}${r.latest ? ` (latest ${r.latest})` : ""}`];
|
|
514
|
+
if (r.error) lines.push(`! ${r.error}`);
|
|
515
|
+
else lines.push(r.updateAvailable ? `Update available: ${r.updateCommand}` : "Up to date");
|
|
516
|
+
if (r.skill.stale.length) lines.push(`Skill out of date: ${r.skill.stale.join(", ")} \u2192 ${r.skill.updateCommand}`);
|
|
517
|
+
else if (r.skill.installed.length) lines.push("Skill up to date");
|
|
518
|
+
else lines.push(`Skill not installed \u2192 ${r.skill.updateCommand}`);
|
|
519
|
+
out(lines.join("\n"), r);
|
|
520
|
+
});
|
|
388
521
|
program.command("whoami").description("Show the current server and account").action(async () => {
|
|
389
522
|
const { name, apiUrl } = await auth();
|
|
390
523
|
const { user } = await (await client()).me();
|
|
@@ -411,7 +544,7 @@ async function applyAccess(api, slug, o) {
|
|
|
411
544
|
return (await api.updateSite(slug, body)).site;
|
|
412
545
|
}
|
|
413
546
|
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";
|
|
414
|
-
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.
|
|
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) => {
|
|
415
548
|
const api = await client();
|
|
416
549
|
const { blob, name, files, format } = await pack(input, o.format);
|
|
417
550
|
const form = new FormData();
|
|
@@ -502,6 +635,7 @@ program.command("rm").description("Delete a site and all its versions").argument
|
|
|
502
635
|
});
|
|
503
636
|
try {
|
|
504
637
|
await program.parseAsync();
|
|
638
|
+
if (process.argv[2] !== "update") await passiveNotice();
|
|
505
639
|
} catch (e) {
|
|
506
640
|
const err = e instanceof CliError ? e : new CliError("internal", e.message, EXIT.error);
|
|
507
641
|
if (g().json) process.stdout.write(`${JSON.stringify({ error: { code: err.code, message: err.message } })}
|