@theholocron/cli 5.1.5 → 5.2.1

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
@@ -1061,6 +1061,12 @@ named `holocron <command> — <timestamp>`, and streams the CLI logger's lines (
1061
1061
  fields only) into it in batches while it runs. The run's `commandLog` line is the thread's last post. It is best effort,
1062
1062
  bounded by the same two second deadline at the end, and never changes the exit code or the output.
1063
1063
 
1064
+ `holocron setup` and `holocron sync` also write `.github/workflows/platform.notifications.yml` (#1579), the workflow that
1065
+ tells Discord about a failed run on the default branch and about a deploy through the org's `HOLOCRON_NOTIFY_WEBHOOK_*`
1066
+ secrets (a missing secret skips the post). It watches the workflow of every task in `tasks`; `notifications.workflows`
1067
+ lists the names to watch instead, and `notifications.workflow: false` writes none (a copy written earlier is removed on
1068
+ the next `sync`). Only the repository root's config writes it.
1069
+
1064
1070
  ### ESLint bundle options
1065
1071
 
1066
1072
  Most repos need nothing here — `@theholocron/eslint-config`'s `library()`
package/dist/cli.mjs CHANGED
@@ -3412,6 +3412,24 @@ function validateIssueTypes(value, at = "issueTypes") {
3412
3412
  };
3413
3413
  });
3414
3414
  }
3415
+ // src/config/validate-notifications-workflow/validate-notifications-workflow.ts
3416
+ /**
3417
+ * Check `notifications.workflow` (a boolean) and `notifications.workflows` (workflow names with no space or control
3418
+ * character), which decide the generated notifications workflow (#1579). The block itself is checked by
3419
+ * `validateCommandLog()`, which runs first.
3420
+ *
3421
+ * @param notifications - The config's top-level `notifications` block, if it has one.
3422
+ * @throws {ConfigError} Naming the key and what it accepts.
3423
+ */
3424
+ function validateNotificationsWorkflow(notifications) {
3425
+ const workflow = notifications?.workflow;
3426
+ if (workflow !== void 0 && typeof workflow !== "boolean") throw new ConfigError$1(`\`notifications.workflow\` must be true or false, got ${JSON.stringify(workflow)}`);
3427
+ const workflows = notifications?.workflows;
3428
+ if (workflows === void 0) return;
3429
+ if (!Array.isArray(workflows)) throw new ConfigError$1(`\`notifications.workflows\` must be a list of workflow names, got ${JSON.stringify(workflows)}`);
3430
+ if (workflows.length === 0) throw new ConfigError$1("`notifications.workflows` is empty: list at least one workflow, or set `notifications.workflow` to false");
3431
+ for (const name of workflows) if (typeof name !== "string" || name === "" || /[\s\u0000-\u001f]/.test(name)) throw new ConfigError$1(`\`notifications.workflows\` holds ${JSON.stringify(name)}: each entry must be a workflow name with no space`);
3432
+ }
3415
3433
  /** GitHub's longest wait timer: 30 days, in minutes. */
3416
3434
  const MAX_WAIT_TIMER = 43200;
