@theholocron/cli 5.0.0-alpha.490 → 5.0.0-alpha.491

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/README.md CHANGED
@@ -691,7 +691,7 @@ Channels fed by the error tracker add `feeds: { errors: true }` and a layout `re
691
691
 
692
692
  `holocron list secrets [--scope repo|environment|organization] [--env <name>] [--json]` prints the names (never the values; GitHub does not return them) of the secrets at each scope, sorted, under a heading per scope. With no `--scope` it lists the repository, plus the organization (`--org`, `HOLOCRON_ORG` or the config's `org`) and the `--env` environment when they are known; `--scope` lists one. A scope that cannot be listed is reported under its heading and the rest are still listed; the exit code is 1 if any fails. `--json` prints `[{ scope, names, error? }]`. It is read-only, so `--dry-run` does not apply. Comparing the names with what the config expects is `doctor secrets`, which also covers the keys of the vault environments declared in `repo.secrets.sync`.
693
693
 
694
- A channel with `kind: "forum"` is a forum, with `tags` (each a `name`, an `emoji` and whether it is `moderated`); `setup` adds and corrects the tags but never removes one, and a text channel of the same name must be deleted first, since neither kind can become the other. A forum takes no `webhook` and none of the webhook feeds (`monitoring`, `errors`); its one feed is `feeds: { prs: true }`, the pull-request feed, where Sentinel keeps one post per pull request tagged with its state. The object form `feeds: { prs: { exclude: { repos?: ["owner/name"], authors?: ["login"] } } }` leaves some pull requests out. `feeds.prs` belongs to a forum (a text channel with it is refused) and the forum's `tags` must hold all eight states, `draft`, `conflicts`, `failing`, `changes requested`, `ready`, `waiting`, `merged` and `closed`, or `setup` refuses the layout. `setup` does nothing more for it; `doctor notifications` checks that the forum exists, has those tags and that the bot can start posts and manage threads in it (`ServerInspection` `botThreads`, filled in by the Discord provider after the forum's own permission overwrites). `defaultReaction` is the emoji Discord offers on every post (its Get Started step "Set a default reaction for posts"); Discord allows only one, so `starterReactions` lists more (`["👍", "👎", "❓"]` for approve, disapprove, question) that the bot adds to the first message of each post `sync specs` makes. Existing posts are left alone, a reaction the bot cannot add is skipped, and `doctor notifications` checks `defaultReaction`. Unicode emoji only.
694
+ A channel with `kind: "forum"` is a forum, with `tags` (each a `name`, an `emoji` and whether it is `moderated`); `setup` adds and corrects the tags but never removes one, and a text channel of the same name must be deleted first, since neither kind can become the other. A forum takes no `webhook` and none of the webhook feeds (`monitoring`, `errors`); its one feed is `feeds: { prs: true }`, the pull-request feed, where Sentinel keeps one post per pull request tagged with its state. The object form `feeds: { prs: { exclude: { repos?: ["owner/name"], authors?: ["login"] } } }` leaves some pull requests out. `feeds.prs` belongs to a forum (a text channel with it is refused) and the forum's `tags` must hold all eight states, `draft`, `conflicts`, `failing`, `changes requested`, `ready`, `waiting`, `merged` and `closed`, or `setup` refuses the layout. `setup` does nothing more for it; `doctor notifications` checks that the forum exists, has those tags and that the bot can start posts and manage threads in it (`ServerInspection` `botThreads`, filled in by the Discord provider after the forum's own permission overwrites). `defaultReaction` is the emoji Discord offers on every post (its Get Started step "Set a default reaction for posts"); Discord allows only one, so `starterReactions` lists more (`["👍", "👎", "❓"]` for approve, disapprove, question) that the bot adds to the first message of each post `sync specs` makes. Existing posts are left alone, a reaction the bot cannot add is skipped, and `doctor notifications` checks `defaultReaction`. A reaction is a Unicode emoji (`"✅"`) or one of the server's own emoji written between colons (`":git_merge:"`, 2 to 32 letters, digits and underscores); the object form `{ emoji: ":git_merge:", image: ".holocron/media/emoji/git_merge.png" }` also names the file `setup` makes the emoji from when the server has none (PNG, JPEG, GIF, WebP or AVIF, at most 256 KiB, under `.holocron/media/`; checked by its bytes before anything is written; an emoji that exists is never replaced or deleted; `--dry-run` only previews; the bot then needs Create Guild Expressions, which the invite link asks for only when the layout gives an emoji an `image`). A word without colons (`git_merge`) is refused, not sent as text. `doctor notifications` has an `emoji` row that fails by name for each server emoji the server lacks, and its `channels` row compares the default reaction in the same spelling.
695
695
 
696
696
  `holocron sync specs [--channel <forum>] [--files <paths...>] [--pr <number>] [--refresh] [--refresh-origin] [--refresh-titles] [--withdraw] [--notify]` keeps one forum post per ADR and spec in step with the files: it makes the post (titled with the document's own title, tagged with the file's status), writes its address into the file as `discussion.url`, and turns a gatekeeper's retag into an edit of the file's `status:` line in the working tree for a pull request. `--files` syncs only those files and `--pr` names a pull request on their posts, for a pull request that is still open. `--refresh-origin` is a one-off repair: it rewrites the `PR:` line of existing posts to the one the current rule names (the optional `prLine` of `DiscussionPatch`, and of `DiscussionPost`), and nothing else in them. `--refresh-titles` is the same kind of one-off repair for the title: it renames each existing post whose title differs from the current rule's (the optional `title` of `DiscussionPatch`, and of `DiscussionPost`) and changes nothing else; a rate limit stops it cleanly, reports how many documents are left, and the next run continues. The id that opens a post is a link to the file on the default branch (`repo.defaultBranch`, else `HEAD`) once the file is there, and plain text while `--pr` names an open pull request; the normal sync rewrites a post's id line (and only that line) whenever it is not the one the rule gives and no `--pr` is given, which covers a file that moved and a post made while its pull request was open, so it needs no extra request when every post is right and `--refresh` is no longer needed for it. `--refresh` runs the `PR:`, title and id-link repairs in one pass (the id link is the optional `idLine` of `DiscussionPatch`, and of `DiscussionPost`, which changes only the message's first line); `--refresh-origin` and `--refresh-titles` still do only their own. `--withdraw` (with `--files`, on the base branch) tags the posts of a pull request closed unmerged `withdrawn` and closes them; `withdrawn` is a tag only, never a file `status:`, and the next sync puts the file's own status back. It cannot be combined with `--refresh`, `--refresh-origin` or `--refresh-titles`. `--dry-run` previews it. The posts behind it are also usable for other keys, such as a pull request (`owner/repo#123`, the state a tag name): `DiscussionPatch.body` replaces the first message's text (the provider keeps its footer), and the optional `Notifications` methods `postDiscussionMessage(channel, key, content, { quiet })` (a closed post is unarchived, written to and closed again), `readDiscussionMessages(channel, key, limit)` (text, newest first, 50 by default) and `dedupeDiscussion(channel, key)` (keeps the oldest post of the key, deletes the rest, returns how many) append to, read and repair a post, and `duplicateDiscussions(channel)` lists the keys with more than one post without deleting: `holocron cleanup posts [channel] [--provider <name>] [--yes]` uses the two to clear duplicates that are already there (the forum with `feeds.prs` by default; `--dry-run` previews it). See the [`sync specs` page](https://docs.theholocron.dev/holocron/commands/sync-specs/).
