frameboard 0.7.0 → 0.8.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/dist/cli.js CHANGED
@@ -4,7 +4,7 @@ import childProcess, { execFile, spawn } from "node:child_process";
4
4
  import { EventEmitter, once } from "node:events";
5
5
  import * as sp from "node:path";
6
6
  import path, { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
7
- import fs, { createReadStream, existsSync, readFileSync, realpathSync, renameSync, rmSync, stat, statSync, unwatchFile, watch, watchFile, writeFileSync } from "node:fs";
7
+ import fs, { copyFileSync, createReadStream, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, stat, statSync, unwatchFile, watch, watchFile, writeFileSync } from "node:fs";
8
8
  import process$1, { versions } from "node:process";
9
9
  import { isDeepStrictEqual, promisify, stripVTControlCharacters } from "node:util";
10
10
  import { fileURLToPath } from "node:url";
@@ -9319,13 +9319,12 @@ function findBoard(cwd) {
9319
9319
  }
9320
9320
  /**
9321
9321
  * The board `serve` shows, started when none exists: at `--root` when given,
9322
- * else the board the walk finds, else `.frameboard/` at the repository top,
9323
- * else `.frameboard/` in `cwd`. A board folder holding no project gets one
9322
+ * else the board the walk finds, else `.frameboard/` in `cwd`. A board folder holding no project gets one
9324
9323
  * project with one empty page, and one missing only `board.json` gets that
9325
9324
  * alone.
9326
9325
  */
9327
9326
  async function startBoard({ root, cwd }, now = /* @__PURE__ */ new Date()) {
9328
- const target = root === void 0 ? findBoard(cwd) ?? join(findRepositoryTop(cwd) ?? cwd, ".frameboard") : resolve(cwd, root);
9327
+ const target = root === void 0 ? findBoard(cwd) ?? join(cwd, ".frameboard") : resolve(cwd, root);
9329
9328
  await mkdir(target, { recursive: true });
9330
9329
  if (!existsSync(join(target, "board.json"))) await writeRecord(join(target, BOARD_FILE), { version: 1 });
9331
9330
  let created = false;
@@ -9344,12 +9343,6 @@ async function startBoard({ root, cwd }, now = /* @__PURE__ */ new Date()) {
9344
9343
  created
9345
9344
  };
9346
9345
  }
9347
- function findRepositoryTop(cwd) {
9348
- for (let dir = resolve(cwd);; dir = dirname(dir)) {
9349
- if (existsSync(join(dir, ".git"))) return dir;
9350
- if (dirname(dir) === dir) return null;
9351
- }
9352
- }
9353
9346
  async function isDirectory(path) {
9354
9347
  try {
9355
9348
  return (await stat$1(path)).isDirectory();
@@ -9360,7 +9353,7 @@ async function isDirectory(path) {
9360
9353
  }
9361
9354
  //#endregion
9362
9355
  //#region package.json
9363
- var version$1 = "0.7.0";
9356
+ var version$1 = "0.8.0";
9364
9357
  var dependencies = { "playwright-core": "1.64.1" };
9365
9358
  //#endregion
9366
9359
  //#region src/shared/version.ts
@@ -13449,11 +13442,11 @@ const setCookie = (c, name, value, opt) => {
13449
13442
  */
13450
13443
  function isWriter(headers, access) {
13451
13444
  const bearer = /^Bearer (.+)$/.exec(headers.authorization ?? "")?.[1];
13452
- if (bearer !== void 0 && matches(bearer, access.token())) return true;
13445
+ if (bearer !== void 0 && matches$1(bearer, access.token())) return true;
13453
13446
  const { origin } = headers;
13454
13447
  if (origin === void 0 || !isOwnOrigin(origin, access)) return false;
13455
13448
  const cookie = readCookie(headers.cookie, access.cookieName);
13456
- return cookie !== void 0 && matches(cookie, access.key);
13449
+ return cookie !== void 0 && matches$1(cookie, access.key);
13457
13450
  }
13458
13451
  /** Hono middleware answering 401 in the envelope to anyone who is not a writer. */
13459
13452
  function requireWriter(access) {
@@ -13485,7 +13478,7 @@ function readCookie(header, name) {
13485
13478
  if (at !== -1 && part.slice(0, at).trim() === name) return part.slice(at + 1).trim();
13486
13479
  }
13487
13480
  }
13488
- function matches(given, expected) {
13481
+ function matches$1(given, expected) {
13489
13482
  if (expected === null) return false;
13490
13483
  const a = Buffer.from(given);
13491
13484
  const b = Buffer.from(expected);
@@ -13497,19 +13490,23 @@ const COOKIE_MAX_AGE_S = 3456e4;
13497
13490
  /**
13498
13491
  * How a tab becomes a writer. A redeem URL carries a single-use ticket that
13499
13492
  * trades for the board's cookie, and answers a 303 home either way so a used
13500
- * ticket still lands on a board that reads.
13493
+ * ticket still lands on a board that reads. A failed redeem lands on
13494
+ * `/?link=expired`, the flag the client's expired-link toast reads.
13501
13495
  */
13502
13496
  function accessRoutes(access, tickets) {
13503
13497
  const app = new Hono();
13504
13498
  app.get("/api/access/redeem", (c) => {
13505
13499
  const ticket = c.req.query("ticket");
13506
- if (ticket !== void 0 && tickets.redeem(ticket)) setCookie(c, access.cookieName, access.key, {
13507
- httpOnly: true,
13508
- sameSite: "Strict",
13509
- path: "/api",
13510
- maxAge: COOKIE_MAX_AGE_S
13511
- });
13512
- return c.redirect("/", 303);
13500
+ if (ticket !== void 0 && tickets.redeem(ticket)) {
13501
+ setCookie(c, access.cookieName, access.key, {
13502
+ httpOnly: true,
13503
+ sameSite: "Strict",
13504
+ path: "/api",
13505
+ maxAge: COOKIE_MAX_AGE_S
13506
+ });
13507
+ return c.redirect("/", 303);
13508
+ }
13509
+ return c.redirect("/?link=expired", 303);
13513
13510
  });
13514
13511
  app.post("/api/access/ticket", (c) => {
13515
13512
  if (!isWriter({ authorization: c.req.header("authorization") }, access)) return c.json({
@@ -13520,10 +13517,14 @@ function accessRoutes(access, tickets) {
13520
13517
  }
13521
13518
  }, 401);
13522
13519
  const url = new URL("/api/access/redeem", c.req.url);
13523
- url.searchParams.set("ticket", tickets.mint());
13520
+ const { ticket, expiresAt } = tickets.mint();
13521
+ url.searchParams.set("ticket", ticket);
13524
13522
  return c.json({
13525
13523
  ok: true,
13526
- data: { url: url.toString() }
13524
+ data: {
13525
+ url: url.toString(),
13526
+ expiresAt
13527
+ }
13527
13528
  });
13528
13529
  });
13529
13530
  return app;
@@ -27437,7 +27438,7 @@ function assetsDirOf(source) {
27437
27438
  return join(source.projectDir, ASSETS_FOLDER);
27438
27439
  }
27439
27440
  /** Line and column of a span in `text`, both counted from 1. */
27440
- function locate(text, startOffset, endOffset) {
27441
+ function locate$1(text, startOffset, endOffset) {
27441
27442
  let line = 1;
27442
27443
  let lineStart = 0;
27443
27444
  for (let index = text.indexOf("\n"); index !== -1 && index < startOffset;) {
@@ -27538,7 +27539,7 @@ function readThemeColors(source) {
27538
27539
  const end = sheet.offset + (node.source?.end?.offset ?? 0);
27539
27540
  firstColor = {
27540
27541
  path: boardPath(source.root, sheet.path),
27541
- location: locate(text, start, end)
27542
+ location: locate$1(text, start, end)
27542
27543
  };
27543
27544
  }
27544
27545
  });
@@ -28415,6 +28416,78 @@ function removeAttribute(source, element, name) {
28415
28416
  return splice(source, start, span.endOffset, "");
28416
28417
  }
28417
28418
  //#endregion
28419
+ //#region src/server/edit/element-span.ts
28420
+ const OTHER$1 = {
28421
+ before: "after",
28422
+ after: "before"
28423
+ };
28424
+ /** The source range a scope covers on a stated element, or undefined for an implied one. */
28425
+ function rangeOf(element, scope) {
28426
+ const location = element.sourceCodeLocation;
28427
+ if (!location?.startTag) return void 0;
28428
+ return scope === "start-tag" ? [location.startTag.startOffset, location.startTag.endOffset] : [location.startOffset, location.endOffset];
28429
+ }
28430
+ /** The bytes of one element a scope covers, as `ElementSpan` records them. */
28431
+ function spanText(source, element, scope) {
28432
+ const range = rangeOf(element, scope);
28433
+ return range ? source.slice(...range) : "";
28434
+ }
28435
+ function matches(source, element, scope, text) {
28436
+ const range = element && rangeOf(element, scope);
28437
+ return range && source.slice(...range) === text ? range : void 0;
28438
+ }
28439
+ /**
28440
+ * The element reading `span[side]`: the one at the recorded index while the
28441
+ * element count is unchanged, else the one element whose bytes match, else
28442
+ * none, since guessing between two would write over the wrong one.
28443
+ */
28444
+ function locate(source, tree, span, side) {
28445
+ const text = span[side];
28446
+ if (tree.elements.length === span.count) {
28447
+ const range = matches(source, tree.elements[span.index], span.scope, text);
28448
+ return range && {
28449
+ index: span.index,
28450
+ range
28451
+ };
28452
+ }
28453
+ const found = tree.elements.flatMap((element, index) => {
28454
+ const range = matches(source, element, span.scope, text);
28455
+ return range ? [{
28456
+ index,
28457
+ range
28458
+ }] : [];
28459
+ });
28460
+ return found.length === 1 ? found[0] : void 0;
28461
+ }
28462
+ /** Whether the frame still holds the edited element as `side` of the edit left it. */
28463
+ function holdsSpan(source, span, side) {
28464
+ return locate(source, parseFrame(source), span, side) !== void 0;
28465
+ }
28466
+ /**
28467
+ * Finds the element reading `side` of the span and writes the other side in
28468
+ * its place, leaving every other byte as it stands. Answers undefined when the
28469
+ * element is not found, or when the swap would leave it unfound, as a write
28470
+ * the parser reads across element bounds would.
28471
+ */
28472
+ function swapSpan(source, span, side) {
28473
+ const tree = parseFrame(source);
28474
+ const found = locate(source, tree, span, side);
28475
+ if (!found) return void 0;
28476
+ const [start, end] = found.range;
28477
+ const html = source.slice(0, start) + span[OTHER$1[side]] + source.slice(end);
28478
+ const moved = {
28479
+ ...span,
28480
+ index: found.index,
28481
+ count: tree.elements.length
28482
+ };
28483
+ const written = parseFrame(html);
28484
+ if (written.elements.length !== moved.count || !matches(html, written.elements[moved.index], span.scope, span[OTHER$1[side]])) return;
28485
+ return {
28486
+ html,
28487
+ span: moved
28488
+ };
28489
+ }
28490
+ //#endregion
28418
28491
  //#region src/server/edit/style.ts
28419
28492
  /**
28420
28493
  * The longhands a shorthand write drops, so a later longhand in the attribute
@@ -28736,7 +28809,19 @@ function applyEdit(source, address, change) {
28736
28809
  const after = parseFrame(written.html);
28737
28810
  const target = after.elements[address.index];
28738
28811
  if (!target || !holdsValue(target, normalized) || !changesOnlyTarget(before, after, address.index, normalized)) return refuse("verify-failed", `the edit to <${element.tagName}> would change more than that element, so nothing was written`);
28739
- return written;
28812
+ const scope = normalized.kind === "text" ? "element" : "start-tag";
28813
+ const span = {
28814
+ scope,
28815
+ index: address.index,
28816
+ count: before.elements.length,
28817
+ before: spanText(source, element, scope),
28818
+ after: spanText(written.html, target, scope)
28819
+ };
28820
+ return {
28821
+ ok: true,
28822
+ html: written.html,
28823
+ span
28824
+ };
28740
28825
  }
28741
28826
  //#endregion
28742
28827
  //#region src/server/edit/frame-file.ts
@@ -28769,7 +28854,8 @@ function editFrameFile(path, address, change) {
28769
28854
  renameSync(temp, path);
28770
28855
  return {
28771
28856
  ok: true,
28772
- hash: contentHash(applied.html)
28857
+ hash: contentHash(applied.html),
28858
+ span: applied.span
28773
28859
  };
28774
28860
  }
28775
28861
  //#endregion
@@ -28841,9 +28927,9 @@ const editSchema = object$1({
28841
28927
  /**
28842
28928
  * A hand edit of one element, behind `requireWriter`, its body mirroring
28843
28929
  * `edit`'s flags with the hash required, since the board always holds the
28844
- * one it rendered. It writes through `editFrameFile`, records the frame's two
28845
- * states as one step, and answers the `edit` record. Each refusal the writer
28846
- * returns answers 409 with its code, `stale-address` among them.
28930
+ * one it rendered. It writes through `editFrameFile`, records the edited
28931
+ * element's span as one step, and answers the `edit` record. Each refusal
28932
+ * the writer returns answers 409 with its code, `stale-address` among them.
28847
28933
  */
28848
28934
  function editRoutes(root, access, history) {
28849
28935
  const app = new Hono();
@@ -28852,7 +28938,6 @@ function editRoutes(root, access, history) {
28852
28938
  const frame = await resolveFrameRef(root, body.ref, { cwd: root });
28853
28939
  const ref = `${frame.project}/${frame.page}/${frame.name}`;
28854
28940
  await refuseClaimed(root, [ref], /* @__PURE__ */ new Date());
28855
- const before = readFileSync(frame.path);
28856
28941
  const result = editFrameFile(frame.path, {
28857
28942
  index: body.index,
28858
28943
  hash: body.hash
@@ -28868,10 +28953,9 @@ function editRoutes(root, access, history) {
28868
28953
  }
28869
28954
  }
28870
28955
  }, 409);
28871
- const after = readFileSync(frame.path);
28872
- if (contentHash(after) === result.hash && !after.equals(before)) {
28956
+ if (result.span.before !== result.span.after) {
28873
28957
  const journal = history.journal();
28874
- journal.content(frame.path, ref, before, after);
28958
+ journal.element(frame.path, ref, result.span);
28875
28959
  history.record({
28876
28960
  id: journal.id,
28877
28961
  changes: journal.changes,
@@ -36519,7 +36603,7 @@ async function writeImages(rendered) {
36519
36603
  //#endregion
36520
36604
  //#region src/cli/commands/capture.ts
36521
36605
  function registerCapture(program, context) {
36522
- const { io, facesDir } = context;
36606
+ const { io } = context;
36523
36607
  act(addVerb(program, "capture", "Write PNGs of a frame, or of every visible frame of a page, in light, dark, or both", { project: true }).argument("[frame-ref]", "a frame ref, <page>/<frame> or <project>/<page>/<frame>, or a path to its .html file").option("--page <page-ref>", "capture every visible frame of this page, <page> or <project>/<page>, in place of one frame").option("--composite", "with --page, one image of the page with each frame at its layout position").addOption(new Option("--theme <theme>", "the theme to capture").choices([
36524
36608
  "light",
36525
36609
  "dark",
@@ -36544,7 +36628,7 @@ function registerCapture(program, context) {
36544
36628
  const out = await outOf();
36545
36629
  const images = await withFrameHost({
36546
36630
  root,
36547
- facesDir
36631
+ facesDir: context.facesDir
36548
36632
  }, "capture", (browser, baseUrl) => options.composite ? captureComposite(browser, {
36549
36633
  baseUrl,
36550
36634
  page: {
@@ -36570,7 +36654,7 @@ function registerCapture(program, context) {
36570
36654
  const out = await outOf();
36571
36655
  const images = await withFrameHost({
36572
36656
  root,
36573
- facesDir
36657
+ facesDir: context.facesDir
36574
36658
  }, "capture", (browser, baseUrl) => captureFrameImages(browser, {
36575
36659
  baseUrl,
36576
36660
  frames: [frame],
@@ -36756,7 +36840,7 @@ function sheetLoads(source, sheet) {
36756
36840
  url,
36757
36841
  base: sheetBase(sheet),
36758
36842
  path,
36759
- location: locate(text, sheet.offset + start, sheet.offset + end),
36843
+ location: locate$1(text, sheet.offset + start, sheet.offset + end),
36760
36844
  via: kind === "import" ? "@import" : "url()"
36761
36845
  }));
36762
36846
  }
@@ -37352,7 +37436,10 @@ function registerCheck(program, context) {
37352
37436
  findings: [...own.findings, ...browser.findings],
37353
37437
  browser: browser.run
37354
37438
  };
37355
- if (result.findings.some((finding) => finding.severity === "error")) throw new FrameboardError("check-findings", describe$5(result), { ...result });
37439
+ if (result.findings.some((finding) => finding.severity === "error")) {
37440
+ if (!options.json) context.io.stdout(`${describe$5(result)}\n`);
37441
+ throw new FrameboardError("check-findings", summarize(result), { ...result });
37442
+ }
37356
37443
  return {
37357
37444
  data: result,
37358
37445
  human: describe$5(result)
@@ -37364,16 +37451,21 @@ async function run(root, target, options, cwd) {
37364
37451
  project: options.project,
37365
37452
  cwd
37366
37453
  };
37367
- if (target === void 0) {
37368
- const project = await resolveProject(root, options.project);
37369
- return {
37370
- result: await checkProject(root, project.name),
37371
- refs: await projectRefs(root, project.name)
37372
- };
37373
- }
37454
+ if (target === void 0) return projectRun(root, (await resolveProject(root, options.project)).name);
37374
37455
  const parts = target.split("/");
37375
37456
  if (target.endsWith(".html") || parts.length === 3) return frameRun(await resolveFrameRef(root, target, refOptions));
37376
- if (parts.length === 1) return pageRun(root, await resolvePageRef(root, target, refOptions));
37457
+ if (parts.length === 1) try {
37458
+ return await pageRun(root, await resolvePageRef(root, target, refOptions));
37459
+ } catch (pageError) {
37460
+ if (options.project !== void 0 || !(pageError instanceof FrameboardError) || !NOT_FRAME.has(pageError.code)) throw pageError;
37461
+ let project;
37462
+ try {
37463
+ project = await resolveProject(root, target);
37464
+ } catch {
37465
+ throw pageError;
37466
+ }
37467
+ return projectRun(root, project.name);
37468
+ }
37377
37469
  try {
37378
37470
  return frameRun(await resolveFrameRef(root, target, refOptions));
37379
37471
  } catch (frameError) {
@@ -37400,6 +37492,12 @@ async function pageRun(root, { project, page }) {
37400
37492
  refs: names.map((name) => `${project}/${page}/${name}`)
37401
37493
  };
37402
37494
  }
37495
+ async function projectRun(root, project) {
37496
+ return {
37497
+ result: await checkProject(root, project),
37498
+ refs: await projectRefs(root, project)
37499
+ };
37500
+ }
37403
37501
  async function projectRefs(root, project) {
37404
37502
  const refs = [];
37405
37503
  for (const page of await listPageFolders(join(root, project))) for (const name of await listFrames(join(root, project, page))) refs.push(`${project}/${page}/${name}`);
@@ -37430,10 +37528,15 @@ async function browserFindings(root, refs) {
37430
37528
  return notRunning;
37431
37529
  }
37432
37530
  }
37433
- /** One line per finding, then a count, then why the browser rules did not run. */
37434
- function describe$5({ checked, findings, browser }) {
37531
+ /** The count line alone, such as `Checked 3 frames, 2 findings.` */
37532
+ function summarize({ checked, findings }) {
37435
37533
  const frames = `${checked} frame${checked === 1 ? "" : "s"}`;
37436
- const lines = findings.length === 0 ? [`Checked ${frames}, no findings.`] : [...findings.map(formatFinding), `Checked ${frames}, ${findings.length} finding${findings.length === 1 ? "" : "s"}.`];
37534
+ return findings.length === 0 ? `Checked ${frames}, no findings.` : `Checked ${frames}, ${findings.length} finding${findings.length === 1 ? "" : "s"}.`;
37535
+ }
37536
+ /** One line per finding, then the count, then why the browser rules did not run. */
37537
+ function describe$5(result) {
37538
+ const { findings, browser } = result;
37539
+ const lines = [...findings.map(formatFinding), summarize(result)];
37437
37540
  if (browser?.reason === "server-not-running") lines.push("Browser rules did not run, since no board server is running. Run frameboard serve, then check again.");
37438
37541
  else if (browser?.reason === "browser-not-found") lines.push(`Browser rules did not run, since the board server could not launch Playwright's headless shell. Install it with ${installCommands().npx}.`);
37439
37542
  return lines.join("\n");
@@ -37878,7 +37981,7 @@ function contentFormat() {
37878
37981
  `A page is any folder in a project except ${ASSETS_FOLDER}/ and dot-named ones. Its ${LAYOUT_FILE} holds each frame's box, stacking order, and flags.`,
37879
37982
  `A frame is any *${FRAME_EXTENSION} file directly in a page, named by its stem.`,
37880
37983
  `A page's notes sit in its ${NOTES_FILE$1}, never in a frame. A note pins to a frame or to one element by index and the frame file's hash, and reads at the frame once the file changes. Read them with notes, answer with notes reply, and close them with notes done.`,
37881
- `serve in a folder with no board creates ${DEFAULT_BOARD_FOLDER}/ with project ${START_PROJECT} and empty page ${START_PAGE}, and records its address in ${RUN_FOLDER}/${ADDRESS_FILE}.`,
37984
+ `serve reuses a board the walk finds, and otherwise creates ${DEFAULT_BOARD_FOLDER}/ in the working folder with project ${START_PROJECT} and empty page ${START_PAGE}, and records its address in ${RUN_FOLDER}/${ADDRESS_FILE}.`,
37882
37985
  `Dot-named folders, *${LOCK_SUFFIX} files, and *${TEMP_SUFFIX} files belong to Frameboard and are never content.`
37883
37986
  ],
37884
37987
  names: {
@@ -37909,20 +38012,69 @@ function contentFormat() {
37909
38012
  };
37910
38013
  }
37911
38014
  //#endregion
38015
+ //#region src/cli/docs/text.ts
38016
+ const INDENT = " ";
38017
+ /**
38018
+ * The human form of `docs`: one heading per section the JSON carries, with
38019
+ * the record schemas named rather than printed, since `--json` holds them whole.
38020
+ */
38021
+ function renderDocs(docs) {
38022
+ return [
38023
+ `frameboard ${docs.version}`,
38024
+ section("Verbs", docs.verbs.flatMap(verbLines)),
38025
+ section("Exit codes", table(Object.entries(docs.exitCodes))),
38026
+ section("Records", [`${INDENT}${Object.keys(docs.records).join(", ")}`, `${INDENT}Run frameboard docs --json for each record's JSON schema.`]),
38027
+ section("Content format", formatLines(docs.contentFormat)),
38028
+ section("Check rules", docs.checks.rules.map((rule) => `${INDENT}${rule.id} ${rule.tier}${rule.configKey ? `, on with checks.${rule.configKey}` : ""}. ${rule.description}`))
38029
+ ].join("\n\n");
38030
+ }
38031
+ function section(heading, lines) {
38032
+ return [heading, ...lines].join("\n");
38033
+ }
38034
+ function verbLines(verb) {
38035
+ const usage = verb.arguments.map((argument) => argument.required ? `<${argument.name}>` : `[${argument.name}]`).join(" ");
38036
+ return [`frameboard ${verb.name}${usage ? ` ${usage}` : ""} ${verb.description}`, ...verb.options.map((option) => {
38037
+ const extras = [option.choices ? `one of ${option.choices.join(", ")}` : "", option.default === void 0 ? "" : `default ${JSON.stringify(option.default)}`].filter(Boolean);
38038
+ return `${INDENT}${option.flags} ${option.description}${extras.length ? ` (${extras.join(", ")})` : ""}`;
38039
+ })];
38040
+ }
38041
+ function table(rows) {
38042
+ const width = Math.max(...rows.map(([name]) => name.length));
38043
+ return rows.map(([name, value]) => `${INDENT}${name.padEnd(width)} ${value}`);
38044
+ }
38045
+ function formatLines(format) {
38046
+ const sizes = Object.entries(format.frameSizes).map(([name, size]) => `${name} ${size.width} × ${size.height}`);
38047
+ return [
38048
+ "Folders",
38049
+ ...format.folders.map((line) => `${INDENT}${line}`),
38050
+ "Names",
38051
+ `${INDENT}Match ${format.names.pattern}, at most ${format.names.maxLength} characters. Reserved page names: ${format.names.reservedPageNames.join(", ")}.`,
38052
+ `${INDENT}${format.names.collision}`,
38053
+ "Frame sizes",
38054
+ `${INDENT}${sizes.join(", ")}, defaulting to ${format.defaultFrameSize}`,
38055
+ "Layout",
38056
+ ...format.layout.map((line) => `${INDENT}${line}`),
38057
+ "Assets",
38058
+ `${INDENT}${format.assets}`,
38059
+ "Look",
38060
+ ...format.look.map((line) => `${INDENT}${line}`)
38061
+ ];
38062
+ }
38063
+ //#endregion
37912
38064
  //#region src/cli/commands/docs.ts
37913
38065
  function registerDocs(program, context) {
37914
38066
  act(addVerb(program, "docs", "Print the verbs, exit codes, record shapes, content format, and check rules"), context, async () => {
37915
- const verbs = describeVerbs(program);
38067
+ const data = {
38068
+ version,
38069
+ verbs: describeVerbs(program),
38070
+ exitCodes: EXIT_CODES,
38071
+ records: Object.fromEntries(Object.entries(RECORDS).map(([name, schema]) => [name, toJSONSchema(schema, { io: "input" })])),
38072
+ contentFormat: contentFormat(),
38073
+ checks: { rules: RULES }
38074
+ };
37916
38075
  return {
37917
- data: {
37918
- version,
37919
- verbs,
37920
- exitCodes: EXIT_CODES,
37921
- records: Object.fromEntries(Object.entries(RECORDS).map(([name, schema]) => [name, toJSONSchema(schema, { io: "input" })])),
37922
- contentFormat: contentFormat(),
37923
- checks: { rules: RULES }
37924
- },
37925
- human: verbs.map((verb) => `frameboard ${verb.name} ${verb.description}`).join("\n")
38076
+ data,
38077
+ human: renderDocs(data)
37926
38078
  };
37927
38079
  });
37928
38080
  }
@@ -38094,7 +38246,7 @@ function describe$4(claims, now) {
38094
38246
  const FRAME_REF = "a frame ref, <page>/<frame> or <project>/<page>/<frame>, or a path to its .html file";
38095
38247
  const ANY_INTEGER = parseInteger(Number.MIN_SAFE_INTEGER);
38096
38248
  function registerFrame(program, context) {
38097
- const { io, facesDir } = context;
38249
+ const { io } = context;
38098
38250
  const frame = program.command("frame").description("Manage frames");
38099
38251
  const verb = (name, description) => addVerb(frame, name, description, { project: true }).argument("<frame-ref>", FRAME_REF);
38100
38252
  const withSize = (command) => command.addOption(new Option("--size <preset>", "a size preset").choices(Object.keys(FRAME_SIZES))).option("--width <n>", "width in px", parseInteger(1)).option("--height <n>", "height in px", parseInteger(1));
@@ -38128,7 +38280,7 @@ function registerFrame(program, context) {
38128
38280
  const frame = await readFrame$1(root, ref, refOptions);
38129
38281
  const result = await withFrameHost({
38130
38282
  root,
38131
- facesDir
38283
+ facesDir: context.facesDir
38132
38284
  }, "frame fit", (browser, baseUrl) => fitFrame(browser, {
38133
38285
  ...refOptions,
38134
38286
  root,
@@ -41953,7 +42105,7 @@ function readLiveElements() {
41953
42105
  //#endregion
41954
42106
  //#region src/cli/commands/inspect.ts
41955
42107
  function registerInspect(program, context) {
41956
- const { io, facesDir } = context;
42108
+ const { io } = context;
41957
42109
  act(addVerb(program, "inspect", "Report each rendered element of a frame with its index, box, and computed color and type, the index being the address 'edit' takes", { project: true }).argument("<frame-ref>", "a frame ref, <page>/<frame> or <project>/<page>/<frame>, or a path to its .html file").addOption(new Option("--theme <theme>", "the theme to read").choices(["light", "dark"]).default("light")).option("--index <n>", "report this element alone", parseInteger(0)), context, async ([ref = ""], options) => {
41958
42110
  const root = await boardOf(options, io);
41959
42111
  const frame = await readFrame$1(root, ref, {
@@ -41962,7 +42114,7 @@ function registerInspect(program, context) {
41962
42114
  });
41963
42115
  const data = await withFrameHost({
41964
42116
  root,
41965
- facesDir
42117
+ facesDir: context.facesDir
41966
42118
  }, "inspect", (browser, baseUrl) => inspectFrame(browser, {
41967
42119
  baseUrl,
41968
42120
  frame,
@@ -42040,8 +42192,8 @@ function registerNotes(program, context) {
42040
42192
  human: describe$1(listed)
42041
42193
  };
42042
42194
  });
42043
- act(addVerb(notes, "reply", "Answer a note in its thread on the board").argument("<id>", "the note id, n_ and 8 hex characters").argument("<text>", "the reply"), context, async ([id = "", text = ""], options) => {
42044
- const found = await findNote(await boardOf(options, io), id);
42195
+ act(addVerb(notes, "reply", "Answer a note in its thread on the board", { project: true }).argument("<id>", "the note id, n_ and 8 hex characters").argument("<text>", "the reply"), context, async ([id = "", text = ""], options) => {
42196
+ const found = await noteIn(await boardOf(options, io), id, options.project);
42045
42197
  const replyId = newNoteId();
42046
42198
  const reply = (await updateNotes(found.path, (current) => addReply(current, id, {
42047
42199
  text,
@@ -42057,8 +42209,8 @@ function registerNotes(program, context) {
42057
42209
  human: `Replied to ${reply?.thread ?? id} on ${found.project}/${found.page}/${found.note.frame}`
42058
42210
  };
42059
42211
  });
42060
- act(addVerb(notes, "done", "Close a note, hiding its marker on the board").argument("<id>", "the note id, n_ and 8 hex characters"), context, async ([id = ""], options) => {
42061
- const found = await findNote(await boardOf(options, io), id);
42212
+ act(addVerb(notes, "done", "Close a note, hiding its marker on the board", { project: true }).argument("<id>", "the note id, n_ and 8 hex characters"), context, async ([id = ""], options) => {
42213
+ const found = await noteIn(await boardOf(options, io), id, options.project);
42062
42214
  const file = await updateNotes(found.path, (current) => setState(current, id, "done", /* @__PURE__ */ new Date()));
42063
42215
  const rootId = found.note.thread ?? found.note.id;
42064
42216
  return {
@@ -42067,6 +42219,16 @@ function registerNotes(program, context) {
42067
42219
  };
42068
42220
  });
42069
42221
  }
42222
+ /** The note an id names, refused as missing when `--project` names another project than the one holding it. */
42223
+ async function noteIn(root, id, project) {
42224
+ const scope = project === void 0 ? void 0 : await resolveProject(root, project);
42225
+ const found = await findNote(root, id);
42226
+ if (scope && found.project !== scope.name) throw new FrameboardError("note-not-found", `No note ${id} in project ${scope.name}. It sits in ${found.project}.`, {
42227
+ id,
42228
+ project: scope.name
42229
+ });
42230
+ return found;
42231
+ }
42070
42232
  /** The pages a listing reads: the one `--page` or `--frame` names, else every page in scope. */
42071
42233
  async function pagesIn(root, options, frame, cwd) {
42072
42234
  const page = frame ?? (options.page ? await resolvePageRef(root, options.page, {
@@ -42097,6 +42259,27 @@ function describe$1(notes) {
42097
42259
  }).join("\n");
42098
42260
  }
42099
42261
  //#endregion
42262
+ //#region src/cli/commands/open.ts
42263
+ function registerOpen(program, context) {
42264
+ const { io } = context;
42265
+ act(addVerb(program, "open", "Open a board tab that can edit, through a single-use link to the running server").option("--no-open", "leave the browser alone and print the link"), context, async (_args, options) => {
42266
+ const root = await boardOf(options, io);
42267
+ const live = await findLiveServer(root);
42268
+ if (!live) throw new FrameboardError("server-not-running", `No frameboard server is running for ${root}. Run frameboard serve first.`, { root });
42269
+ const { url: writeUrl, expiresAt } = await postToBoard(live, "/api/access/ticket", {});
42270
+ if (options.open) io.openUrl(writeUrl);
42271
+ return {
42272
+ data: {
42273
+ url: live.url,
42274
+ writeUrl,
42275
+ expiresAt,
42276
+ opened: options.open
42277
+ },
42278
+ human: options.open ? `Opened a board tab that can edit ${live.url}` : `Open ${writeUrl} before ${expiresAt} to edit the board. The link works once.`
42279
+ };
42280
+ });
42281
+ }
42282
+ //#endregion
42100
42283
  //#region src/cli/commands/page.ts
42101
42284
  const PAGE_REF = "a page ref, <page> or <project>/<page>";
42102
42285
  const INDEX = "position in the page order, 0 first, clamped";
@@ -42278,8 +42461,12 @@ function createTickets(now = Date.now) {
42278
42461
  mint: () => {
42279
42462
  for (const [ticket, expiry] of expiries) if (expiry <= now()) expiries.delete(ticket);
42280
42463
  const ticket = randomBytes(16).toString("hex");
42281
- expiries.set(ticket, now() + TICKET_TTL_MS);
42282
- return ticket;
42464
+ const expiry = now() + TICKET_TTL_MS;
42465
+ expiries.set(ticket, expiry);
42466
+ return {
42467
+ ticket,
42468
+ expiresAt: new Date(expiry).toISOString()
42469
+ };
42283
42470
  },
42284
42471
  redeem: (ticket) => {
42285
42472
  const expiry = expiries.get(ticket);
@@ -42561,7 +42748,7 @@ function createChangeTracker(root, { now = () => /* @__PURE__ */ new Date() } =
42561
42748
  /** The files and folders a step wrote, being every rewrite, creation, removal, and move. */
42562
42749
  function writtenPaths(step) {
42563
42750
  return step.changes.flatMap((change) => {
42564
- if (change.kind === "content" || change.kind === "path") return [change.path];
42751
+ if (change.kind === "element" || change.kind === "path") return [change.path];
42565
42752
  if (change.kind === "moved") return [change.from, change.to];
42566
42753
  return [];
42567
42754
  });
@@ -42746,14 +42933,18 @@ async function reads(change, side) {
42746
42933
  return await exists(present) && !await exists(absent);
42747
42934
  }
42748
42935
  case "path": return change.present === side ? await exists(change.path) && await hashPath(change.path) === change.hash : !await exists(change.path) && await exists(change.slot);
42749
- case "content": return await exists(change.path) && contentHash(await readFile(change.path)) === change.hashes[side];
42936
+ case "element": return await exists(change.path) && holdsSpan(await readFile(change.path, "utf8"), change.span, side);
42750
42937
  }
42751
42938
  }
42752
42939
  const OTHER = {
42753
42940
  before: "after",
42754
42941
  after: "before"
42755
42942
  };
42756
- /** Writes `side` of a change back, under the record's lock, once `holds` read the other side. */
42943
+ /**
42944
+ * Writes `side` of a change back, under the record's lock, once `holds` read
42945
+ * the other side. A hand edit's change answers the frame's content hash as it
42946
+ * left it, and every other kind answers undefined.
42947
+ */
42757
42948
  async function restore(change, side) {
42758
42949
  switch (change.kind) {
42759
42950
  case "entry": {
@@ -42787,22 +42978,41 @@ async function restore(change, side) {
42787
42978
  if (change.present === side) await rename(change.slot, change.path);
42788
42979
  else await takeOut(change.path, change.slot);
42789
42980
  return;
42790
- case "content": await rewrite(change, side);
42981
+ case "element": return swapElement(change, side);
42791
42982
  }
42792
42983
  }
42793
42984
  /**
42794
- * Writes `side` of a frame's bytes through a temporary file and a rename,
42795
- * reading the file again just before the rename so an agent's write landing
42796
- * since `holds` read it is refused rather than overwritten, as a hand edit is.
42985
+ * Swaps the edited element to `side` through a temporary file and a rename,
42986
+ * reading the file again just before the rename. A write landing before that
42987
+ * read is not overwritten: the swap is made once more from the fresh bytes,
42988
+ * and refused once they change again or no longer hold the element. Bytes
42989
+ * that fail a UTF-8 round trip are refused too, since decoding would rewrite
42990
+ * each invalid byte outside the element. The change keeps the index the
42991
+ * element was found at, so a redo lands on it.
42797
42992
  */
42798
- async function rewrite(change, side) {
42993
+ async function swapElement(change, side) {
42799
42994
  const temp = join(dirname(change.path), `.${basename(change.path)}.${process.pid}.tmp`);
42800
- await writeFile(temp, change[side]);
42801
- if (contentHash(await readFile(change.path)) !== change.hashes[OTHER[side]]) {
42802
- await rm(temp, { force: true });
42803
- throw new FrameboardError("undo-overtaken", `An agent changed ${basename(change.path, FRAME_EXTENSION)} after your edit, so that step was dropped.`, { change: change.kind });
42995
+ let source = await readText(change.path);
42996
+ for (let attempt = 0; source !== void 0 && attempt < 2; attempt += 1) {
42997
+ const swapped = swapSpan(source, change.span, OTHER[side]);
42998
+ if (!swapped) break;
42999
+ await writeFile(temp, swapped.html);
43000
+ const now = await readText(change.path);
43001
+ if (now === source) {
43002
+ await rename(temp, change.path);
43003
+ change.span = swapped.span;
43004
+ return contentHash(swapped.html);
43005
+ }
43006
+ source = now;
42804
43007
  }
42805
- await rename(temp, change.path);
43008
+ await rm(temp, { force: true });
43009
+ throw new FrameboardError("undo-overtaken", `An agent changed ${basename(change.path, FRAME_EXTENSION)} after your edit, so that step was dropped.`, { change: change.kind });
43010
+ }
43011
+ /** A frame file's text, or undefined when its bytes do not survive a UTF-8 round trip. */
43012
+ async function readText(path) {
43013
+ const bytes = await readFile(path);
43014
+ const text = bytes.toString("utf8");
43015
+ return Buffer.from(text, "utf8").equals(bytes) ? text : void 0;
42806
43016
  }
42807
43017
  /**
42808
43018
  * The journal one board write reports into, building the changes of one
@@ -42843,18 +43053,13 @@ var StepJournal = class {
42843
43053
  to
42844
43054
  });
42845
43055
  }
42846
- /** A frame file a hand edit rewrote from `before` to `after`, which this journal does not write. */
42847
- content(path, ref, before, after) {
43056
+ /** The element a hand edit rewrote in a frame file, which this journal does not write. */
43057
+ element(path, ref, span) {
42848
43058
  this.changes.push({
42849
- kind: "content",
43059
+ kind: "element",
42850
43060
  path,
42851
43061
  ref,
42852
- before,
42853
- after,
42854
- hashes: {
42855
- before: contentHash(before),
42856
- after: contentHash(after)
42857
- }
43062
+ span
42858
43063
  });
42859
43064
  }
42860
43065
  async created(path) {
@@ -43000,12 +43205,16 @@ var History = class {
43000
43205
  const step = from.pop();
43001
43206
  if (!step) throw empty();
43002
43207
  const was = to === "before" ? "after" : "before";
43208
+ const hashes = {};
43003
43209
  const locks = step.changes.flatMap(lockPaths).filter((path) => existsSync(dirname(path)));
43004
43210
  try {
43005
43211
  await withLocks(locks, async () => {
43006
43212
  for (const change of step.changes) if (!await holds(change, was)) throw new FrameboardError("undo-overtaken", `An agent changed ${nameOf(change)} after your edit, so that step was dropped.`, { change: change.kind });
43007
43213
  const ordered = to === "before" ? [...step.changes].reverse() : step.changes;
43008
- for (const change of ordered) await restore(change, to);
43214
+ for (const change of ordered) {
43215
+ const hash = await restore(change, to);
43216
+ if (hash !== void 0 && "ref" in change) hashes[change.ref] = hash;
43217
+ }
43009
43218
  });
43010
43219
  } catch (error) {
43011
43220
  if (!(error instanceof FrameboardError && error.code === "undo-overtaken")) from.push(step);
@@ -43019,7 +43228,6 @@ var History = class {
43019
43228
  page: step.page?.[to] ?? null,
43020
43229
  frames: step.frames
43021
43230
  };
43022
- const hashes = Object.fromEntries(step.changes.flatMap((change) => change.kind === "content" ? [[change.ref, change.hashes[to]]] : []));
43023
43231
  return Object.keys(hashes).length > 0 ? {
43024
43232
  ...answer,
43025
43233
  hashes
@@ -45300,7 +45508,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
45300
45508
  cookieName: cookieName(root),
45301
45509
  isOwnOrigin: (host) => isBoardHost(host, bound)
45302
45510
  };
45303
- const boardUrl = () => `http://${HOSTNAME}:${bound}/api/access/redeem?ticket=${tickets.mint()}`;
45511
+ const boardUrl = () => `http://${HOSTNAME}:${bound}/api/access/redeem?ticket=${tickets.mint().ticket}`;
45304
45512
  let scanning = Promise.resolve();
45305
45513
  const inTurn = (task) => {
45306
45514
  const run = scanning.then(task);
@@ -45591,7 +45799,7 @@ const DEFAULT_PORT = 4173;
45591
45799
  /** How long a fresh server waits for a writing board tab left open by its predecessor to reconnect. */
45592
45800
  const RECONNECT_WAIT_MS = 1e3;
45593
45801
  function registerServe(program, context) {
45594
- const { io, clientDir, facesDir } = context;
45802
+ const { io, clientDir } = context;
45595
45803
  act(addVerb(program, "serve", "Serve the board in a local browser").option("-p, --port <port>", "port to listen on, falling back to a free one when the default is taken", parsePort, DEFAULT_PORT).option("--no-open", "leave the browser alone").option("--tokens <path>", "a token sheet another tool manages, standing in for the board's tokens.css"), context, async (_args, options, self) => {
45596
45804
  const tokens = options.tokens === void 0 ? void 0 : resolve(io.cwd, options.tokens);
45597
45805
  if (tokens !== void 0 && !isFile(tokens)) throw new FrameboardError("tokens-not-found", `No token sheet at ${tokens}.`, { tokens });
@@ -45618,7 +45826,7 @@ function registerServe(program, context) {
45618
45826
  }
45619
45827
  const server = await startServer({
45620
45828
  clientDir,
45621
- facesDir,
45829
+ facesDir: context.facesDir,
45622
45830
  root,
45623
45831
  tokens,
45624
45832
  port: options.port,
@@ -45684,9 +45892,69 @@ function registerShow(program, context) {
45684
45892
  });
45685
45893
  }
45686
45894
  //#endregion
45895
+ //#region src/server/look/write-faces.ts
45896
+ const require$1 = createRequire(import.meta.url);
45897
+ /** Whether `dir` holds a sheet for every face. */
45898
+ function hasFaces(dir) {
45899
+ return FACES.every((face) => existsSync(join(dir, face.folder, "index.css")));
45900
+ }
45901
+ /**
45902
+ * Copies each face every frame imports from its package into `outDir`,
45903
+ * replacing what was there. The faces fill a sibling folder first and rename
45904
+ * into place, so `outDir` holds every file or does not exist, and an
45905
+ * interrupted write leaves no half-filled face behind. Each sheet is
45906
+ * rewritten to declare the plain family a frame names, such as Geist, rather
45907
+ * than the package's own, such as Geist Variable. With `keepComplete`, a
45908
+ * folder that filled in meanwhile, as from a parallel run, stays as it is.
45909
+ */
45910
+ function writeFaces(outDir, { keepComplete = false } = {}) {
45911
+ const staging = `${outDir}.${process.pid}.tmp`;
45912
+ rmSync(staging, {
45913
+ recursive: true,
45914
+ force: true
45915
+ });
45916
+ try {
45917
+ for (const face of FACES) {
45918
+ const from = dirname(require$1.resolve(`${face.package}/package.json`));
45919
+ const to = join(staging, face.folder);
45920
+ mkdirSync(join(to, "files"), { recursive: true });
45921
+ const sheet = readFileSync(join(from, "index.css"), "utf8");
45922
+ writeFileSync(join(to, "index.css"), sheet.replaceAll(`'${face.packageFamily}'`, `'${face.family}'`));
45923
+ copyFileSync(join(from, "LICENSE"), join(to, "LICENSE"));
45924
+ for (const file of readdirSync(join(from, "files"))) if (file.endsWith(".woff2")) copyFileSync(join(from, "files", file), join(to, "files", file));
45925
+ }
45926
+ if (keepComplete && hasFaces(outDir)) return;
45927
+ rmSync(outDir, {
45928
+ recursive: true,
45929
+ force: true
45930
+ });
45931
+ mkdirSync(dirname(outDir), { recursive: true });
45932
+ renameSync(staging, outDir);
45933
+ } finally {
45934
+ rmSync(staging, {
45935
+ recursive: true,
45936
+ force: true
45937
+ });
45938
+ }
45939
+ }
45940
+ //#endregion
45941
+ //#region src/cli/faces-dir.ts
45942
+ /**
45943
+ * The folder the faces are served from. A built run reads the `faces` folder
45944
+ * the build put beside the bundle and never looks further, so a bundle missing
45945
+ * it fails loudly. A source run writes the faces once into the package's
45946
+ * `node_modules/.cache` from the installed packages, and completes a cache
45947
+ * missing any face.
45948
+ */
45949
+ function resolveFacesDir(moduleUrl = import.meta.url) {
45950
+ if (!moduleUrl.endsWith(".ts")) return fileURLToPath(new URL("./faces", moduleUrl));
45951
+ const cache = fileURLToPath(new URL("../../node_modules/.cache/frameboard/faces", moduleUrl));
45952
+ if (!hasFaces(cache)) writeFaces(cache, { keepComplete: true });
45953
+ return cache;
45954
+ }
45955
+ //#endregion
45687
45956
  //#region src/cli/program.ts
45688
45957
  const CLIENT_DIR = fileURLToPath(new URL("./client", import.meta.url));
45689
- const FACES_DIR = fileURLToPath(new URL("./faces", import.meta.url));
45690
45958
  function parsePort(value) {
45691
45959
  const port = /^\d+$/.test(value) ? Number(value) : NaN;
45692
45960
  if (!(port >= 0 && port <= 65535)) throw new InvalidArgumentError("Expected a port between 0 and 65535.");
@@ -45702,7 +45970,7 @@ function parseInteger(min) {
45702
45970
  }
45703
45971
  /** Adds a verb with `--json` and `--root`, and `--project` when it acts inside a project. */
45704
45972
  function addVerb(parent, name, description, { project = false } = {}) {
45705
- const command = parent.command(name).description(description).option("--json", "print one JSON document on stdout").option("--root <path>", "the board folder, found from the working folder when absent");
45973
+ const command = parent.command(name).description(description).option("--json", "print one JSON document on stdout").option("--root <path>", "the board folder itself, holding board.json, found from the working folder when absent");
45706
45974
  if (project) command.option("--project <name>", "the project, defaulting to the board's only one");
45707
45975
  return command;
45708
45976
  }
@@ -45733,34 +46001,29 @@ function createProgram(context) {
45733
46001
  writeOut: io.stdout,
45734
46002
  writeErr: (text) => json ? void 0 : io.stderr(text)
45735
46003
  });
45736
- const facesDir = context.facesDir ?? FACES_DIR;
45737
- registerServe(program, {
46004
+ let facesDir;
46005
+ const faced = {
45738
46006
  ...context,
45739
46007
  clientDir: context.clientDir ?? CLIENT_DIR,
45740
- facesDir
45741
- });
46008
+ get facesDir() {
46009
+ return facesDir ??= context.facesDir ?? resolveFacesDir();
46010
+ }
46011
+ };
46012
+ registerServe(program, faced);
45742
46013
  registerShow(program, context);
46014
+ registerOpen(program, context);
45743
46015
  registerSelection(program, context);
45744
46016
  registerList(program, context);
45745
46017
  registerProject(program, context);
45746
46018
  registerPage(program, context);
45747
- registerFrame(program, {
45748
- ...context,
45749
- facesDir
45750
- });
46019
+ registerFrame(program, faced);
45751
46020
  registerEdit(program, context);
45752
46021
  registerCheck(program, context);
45753
46022
  registerNotes(program, context);
45754
46023
  registerInbox(program, context);
45755
46024
  registerEditing(program, context);
45756
- registerCapture(program, {
45757
- ...context,
45758
- facesDir
45759
- });
45760
- registerInspect(program, {
45761
- ...context,
45762
- facesDir
45763
- });
46025
+ registerCapture(program, faced);
46026
+ registerInspect(program, faced);
45764
46027
  registerDocs(program, context);
45765
46028
  return program;
45766
46029
  }
@@ -45845,6 +46108,10 @@ function missingCommand(group) {
45845
46108
  //#region src/cli/index.ts
45846
46109
  const controller = new AbortController();
45847
46110
  for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => controller.abort());
46111
+ process.stdout.on("error", (error) => {
46112
+ if (error.code === "EPIPE") process.exit(0);
46113
+ throw error;
46114
+ });
45848
46115
  process.exitCode = await runCli(process.argv.slice(2), {
45849
46116
  stdout: (text) => process.stdout.write(text),
45850
46117
  stderr: (text) => process.stderr.write(text),