3417
3435
  const KEYS$1 = /* @__PURE__ */ new Set([
@@ -3880,6 +3898,7 @@ function resolveConfig(raw) {
3880
3898
  validateRepoViews(raw.repo?.views);
3881
3899
  validateCommandLog(raw.notifications);
3882
3900
  validateCommandThreads(raw.notifications);
3901
+ validateNotificationsWorkflow(raw.notifications);
3883
3902
  validateRepoEnvironments(raw.repo?.environments);
3884
3903
  validateRepoProtectedBranches(raw.repo?.protectedBranches, raw.repo?.defaultBranch);
3885
3904
  validateRequiredChecks(raw.repo?.requiredChecks);
@@ -7580,7 +7599,7 @@ const cleanupCommand = {
7580
7599
  handler: () => {}
7581
7600
  };
7582
7601
  // src/commands/clone/clone.args.ts
7583
- const cloneArgs = (y) => y.positional("target", {
7602
+ const cloneArgs$1 = (y) => y.positional("target", {
7584
7603
  type: "string",
7585
7604
  describe: "org/repo to clone, or a bare org to clone every repo in it (confirms first)."
7586
7605
  }).option("dir", {
@@ -7792,7 +7811,7 @@ const resolveCloneToken = createFeatureResolver({
7792
7811
  const cloneCommand = {
7793
7812
  command: "clone [target]",
7794
7813
  describe: "Clone a single repo (org/repo) or every repo in an org (org)",
7795
- builder: cloneArgs,
7814
+ builder: cloneArgs$1,
7796
7815
  handler: async (argv) => {
7797
7816
  const tokens = tokenContext(argv.token);
7798
7817
  if (!tokens) return;
@@ -18330,6 +18349,28 @@ async function runNotificationsLink(input) {
18330
18349
  return refuse(describeError(err), logReason(err));
18331
18350
  }
18332
18351
  }
18352
+ // src/commands/notifications-workflow/notifications.yml
18353
+ var notifications_default = "# Tells Discord about the runs nobody is watching (#1159, epic #1160):\n#\n# - A workflow that fails on `alpha` or `main` (not a pull request) posts to #alerts and pings the gatekeepers. A failed\n# deploy, deploy-docs, deploy-components, preview, deploy-preview, check-preview or deploy-sentinel goes to #deploys\n# instead. The daily check-tokens run is in the list, so a token close to expiring reaches #alerts the day it is found.\n# The post names the failing jobs of that run with links (five at most, then \"and N more\"), read with `actions: read`\n# (#1614); when they cannot be read the post is just the run's line.\n# - A deploy, preview or check-preview that succeeds posts to #deploys too (#1578), on any branch and for a pull\n# request, so the channel shows every deploy and not only the broken ones. That is deliberately noisy; narrow the\n# `deployed` job's `if` to dial it back.\n# When GitHub has a deployment of the run's commit with a successful status that carries an environment URL (the preview\n# or the domain), the post ends with it in angle brackets (#2855); without one the post is unchanged.\n# - A release is announced by the release job itself (`holocron sync releases` in `release.yml`: the message and its\n# thread), not here; this workflow posts a `release` run only when it errors.\n#\n# The runs are named for their task id (`test:unit`, `release`, …), the workflow, job and file names being the id since\n# #1620, and a release is told from the other runs by its file. `holocron doctor notifications` fails on a listed name\n# that is no task id. Repo sync (`sync-repo.yml`) is left out, because it posts its own result, and so is this\n# workflow, so a failure here cannot loop. `workflow_run` only fires from the default branch, so a change to this\n# file takes effect once it is on the default branch. A missing webhook secret skips the post and never fails the run.\nname: Notifications\n\non: # yamllint disable-line rule:truthy\n workflow_run:\n workflows:\n - __WORKFLOWS__\n types: [completed]\n\npermissions: {}\n\njobs:\n failed:\n name: Notify of a failed run\n if: >-\n github.event.workflow_run.conclusion == 'failure' &&\n github.event.workflow_run.event != 'pull_request' &&\n !endsWith(github.event.workflow_run.path, 'sync-repo.yml') &&\n contains(fromJSON('[\"alpha\",\"main\"]'), github.event.workflow_run.head_branch)\n runs-on: ubuntu-latest\n timeout-minutes: 2\n permissions:\n actions: read\n env:\n WORKFLOW: ${{ github.event.workflow_run.name }}\n FILE: ${{ github.event.workflow_run.path }}\n BRANCH: ${{ github.event.workflow_run.head_branch }}\n URL: ${{ github.event.workflow_run.html_url }}\n ATTEMPT: ${{ github.event.workflow_run.run_attempt }}\n RUN_ID: ${{ github.event.workflow_run.id }}\n GH_TOKEN: ${{ github.token }}\n steps:\n - name: Word the message\n id: message\n run: |\n retry=\"\"\n if [ \"$ATTEMPT\" -gt 1 ]; then retry=\" (attempt $ATTEMPT)\"; fi\n text=\"❌ ${GITHUB_REPOSITORY}: $WORKFLOW (${FILE##*/}) failed on $BRANCH — <$URL>$retry\"\n # The jobs of this attempt that failed, five at most, then \"and N more\". A name loses its brackets and is cut\n # to 80 characters, so the message stays inside Discord's 2000. If the jobs cannot be read, or none failed\n # (a cancelled run), the message is the line above.\n failed=$(gh api \"repos/${GITHUB_REPOSITORY}/actions/runs/${RUN_ID}/attempts/${ATTEMPT}/jobs?per_page=100\" 2>/dev/null |\n jq -r '[.jobs[] | select(.conclusion == \"failure\" or .conclusion == \"timed_out\")] as $f\n | ($f[:5][] | \"• [\\(.name | gsub(\"[\\\\[\\\\]\\r\\n]\"; \" \") | .[:80])](<\\(.html_url)>)\"),\n (if ($f | length) > 5 then \"and \\($f | length - 5) more\" else empty end)' 2>/dev/null) || failed=\"\"\n {\n echo \"text<<HOLOCRON_EOF\"\n echo \"$text\"\n if [ -n \"$failed\" ]; then\n echo \"Failed jobs:\"\n echo \"$failed\"\n fi\n echo \"HOLOCRON_EOF\"\n } >> \"$GITHUB_OUTPUT\"\n\n - uses: theholocron/holocron/ci/actions/notify@ci-v1\n name: \"Notify #deploys\"\n if: ${{ contains(fromJSON('[\"deploy\",\"deploy-docs\",\"deploy-components\",\"preview\",\"deploy-sentinel\"]'), github.event.workflow_run.name) || endsWith(github.event.workflow_run.path, 'deploy-preview.yml') || endsWith(github.event.workflow_run.path, 'check-preview.yml') }}\n with:\n webhook: ${{ secrets.HOLOCRON_NOTIFY_WEBHOOK_DEPLOYS }}\n message: ${{ steps.message.outputs.text }}\n\n - uses: theholocron/holocron/ci/actions/notify@ci-v1\n name: \"Notify #alerts\"\n if: ${{ !(contains(fromJSON('[\"deploy\",\"deploy-docs\",\"deploy-components\",\"preview\",\"deploy-sentinel\"]'), github.event.workflow_run.name) || endsWith(github.event.workflow_run.path, 'deploy-preview.yml') || endsWith(github.event.workflow_run.path, 'check-preview.yml')) }}\n with:\n webhook: ${{ secrets.HOLOCRON_NOTIFY_WEBHOOK_ALERTS }}\n mention: ${{ secrets.HOLOCRON_NOTIFY_ALERT_ROLE }}\n message: ${{ steps.message.outputs.text }}\n\n deployed:\n name: Notify of a deploy\n if: >-\n github.event.workflow_run.conclusion == 'success' &&\n (contains(fromJSON('[\"deploy\",\"deploy-docs\",\"deploy-components\",\"preview\",\"deploy-sentinel\"]'), github.event.workflow_run.name) ||\n endsWith(github.event.workflow_run.path, 'deploy-preview.yml') ||\n endsWith(github.event.workflow_run.path, 'check-preview.yml'))\n runs-on: ubuntu-latest\n timeout-minutes: 2\n permissions:\n deployments: read\n env:\n WORKFLOW: ${{ github.event.workflow_run.name }}\n FILE: ${{ github.event.workflow_run.path }}\n BRANCH: ${{ github.event.workflow_run.head_branch }}\n EVENT: ${{ github.event.workflow_run.event }}\n URL: ${{ github.event.workflow_run.html_url }}\n SHA: ${{ github.event.workflow_run.head_sha }}\n GH_TOKEN: ${{ github.token }}\n steps:\n - name: Word the message\n id: message\n run: |\n where=\"on $BRANCH\"\n if [ \"$EVENT\" = \"pull_request\" ]; then where=\"for a pull request ($BRANCH)\"; fi\n text=\"✅ ${GITHUB_REPOSITORY}: $WORKFLOW (${FILE##*/}) succeeded $where — <$URL>\"\n # What was deployed: the environment URL of the newest status of the newest deployment of this commit that is\n # a success with a URL (the run does not name its deployment, so a commit deployed to two environments gets one). The URL is text someone else set, so it is read through jq into a variable, never into the\n # script, and used only if it is one https URL with no space, control character or angle bracket. Anything else, or any\n # failure, leaves the line above and a notice: a notification problem never fails the run it reports on.\n deployed=\"\"\n ids=$(gh api \"repos/${GITHUB_REPOSITORY}/deployments?sha=${SHA}&per_page=20\" 2>/dev/null |\n jq -r 'sort_by(.created_at) | reverse | .[:5][] | .id' 2>/dev/null) || ids=\"\"\n for id in $ids; do\n [[ \"$id\" =~ ^[0-9]+$ ]] || continue\n # Only the newest status of a deployment says what it is now: a newer failure or `inactive` (a replaced or\n # deleted preview) means this deployment has no link, and the next older deployment is tried.\n deployed=$(gh api \"repos/${GITHUB_REPOSITORY}/deployments/${id}/statuses?per_page=30\" 2>/dev/null |\n jq -r 'max_by(.created_at) | select(.state == \"success\") | .environment_url // empty' 2>/dev/null) || deployed=\"\"\n [ -n \"$deployed\" ] && break\n done\n link='^https://[^[:space:][:cntrl:]<>]+$'\n if [ -z \"$deployed\" ]; then\n echo \"::notice::No deployment URL found for $SHA, so the post has no link.\"\n elif [[ \"$deployed\" =~ $link ]] && [ \"${#deployed}\" -le 300 ]; then\n text=\"$text · deployed to <$deployed>\"\n else\n echo \"::notice::The deployment URL for $SHA is not a plain https URL, so the post has no link.\"\n fi\n echo \"text=$text\" >> \"$GITHUB_OUTPUT\"\n\n - uses: theholocron/holocron/ci/actions/notify@ci-v1\n name: \"Notify #deploys\"\n with:\n webhook: ${{ secrets.HOLOCRON_NOTIFY_WEBHOOK_DEPLOYS }}\n message: ${{ steps.message.outputs.text }}\n";
18354
+ // src/commands/notifications-workflow/notifications-workflow.ts
18355
+ /** Where the workflow that posts failed runs and deploys lives, on the default branch. */
18356
+ const NOTIFICATIONS_WORKFLOW_PATH = ".github/workflows/platform.notifications.yml";
18357
+ /** The runs that are never watched: this workflow, and repo sync, which posts its own result. */
18358
+ const UNWATCHED_WORKFLOWS = ["Notifications", "sync-repo"];
18359
+ const PLACEHOLDER = " - __WORKFLOWS__";
18360
+ /** A name YAML reads as the same text without quotes (a task id: letters, digits, `.`, `_`, `-`, and a `:` between parts). */
18361
+ const PLAIN_NAME = /^[A-Za-z0-9_.-]+(:[A-Za-z0-9_.-]+)*$/;
18362
+ /**
18363
+ * The text of `platform.notifications.yml` (#1579): the workflow that tells Discord about a failed run on the default
18364
+ * branch and about a deploy, with the runs it watches filled in. Each name is one `workflows:` entry, quoted only when it
18365
+ * is not a plain task id.
18366
+ *
18367
+ * @returns `undefined` when no workflow is left to watch, because `workflow_run` needs at least one.
18368
+ */
18369
+ function renderNotificationsWorkflow(input) {
18370
+ const names = [...new Set(input.workflows)].filter((name) => !UNWATCHED_WORKFLOWS.includes(name));
18371
+ if (names.length === 0) return void 0;
18372
+ return notifications_default.replace(PLACEHOLDER, names.map((name) => ` - ${PLAIN_NAME.test(name) ? name : JSON.stringify(name)}`).join("\n"));
18373
+ }
18333
18374
  // src/commands/workflow-name-problems/workflow-name-problems.ts
18334
18375
  /** The six group names a caller workflow had before its name became the task id. */
18335
18376
  const GROUP_NAMES = /* @__PURE__ */ new Set([
@@ -18360,8 +18401,6 @@ function workflowNameProblems(text) {
18360
18401
  });
18361
18402
  }
18362
18403
  // src/commands/notifications-workflow-checks/notifications-workflow-checks.ts
18363
- /** Where the workflow that posts failed runs and deploys lives, on the default branch. */
18364
- const NOTIFICATIONS_WORKFLOW_PATH = ".github/workflows/platform.notifications.yml";
18365
18404
  /** The webhook secrets the workflow posts through: failed runs and deploys. A release is announced by the release job. */
18366
18405
  const WEBHOOK_SECRETS = ["HOLOCRON_NOTIFY_WEBHOOK_ALERTS", "HOLOCRON_NOTIFY_WEBHOOK_DEPLOYS"];
18367
18406
  const PRESENT_ID = "notifications-workflow";
@@ -25698,6 +25737,20 @@ function generateWorkflowFiles(input) {
25698
25737
  }
25699
25738
  });
25700
25739
  }
25740
+ if (pkgRelPath === "." && config.notifications?.workflow !== false) {
25741
+ const content = renderNotificationsWorkflow({ workflows: config.notifications?.workflows ?? wanted.map(({ key }) => key) });
25742
+ if (content !== void 0) entries.push({
25743
+ kind: "file",
25744
+ path: NOTIFICATIONS_WORKFLOW_PATH,
25745
+ content: thinCallerFile(pkgRelPath, content),
25746
+ step: "write workflow notifications",
25747
+ syncStep: "sync workflow notifications",
25748
+ workflow: {
25749
+ task: "notifications",
25750
+ filename: "platform.notifications.yml"
25751
+ }
25752
+ });
25753
+ }
25701
25754
  if (hosting && pkgRelPath === ".") {
25702
25755
  const aggregate = astromech.aggregateCaller();
25703
25756
  if (aggregate !== null) {
@@ -36741,6 +36794,41 @@ function listProbes(groups) {
36741
36794
  // src/commands/probe/references/clone-org.ts
36742
36795
  const SKIP_DIRS = /* @__PURE__ */ new Set([".git", "node_modules"]);
36743
36796
  const MAX_FILE_BYTES = 5242880;
36797
+ /** How often, and how long apart, removing a clone is tried again when something is still writing into it. */
36798
+ const REMOVE_RETRIES = 10;
36799
+ const REMOVE_RETRY_DELAY_MS = 200;
36800
+ /**
36801
+ * The arguments of `gh repo clone` for `org/name` into `dest`: a shallow, quiet clone that runs none of the user's git
36802
+ * hooks. The probe only reads, and a global hook (`core.hooksPath`, `init.templateDir`) such as a `post-checkout` that
36803
+ * starts `ctags` in the background writes `.git/tags` after the clone has returned, which made removing the clone fail
36804
+ * with `ENOTEMPTY` (#2913). `-c` takes effect before the files are checked out.
36805
+ */
36806
+ function cloneArgs(org, name, dest) {
36807
+ return [
36808
+ "repo",
36809
+ "clone",
36810
+ `${org}/${name}`,
36811
+ dest,
36812
+ "--",
36813
+ "--depth",
36814
+ "1",
36815
+ "--quiet",
36816
+ "-c",
36817
+ "core.hooksPath=/dev/null"
36818
+ ];
36819
+ }
36820
+ /**
36821
+ * Removes a scratch directory, trying again when something still writes into it. A process the clone left running can
36822
+ * recreate a file while the directory is being deleted; `rmSync` retries `ENOTEMPTY` (and `EBUSY`, `EPERM`) itself.
36823
+ */
36824
+ function removeScratch(path, remove = rmSync) {
36825
+ remove(path, {
36826
+ recursive: true,
36827
+ force: true,
36828
+ maxRetries: REMOVE_RETRIES,
36829
+ retryDelay: REMOVE_RETRY_DELAY_MS
36830
+ });
36831
+ }
36744
36832
  /** Every text file under `dir`: not in `.git` or `node_modules`, under 5 MiB, and without a NUL in its first KiB. */
36745
36833
  function* textFiles(dir, root = dir) {
36746
36834
  for (const entry of readdirSync(dir, { withFileTypes: true })) {
@@ -36776,29 +36864,18 @@ function cloneOrg(org) {
36776
36864
  files() {
36777
36865
  const scratch = mkdtempSync(join(tmpdir(), "refs-"));
36778
36866
  const dest = join(scratch, repo.name);
36779
- execFileSync("gh", [
36780
- "repo",
36781
- "clone",
36782
- `${org}/${repo.name}`,
36783
- dest,
36784
- "--",
36785
- "--depth",
36786
- "1",
36787
- "--quiet"
36788
- ], { stdio: "pipe" });
36867
+ execFileSync("gh", cloneArgs(org, repo.name, dest), { stdio: "pipe" });
36789
36868
  try {
36790
36869
  return [...textFiles(dest)];
36791
36870
  } finally {
36792
- rmSync(scratch, {
36793
- recursive: true,
36794
- force: true
36795
- });
36871
+ removeScratch(scratch);
36796
36872
  }
36797
36873
  }
36798
36874
  }));
36799
36875
  /* v8 ignore stop */
36800
36876
  }
36801
36877
  // src/commands/probe/references/find-references.ts
36878
+ const CALL = /^-?\s*uses:\s/;
36802
36879
  /** The repository that hosts the files; its own references are the starters and shims, not callers. */
36803
36880
  const HOST_REPO = ".github";
36804
36881
  /** What a reference points at, from the text after the needle. */
@@ -36823,6 +36900,14 @@ function findReferences(repo, needle) {
36823
36900
  });
36824
36901
  return found;
36825
36902
  }
36903
+ /**
36904
+ * Whether a reference is a live call: a `uses:` line in a YAML file, which is what GitHub reads. Tests, docs and specs
36905
+ * name the path on purpose (the legacy-path detection, a test that nothing spells it, a record of the move), so they are
36906
+ * references to list but not calls to wait on.
36907
+ */
36908
+ function isCall(ref) {
36909
+ return /\.ya?ml$/.test(ref.file) && CALL.test(ref.text);
36910
+ }
36826
36911
  // src/commands/probe/references/references-probes.ts
36827
36912
  function scan(repos, needle) {
36828
36913
  return {
@@ -36842,27 +36927,29 @@ function summarise(ctx, repos, found, needle, max) {
36842
36927
  ctx.say({
36843
36928
  status: "info",
36844
36929
  label: repo.name === ".github" ? `${repo.name} (host)` : repo.name,
36845
- detail: `${files} files: ${count("workflow")} workflow, ${count("action")} action, ${count("other")} other`
36930
+ detail: `${files} files: ${count("workflow")} workflow, ${count("action")} action, ${count("other")} other; ${own.filter(isCall).length} live calls`
36846
36931
  });
36847
36932
  }
36848
- const outside = found.filter((ref) => ref.repo !== HOST_REPO).length;
36849
- const detail = `${found.length - outside} more inside ${HOST_REPO}`;
36850
- if (max !== void 0 && outside > max) ctx.say({
36933
+ const outside = found.filter((ref) => ref.repo !== HOST_REPO);
36934
+ const calls = outside.filter(isCall).length;
36935
+ const inside = found.length - outside.length;
36936
+ const detail = `${outside.length} references in all (tests, docs and specs may name the path on purpose), ${inside} more inside ${HOST_REPO}`;
36937
+ if (calls > max) ctx.say({
36851
36938
  status: "fail",
36852
- label: `${outside} outside ${HOST_REPO}`,
36939
+ label: `${calls} live calls outside ${HOST_REPO}`,
36853
36940
  detail: `more than the ${max} allowed; ${detail}`
36854
36941
  });
36855
36942
  else ctx.say({
36856
36943
  status: "ok",
36857
- label: `${outside} outside ${HOST_REPO}`,
36944
+ label: `${calls} live calls outside ${HOST_REPO}`,
36858
36945
  detail
36859
36946
  });
36860
36947
  }
36861
36948
  /**
36862
36949
  * `ci refs` counts the references to the reusable workflows and composite actions hosted in `<org>/.github` across
36863
36950
  * every active repository of the org. It is the exit test for removing the forwarding shims there: they can go when
36864
- * the count outside `.github` is zero. `ci refs <max>` fails above `<max>`. `ci ref-list` prints each reference with
36865
- * its file and line.
36951
+ * no live call outside `.github` is left (a `uses:` line in a YAML file; see {@link isCall}). It fails above `<max>`,
36952
+ * which defaults to 0, so the exit code is the test (#2915). `ci ref-list` prints each reference with its file and line.
36866
36953
  */
36867
36954
  function ciProbes(org, clone = cloneOrg) {
36868
36955
  const needle = (name) => `${name}/.github/.github/`;
@@ -36882,13 +36969,13 @@ function ciProbes(org, clone = cloneOrg) {
36882
36969
  };
36883
36970
  return {
36884
36971
  refs: {
36885
- summary: "Count references to the reusable workflows and actions hosted in the org's .github repo (arg: max).",
36972
+ summary: "Count references to the reusable workflows and actions hosted in the org's .github repo; fails on a live call outside it (arg: max, default 0).",
36886
36973
  writes: false,
36887
36974
  async run(ctx) {
36888
36975
  const result = read(ctx);
36889
36976
  if (!result) return;
36890
- const max = ctx.args?.[0] === void 0 ? void 0 : Number(ctx.args[0]);
36891
- if (max !== void 0 && !Number.isInteger(max)) {
36977
+ const max = ctx.args?.[0] === void 0 ? 0 : Number(ctx.args[0]);
36978
+ if (!Number.isInteger(max) || max < 0) {
36892
36979
  ctx.say({
36893
36980
  status: "fail",
36894
36981
  label: `\`${ctx.args[0]}\` is not a number`,