697
697
 
package/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire } from "node:module";
3
3
  import { homedir, tmpdir } from "node:os";
4
- import path, { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
4
+ import path, { basename, dirname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
5
5
  import { PREFIX as PREFIX$1, createEnvLookup, detectEnvironment, firstEnv, holocronEnv } from "@theholocron/env-utils/lookup";
6
6
  import { ProviderApiError, ProviderApiError as ProviderApiError$1, createRestClient, onRetry } from "@theholocron/http-client";
7
7
  import { addGlobalOptions, groupMenu as groupMenu$1, tokenContext as tokenContext$1 } from "@theholocron/kyber/flags";
@@ -7576,7 +7576,7 @@ const SETUP_ENVIRONMENTS = ["staging", "production"];
7576
7576
  * nothing named, nothing is declared; with no provider but some named, the row is a skip with the reason.
7577
7577
  */
7578
7578
  const ID$5 = "environments";
7579
- const TITLE$5 = "environments exist";
7579
+ const TITLE$6 = "environments exist";
7580
7580
  async function runDoctorEnvironments(input) {
7581
7581
  const print = input.print ?? ((line) => console.log(line));
7582
7582
  const logger = input.logger ?? getLogger();
@@ -7601,7 +7601,7 @@ async function runDoctorEnvironments(input) {
7601
7601
  async function checkEnvironments(loader, named) {
7602
7602
  const make = (status, detail, problems = []) => ({
7603
7603
  id: ID$5,
7604
- title: TITLE$5,
7604
+ title: TITLE$6,
7605
7605
  status,
7606
7606
  detail,
7607
7607
  problems
@@ -8206,7 +8206,7 @@ async function readWorkspaceMonitoring(context) {
8206
8206
  }
8207
8207
  // src/commands/doctor-monitoring/dashboard-rows/dashboard-rows.ts
8208
8208
  const ID$4 = "monitoring-dashboards";
8209
- const TITLE$4 = "monitoring dashboards match";
8209
+ const TITLE$5 = "monitoring dashboards match";
8210
8210
  /** The tags as comparable text: sorted and de-duplicated. */
8211
8211
  const tagsText = (tags) => [...new Set(tags)].sort().join(", ") || "none";
8212
8212
  /** What differs between a declared dashboard and the one the account holds. Privacy is always compared (default private). */
@@ -8238,7 +8238,7 @@ async function dashboardRows(monitoring) {
8238
8238
  detail,
8239
8239
  problems: []
8240
8240
  });
8241
- if (!monitoring.inspectDashboard) return [skip(ID$4, TITLE$4, "provider does not implement inspectDashboard")];
8241
+ if (!monitoring.inspectDashboard) return [skip(ID$4, TITLE$5, "provider does not implement inspectDashboard")];
8242
8242
  try {
8243
8243
  const names = new Set(declared.map((d) => d.name));
8244
8244
  const problems = [];
@@ -8250,13 +8250,13 @@ async function dashboardRows(monitoring) {
8250
8250
  }
8251
8251
  const rows = [problems.length > 0 ? {
8252
8252
  id: ID$4,
8253
- title: TITLE$4,
8253
+ title: TITLE$5,
8254
8254
  status: "fail",
8255
8255
  detail: `${problems.length} problem(s)`,
8256
8256
  problems
8257
8257
  } : {
8258
8258
  id: ID$4,
8259
- title: TITLE$4,
8259
+ title: TITLE$5,
8260
8260
  status: "ok",
8261
8261
  detail: `${declared.length} of ${declared.length} match`,
8262
8262
  problems: []
@@ -8265,10 +8265,10 @@ async function dashboardRows(monitoring) {
8265
8265
  return rows;
8266
8266
  } catch (err) {
8267
8267
  const noToken = missingTokenReason(err);
8268
- if (noToken !== void 0) return [skip(ID$4, TITLE$4, noToken)];
8268
+ if (noToken !== void 0) return [skip(ID$4, TITLE$5, noToken)];
8269
8269
  return [{
8270
8270
  id: ID$4,
8271
- title: TITLE$4,
8271
+ title: TITLE$5,
8272
8272
  status: "fail",
8273
8273
  detail: errorMessage(err),
8274
8274
  problems: []
@@ -8282,7 +8282,7 @@ async function dashboardRows(monitoring) {
8282
8282
  * config is an `info` row (shown as skipped). Names only: the ping URL is never read here.
8283
8283
  */
8284
8284
  const ID$3 = "monitoring-heartbeats";
8285
- const TITLE$3 = "monitoring heartbeats match";
8285
+ const TITLE$4 = "monitoring heartbeats match";
8286
8286
  const show = (b) => new Map([
8287
8287
  ["period", `${b.period} ${b.periodUnit}`],
8288
8288
  ["grace", `${b.grace} ${b.graceUnit}`],
@@ -8294,7 +8294,7 @@ async function heartbeatRows(monitoring) {
8294
8294
  if (declared.length === 0) return [];
8295
8295
  const skip = (detail) => ({
8296
8296
  id: ID$3,
8297
- title: TITLE$3,
8297
+ title: TITLE$4,
8298
8298
  status: "skip",
8299
8299
  detail,
8300
8300
  problems: []
@@ -8319,13 +8319,13 @@ async function heartbeatRows(monitoring) {
8319
8319
  }
8320
8320
  const rows = [problems.length > 0 ? {
8321
8321
  id: ID$3,
8322
- title: TITLE$3,
8322
+ title: TITLE$4,
8323
8323
  status: "fail",
8324
8324
  detail: `${problems.length} problem(s)`,
8325
8325
  problems
8326
8326
  } : {
8327
8327
  id: ID$3,
8328
- title: TITLE$3,
8328
+ title: TITLE$4,
8329
8329
  status: "ok",
8330
8330
  detail: `${declared.length} of ${declared.length} match`,
8331
8331
  problems: []
@@ -8345,7 +8345,7 @@ async function heartbeatRows(monitoring) {
8345
8345
  if (noToken !== void 0) return [skip(noToken)];
8346
8346
  return [{
8347
8347
  id: ID$3,
8348
- title: TITLE$3,
8348
+ title: TITLE$4,
8349
8349
  status: "fail",
8350
8350
  detail: errorMessage(err),
8351
8351
  problems: []
@@ -8450,7 +8450,7 @@ async function statusPageRows(monitoring) {
8450
8450
  }
8451
8451
  // src/commands/doctor-monitoring/undeclared-check-rows/undeclared-check-rows.ts
8452
8452
  const ID$2 = "monitoring-undeclared";
8453
- const TITLE$2 = "checks no config declares";
8453
+ const TITLE$3 = "checks no config declares";
8454
8454
  function undeclaredCheckRows({ monitoring, workspace, have }) {
8455
8455
  if (have === void 0) return [];
8456
8456
  const tags = new Set([
@@ -8461,7 +8461,7 @@ function undeclaredCheckRows({ monitoring, workspace, have }) {
8461
8461
  if (tags.size === 0) return [];
8462
8462
  const row = (status, detail) => [{
8463
8463
  id: ID$2,
8464
- title: TITLE$2,
8464
+ title: TITLE$3,
8465
8465
  status,
8466
8466
  detail,
8467
8467
  problems: []
@@ -8499,7 +8499,7 @@ function undeclaredCheckRows({ monitoring, workspace, have }) {
8499
8499
  * `doctor notifications`) and any check that a message really arrives.
8500
8500
  */
8501
8501
  const ID$1 = "monitoring-checks";
8502
- const TITLE$1 = "monitoring checks match";
8502
+ const TITLE$2 = "monitoring checks match";
8503
8503
  async function runDoctorMonitoring(input) {
8504
8504
  const print = input.print ?? ((line) => console.log(line));
8505
8505
  const logger = input.logger ?? getLogger();
@@ -8539,14 +8539,14 @@ async function runDoctorMonitoring(input) {
8539
8539
  async function checkRow(loader) {
8540
8540
  const skip = (detail) => ({ row: {
8541
8541
  id: ID$1,
8542
- title: TITLE$1,
8542
+ title: TITLE$2,
8543
8543
  status: "skip",
8544
8544
  detail,
8545
8545
  problems: []
8546
8546
  } });
8547
8547
  const none = () => ({ row: {
8548
8548
  id: ID$1,
8549
- title: TITLE$1,
8549
+ title: TITLE$2,
8550
8550
  status: "ok",
8551
8551
  detail: "none declared",
8552
8552
  problems: []
@@ -8564,7 +8564,7 @@ async function checkRow(loader) {
8564
8564
  if (problems.length > 0) return {
8565
8565
  row: {
8566
8566
  id: ID$1,
8567
- title: TITLE$1,
8567
+ title: TITLE$2,
8568
8568
  status: "fail",
8569
8569
  detail: `${problems.length} problem(s)`,
8570
8570
  problems
@@ -8575,7 +8575,7 @@ async function checkRow(loader) {
8575
8575
  return {
8576
8576
  row: {
8577
8577
  id: ID$1,
8578
- title: TITLE$1,
8578
+ title: TITLE$2,
8579
8579
  status: "ok",
8580
8580
  detail: `${n} of ${n} match`,
8581
8581
  problems: []
@@ -8587,7 +8587,7 @@ async function checkRow(loader) {
8587
8587
  if (noToken !== void 0) return skip(noToken);
8588
8588
  return { row: {
8589
8589
  id: ID$1,
8590
- title: TITLE$1,
8590
+ title: TITLE$2,
8591
8591
  status: "fail",
8592
8592
  detail: errorMessage(err),
8593
8593
  problems: []
@@ -8722,7 +8722,7 @@ function resultRow(id, title, problems, ok) {
8722
8722
  };
8723
8723
  }
8724
8724
  // src/commands/bot-permission-checks/bot-permission-checks.ts
8725
- const TITLE = "bot holds the server-wide permissions it needs";
8725
+ const TITLE$1 = "bot holds the server-wide permissions it needs";
8726
8726
  /**
8727
8727
  * The step of `doctor notifications` for the bot's own role: the permissions the provider says it needs (read from
8728
8728
  * `inspect`, server-wide, before any channel overwrite) are all held. A failure names the missing ones and carries the
@@ -8731,13 +8731,161 @@ const TITLE = "bot holds the server-wide permissions it needs";
8731
8731
  */
8732
8732
  function botPermissionChecks(input) {
8733
8733
  const { found } = input;
8734
- if (!found) return [skipRow$1("bot-permissions", TITLE, "not checked: could not read the server")];
8735
- if (found.botPermissionsError) return [skipRow$1("bot-permissions", TITLE, `not checked: could not read the bot's roles (${sanitizeDetail(found.botPermissionsError)})`)];
8734
+ if (!found) return [skipRow$1("bot-permissions", TITLE$1, "not checked: could not read the server")];
8735
+ if (found.botPermissionsError) return [skipRow$1("bot-permissions", TITLE$1, `not checked: could not read the bot's roles (${sanitizeDetail(found.botPermissionsError)})`)];
8736
8736
  const { botPermissions } = found;
8737
8737
  if (!botPermissions) return [];
8738
8738
  const { missing, inviteUrl } = botPermissions;
8739
8739
  const problems = missing.length === 0 ? [] : [`missing: ${missing.map((m) => sanitizeDetail(m)).join(", ")}`, ...inviteUrl ? [`invite the bot again with them (updates its role in place): ${inviteUrl}`] : []];
8740
- return [resultRow("bot-permissions", TITLE, problems, "every permission it needs")];
8740
+ return [resultRow("bot-permissions", TITLE$1, problems, "every permission it needs")];
8741
+ }
8742
+ // src/commands/notifications-reaction/parse-reaction/parse-reaction.ts
8743
+ /** A server emoji written as Discord shows it: `:name:`, the name 2 to 32 letters, digits and underscores. */
8744
+ const CUSTOM_EMOJI = /^:([A-Za-z0-9_]{2,32}):$/;
8745
+ /**
8746
+ * Reads a layout reaction. `":git_merge:"` (or `{ emoji: ":git_merge:", image }`) is a server emoji named `git_merge`;
8747
+ * any other string is a Unicode emoji and kept as written. It does not judge a value: `reactionProblem()` does, before
8748
+ * anything is applied, so an invalid `emoji` here is kept as the name it was given.
8749
+ */
8750
+ function parseReaction(reaction) {
8751
+ if (typeof reaction === "string") {
8752
+ const name = CUSTOM_EMOJI.exec(reaction)?.[1];
8753
+ return name === void 0 ? {
8754
+ kind: "unicode",
8755
+ value: reaction
8756
+ } : {
8757
+ kind: "custom",
8758
+ name
8759
+ };
8760
+ }
8761
+ return {
8762
+ kind: "custom",
8763
+ name: CUSTOM_EMOJI.exec(reaction.emoji)?.[1] ?? reaction.emoji,
8764
+ ...reaction.image ? { image: reaction.image } : {}
8765
+ };
8766
+ }
8767
+ // src/commands/notifications-reaction/emoji-conflict-problem/emoji-conflict-problem.ts
8768
+ /**
8769
+ * The first server emoji a layout gives two different pictures, or undefined. One name is one emoji, so it can be made
8770
+ * from one file only; the same file written twice is fine.
8771
+ */
8772
+ function emojiConflictProblem(layout) {
8773
+ const images = /* @__PURE__ */ new Map();
8774
+ for (const channel of (layout.categories ?? []).flatMap((c) => c.channels ?? [])) {
8775
+ const reactions = [...channel.defaultReaction === void 0 ? [] : [channel.defaultReaction], ...channel.starterReactions ?? []];
8776
+ for (const reaction of reactions) {
8777
+ const parsed = parseReaction(reaction);
8778
+ if (parsed.kind !== "custom" || !parsed.image) continue;
8779
+ const image = posix.normalize(parsed.image);
8780
+ const have = images.get(parsed.name);
8781
+ if (have !== void 0 && have !== image) return `emoji \`:${parsed.name}:\` is given two different images, \`${have}\` and \`${image}\``;
8782
+ images.set(parsed.name, image);
8783
+ }
8784
+ }
8785
+ }
8786
+ // src/commands/notifications-reaction/layout-emojis/layout-emojis.ts
8787
+ /**
8788
+ * The server emoji a layout's forum reactions name (default and starter), once each, in the order the layout first
8789
+ * names them. A name that is given an `image` anywhere keeps it, so the picture can sit on any one of its uses.
8790
+ */
8791
+ function layoutEmojis(layout) {
8792
+ const found = /* @__PURE__ */ new Map();
8793
+ for (const channel of (layout?.categories ?? []).flatMap((c) => c.channels ?? [])) {
8794
+ const reactions = [...channel.defaultReaction === void 0 ? [] : [channel.defaultReaction], ...channel.starterReactions ?? []];
8795
+ for (const reaction of reactions) {
8796
+ const parsed = parseReaction(reaction);
8797
+ if (parsed.kind !== "custom") continue;
8798
+ const have = found.get(parsed.name);
8799
+ if (!have) found.set(parsed.name, {
8800
+ name: parsed.name,
8801
+ ...parsed.image ? { image: parsed.image } : {}
8802
+ });
8803
+ else if (!have.image && parsed.image) have.image = parsed.image;
8804
+ }
8805
+ }
8806
+ return [...found.values()];
8807
+ }
8808
+ const ascii = (bytes, from, to) => Buffer.from(bytes.subarray(from, to)).toString("latin1");
8809
+ /** The image type the first bytes show, among the ones Discord takes for an emoji (JPEG, PNG, GIF, WebP, AVIF). */
8810
+ function typeOf(bytes) {
8811
+ if (bytes.length >= 8 && [
8812
+ 137,
8813
+ 80,
8814
+ 78,
8815
+ 71,
8816
+ 13,
8817
+ 10,
8818
+ 26,
8819
+ 10
8820
+ ].every((b, i) => bytes[i] === b)) return "image/png";
8821
+ if (bytes.length >= 3 && bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) return "image/jpeg";
8822
+ if (ascii(bytes, 0, 4) === "GIF8") return "image/gif";
8823
+ if (ascii(bytes, 0, 4) === "RIFF" && ascii(bytes, 8, 12) === "WEBP") return "image/webp";
8824
+ if (ascii(bytes, 4, 8) === "ftyp" && ["avif", "avis"].includes(ascii(bytes, 8, 12))) return "image/avif";
8825
+ }
8826
+ /**
8827
+ * Reads the picture an emoji is made from, a file in the repo, and returns it as a `data:` URI. The type comes from the
8828
+ * first bytes, not the name, and a file Discord would refuse (larger than 256 KiB, or not a JPEG, PNG, GIF, WebP or
8829
+ * AVIF image) is refused here, before anything is written. `read` is injected by tests.
8830
+ */
8831
+ async function loadEmojiImage(source, baseDir = process.cwd(), read = readFile) {
8832
+ const bytes = await read(resolve(baseDir, source));
8833
+ if (bytes.length > 262144) throw new Error(`it is ${Math.ceil(bytes.length / 1024)} KiB, and Discord takes an emoji up to 256 KiB`);
8834
+ const type = typeOf(bytes);
8835
+ if (!type) throw new Error("it is not a JPEG, PNG, GIF, WebP or AVIF image, which are the formats Discord takes");
8836
+ return `data:${type};base64,${Buffer.from(bytes).toString("base64")}`;
8837
+ }
8838
+ // src/commands/notifications-reaction/reaction-problem/reaction-problem.ts
8839
+ /** The folder a layout's emoji pictures live in, as the webhook avatar's files do. */
8840
+ const EMOJI_MEDIA_DIR = ".holocron/media/";
8841
+ /**
8842
+ * The first reason a reaction cannot work, or undefined; `noun` names it in the message (`` `defaultReaction` ``, "a
8843
+ * starter reaction"). A Unicode emoji must be a character, not a word (`git_merge` without colons would be sent to
8844
+ * Discord as text), a server emoji `:name:` with a name Discord allows, and an `image` a file under `.holocron/media/`
8845
+ * (a path, not a URL, with no `..` out of it). A `null` a config wrote is refused, not read as absent.
8846
+ */
8847
+ function reactionProblem(noun, reaction) {
8848
+ if (reaction === null || typeof reaction !== "string" && typeof reaction !== "object") return `${noun} must be an emoji, \`:name:\` for a server emoji, or \`{ emoji, image }\``;
8849
+ const text = typeof reaction === "string" ? reaction : reaction.emoji;
8850
+ if (typeof text !== "string" || text.trim() === "") return `${noun} is empty`;
8851
+ const isCustom = CUSTOM_EMOJI.test(text);
8852
+ if (typeof reaction === "object" && !isCustom) return `${noun}: \`emoji\` must be a server emoji written \`:name:\` (2 to 32 letters, digits and underscores), not \`${text}\``;
8853
+ if (!isCustom && /^:|:$|^[A-Za-z0-9_ ]+$/.test(text)) return `${noun}: \`${text}\` is not an emoji; write a server emoji as \`:name:\` (2 to 32 letters, digits and underscores)`;
8854
+ if (typeof reaction === "object" && reaction.image !== void 0) {
8855
+ const image = reaction.image;
8856
+ if (typeof image !== "string" || image.trim() === "") return `${noun}: \`image\` is empty`;
8857
+ if (/^[a-z][a-z0-9+.-]+:/i.test(image)) return `${noun}: \`image\` must be a file under \`${EMOJI_MEDIA_DIR}\`, not a URL`;
8858
+ const path = posix.normalize(image);
8859
+ if (!path.startsWith(".holocron/media/") || path === ".holocron/media/") return `${noun}: \`image\` must be a file under \`${EMOJI_MEDIA_DIR}\`, not \`${image}\``;
8860
+ }
8861
+ }
8862
+ // src/commands/notifications-reaction/reaction-spelling/reaction-spelling.ts
8863
+ /** How a reaction is written in a layout and shown in a row: `:name:` for a server emoji, the character otherwise. */
8864
+ function reactionSpelling(reaction) {
8865
+ const parsed = parseReaction(reaction);
8866
+ return parsed.kind === "custom" ? `:${parsed.name}:` : parsed.value;
8867
+ }
8868
+ // src/commands/emoji-checks/emoji-checks.ts
8869
+ const TITLE = "server emoji the forums' reactions name exist";
8870
+ /**
8871
+ * The step of `doctor notifications` for server emoji: each one a forum's `defaultReaction` or `starterReactions` names
8872
+ * (`:git_merge:`) is on the server. A missing one fails by name, and says how to get it: `setup` makes it when the layout
8873
+ * gives it an `image`, otherwise it has to be added in the server's settings (or the reaction changed). A changed default
8874
+ * reaction is the `channels` step's. Read-only. No row when no reaction names a server emoji; a skip when the server or
8875
+ * its emoji could not be read.
8876
+ */
8877
+ function emojiChecks(input) {
8878
+ const wanted = layoutEmojis(input.layout);
8879
+ if (wanted.length === 0) return [];
8880
+ const { found } = input;
8881
+ if (!found) return [skipRow$1("emoji", TITLE, "not checked: could not read the server")];
8882
+ if (found.emojisError) return [skipRow$1("emoji", TITLE, `not checked: could not read the server's emoji (${sanitizeDetail(found.emojisError)})`)];
8883
+ const have = new Set(found.emojis ?? []);
8884
+ const problems = wanted.filter((emoji) => !have.has(emoji.name)).map((emoji) => {
8885
+ const name = sanitizeDetail(emoji.name);
8886
+ return emoji.image ? `:${name}: is not on the server; \`setup notifications\` makes it from ${sanitizeDetail(emoji.image)}` : `:${name}: is not on the server; add it in the server's settings, or give the reaction an \`image\` for \`setup notifications\` to make it from`;
8887
+ });
8888
+ return [resultRow("emoji", TITLE, problems, `${wanted.length} of ${wanted.length} on the server`)];
8741
8889
  }
8742
8890
  // src/commands/notifications-setup/layout-picture-problem/layout-picture-problem.ts
8743
8891
  /** The first reason a picture in the layout (`webhookAvatar`, a channel's `webhook.avatar`) cannot work, or undefined. */
@@ -9044,8 +9192,14 @@ function forumLayoutProblem(layout) {
9044
9192
  continue;
9045
9193
  }
9046
9194
  if (channel.webhook || channel.feeds?.monitoring || channel.feeds?.errors) return `${where}: a forum takes no \`webhook\` or the \`monitoring\` and \`errors\` feeds; its conversations are posts`;
9047
- if (channel.defaultReaction !== void 0 && channel.defaultReaction.trim() === "") return `${where}: \`defaultReaction\` is empty`;
9048
- if ((channel.starterReactions ?? []).some((r) => r.trim() === "")) return `${where}: a starter reaction is empty`;
9195
+ if (channel.defaultReaction !== void 0) {
9196
+ const problem = reactionProblem("`defaultReaction`", channel.defaultReaction);
9197
+ if (problem) return `${where}: ${problem}`;
9198
+ }
9199
+ for (const reaction of channel.starterReactions ?? []) {
9200
+ const problem = reactionProblem("a starter reaction", reaction);
9201
+ if (problem) return `${where}: ${problem}`;
9202
+ }
9049
9203
  const seen = /* @__PURE__ */ new Set();
9050
9204
  for (const tag of channel.tags ?? []) {
9051
9205
  const name = tag.name.trim().toLowerCase();
@@ -9058,6 +9212,8 @@ function forumLayoutProblem(layout) {
9058
9212
  if (missing.length > 0) return `${where}: \`feeds.prs\` needs the tags ${missing.map((t) => `\`${t}\``).join(", ")}; add them to \`tags\``;
9059
9213
  }
9060
9214
  }
9215
+ const emojiProblem = emojiConflictProblem(layout);
9216
+ if (emojiProblem) return emojiProblem;
9061
9217
  const forums = new Set(channels.filter((c) => c.kind === "forum").map((c) => c.name.toLowerCase()));
9062
9218
  for (const pin of layout.pinned ?? []) if (forums.has(pin.channel.toLowerCase())) return `pinned: \`${pin.channel}\` is a forum; a message is pinned in a post, not in the forum`;
9063
9219
  }
@@ -9267,6 +9423,16 @@ async function runNotificationsSetup(input$1) {
9267
9423
  if (forumProblem) return refuse(forumProblem);
9268
9424
  const serverProblem = serverLayoutProblem(layout);
9269
9425
  if (serverProblem) return refuse(serverProblem);
9426
+ const emojiImages = /* @__PURE__ */ new Map();
9427
+ const readEmoji = input$1.loadEmojiImage ?? ((source) => loadEmojiImage(source, input$1.context.repoRoot));
9428
+ for (const emoji of layoutEmojis(layout)) {
9429
+ if (!emoji.image) continue;
9430
+ try {
9431
+ emojiImages.set(emoji.name, await readEmoji(emoji.image));
9432
+ } catch (err) {
9433
+ return refuse(`emoji \`:${emoji.name}:\` image \`${emoji.image}\`: ${errorMessage(err)}`);
9434
+ }
9435
+ }
9270
9436
  if (layout.server && !notifications.ensureServer) return refuse(`the layout declares \`server\` settings, but the \`${notifications.providerName}\` provider cannot manage them`);
9271
9437
  if (layout.welcome && !notifications.ensureWelcome) return refuse(`the layout declares a \`welcome\` screen, but the \`${notifications.providerName}\` provider cannot manage one`);
9272
9438
  if (layout.onboarding && !notifications.ensureOnboarding) return refuse(`the layout declares \`onboarding\`, but the \`${notifications.providerName}\` provider cannot manage it`);
@@ -9275,6 +9441,7 @@ async function runNotificationsSetup(input$1) {
9275
9441
  if (layout.everyone && !notifications.ensureEveryone) return refuse(`the layout declares \`everyone\` permissions, but the \`${notifications.providerName}\` provider cannot manage them`);
9276
9442
  const needsCategories = (layout.categories ?? []).find((c) => c.access);
9277
9443
  if (needsCategories && !notifications.ensureCategory) return refuse(`category \`${needsCategories.name}\` declares \`access\`, but the \`${notifications.providerName}\` provider cannot manage categories`);
9444
+ if (emojiImages.size > 0 && !notifications.ensureEmoji) return refuse(`the layout gives a server emoji an \`image\`, but the \`${notifications.providerName}\` provider cannot create emoji`);
9278
9445
  const providerProblem = notifications.validateLayout?.(layout);
9279
9446
  if (providerProblem) return refuse(providerProblem);
9280
9447
  if (!dryRun && notifications.preflight) try {
@@ -9341,6 +9508,24 @@ async function runNotificationsSetup(input$1) {
9341
9508
  tally.ok++;
9342
9509
  }
9343
9510
  });
9511
+ if (emojiImages.size > 0) print(`\n${style.header("Emoji")}`);
9512
+ for (const [name, image] of emojiImages) await attempt(`emoji :${name}:`, async () => {
9513
+ if (dryRun) {
9514
+ print(` ${style.skip(`would ensure emoji :${name}: (made from its image only when the server has none)`)}`);
9515
+ tally.skip++;
9516
+ return;
9517
+ }
9518
+ const result = await notifications.ensureEmoji({
9519
+ name,
9520
+ image
9521
+ });
9522
+ report.emojis = [...report.emojis ?? [], {
9523
+ name,
9524
+ created: result.created
9525
+ }];
9526
+ print(` ${(result.created ? style.success : style.skip)(`${result.created ? "created" : "exists "} emoji :${name}: (id ${result.id})`)}`);
9527
+ made(result.created);
9528
+ });
9344
9529
  for (const category of layout.categories ?? []) {
9345
9530
  print(`\n${style.header(category.name)}`);
9346
9531
  report.categories.push(category.name);
@@ -10646,7 +10831,8 @@ async function runDoctorNotifications(input) {
10646
10831
  const isForum = channel.kind === "forum";
10647
10832
  if (isForum !== (match.kind === "forum")) channelProblems.push(`#${shown(channel.name)}: is ${isForum ? "a text channel, and the layout says forum" : "a forum, and the layout says text"}; delete it so \`setup\` can make it again`);
10648
10833
  else if (isForum) {
10649
- if (channel.defaultReaction && (match.defaultReaction ?? "") !== channel.defaultReaction) channelProblems.push(`#${shown(channel.name)}: default reaction is ${match.defaultReaction ? `"${shown(match.defaultReaction)}"` : "not set"} but the layout says "${shown(channel.defaultReaction)}"`);
10834
+ const wantReaction = channel.defaultReaction ? reactionSpelling(channel.defaultReaction) : void 0;
10835
+ if (wantReaction && (match.defaultReaction ?? "") !== wantReaction) channelProblems.push(`#${shown(channel.name)}: default reaction is ${match.defaultReaction ? `"${shown(match.defaultReaction)}"` : "not set"} but the layout says "${shown(wantReaction)}"`);
10650
10836
  for (const tag of channel.tags ?? []) {
10651
10837
  const have = match.tags?.find((t) => same$2(t.name, tag.name));
10652
10838
  if (!have) channelProblems.push(`#${shown(channel.name)}: tag "${shown(tag.name)}" is missing`);
@@ -10959,6 +11145,10 @@ async function runDoctorNotifications(input) {
10959
11145
  found
10960
11146
  }));
10961
11147
  checks.push(...botPermissionChecks({ found }));
11148
+ checks.push(...emojiChecks({
11149
+ layout,
11150
+ found
11151
+ }));
10962
11152
  checks.push(...prFeedChecks({
10963
11153
  layout,
10964
11154
  found