@mark1russell7/conventions 0.7.0 → 0.8.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
@@ -38,6 +38,7 @@ The rules come from the invariants audit of 2026-10-26 (strategy item s38). The
38
38
  | `typed-files` | Each TypeScript file that git keeps (`.ts`, `.tsx`, `.mts`, `.cts`, not `.d.ts`) is in the program of a tsconfig that a `typecheck` script names: the tests, the e2e specs, the scripts, the benches and the configs too. The rule reads the configs of each `tsc`, `tsgo` or `vue-tsc` (`-p`, `--project`, `-b`, or `tsconfig.json`) and of `svelte-check --tsconfig`, follows their `references`, and lists the files with `tsc --listFilesOnly`. A file that a covered file imports is covered. A config that does not exist, and a repository where no typecheck names a config, are a break. | fleet `fail-closed` (STRATEGY.md, 2026-10-30). |
39
39
  | `tests-required` | No test runner passes when it finds no test: no `passWithNoTests: true` in a config of vitest, vite, jest or Playwright, and no `--passWithNoTests` in `package.json`. With the option, a broken include pattern turns the test gate green with no test run. | fleet `fail-closed` (STRATEGY.md, 2026-10-30). |
40
40
  | `roadmap-parses` | Each call of the Pages workflow of the template (`reusable-pages.yml`) gives a `roadmap`, or `site-pages: false`. Without it, the Status page shows no item of the plan. Each roadmap that a workflow gives to the Status page (a `roadmap:` key) parses as `@mark1russell7/site-pages` reads it. The rule uses the parser of site-pages. Thus a pull request finds a bad row, and the Pages job on `main` does not stop on it. | fleet `fail-closed` (STRATEGY.md, 2026-10-30). |
41
+ | `runner-budget` | All repositories of the account share 40 runners. Each `strategy` with a `matrix` has a `max-parallel` of 3 or less. Each workflow has a concurrency group at the top or in each job. A job that calls a shared workflow of the option `grouped` gets its group from that workflow, and each job of that workflow has a group. The minute of each `cron` comes from a hash of the repository and the file (1 to 59), so the schedules of the repositories do not start together. The repository comes from `GITHUB_REPOSITORY` or from the remote `origin`. | fleet `runner-slots` (STRATEGY.md, 2026-10-30). |
41
42
 
42
43
  The rule `release-files` needs the base of the change. On a pull request, the checkout is a merge commit, and the rule reads its two parents (`fetch-depth` 2 or more). In other runs, give `--base <ref>`. Without a base, the rule shows `skip`.
43
44
 
@@ -88,6 +89,9 @@ An unknown rule, an unknown option, or an exception or a changed option without
88
89
  | `typed-scripts.shellLines` | `1` | The most lines of code of a shell script (a launcher). Empty lines and comments do not count. |
89
90
  | `typed-files.configs` | `[]` | More tsconfig files, relative to the root, that CI examines with another command (for example a script that the typecheck starts). |
90
91
  | `roadmap-parses.roadmaps` | `[]` | More roadmap files, relative to the root, for a roadmap that no workflow names. |
92
+ | `runner-budget.maxParallel` | `3` | The largest `max-parallel` of a matrix. |
93
+ | `runner-budget.minute` | `true` | When `false`, the rule does not examine the minute of the schedules. |
94
+ | `runner-budget.grouped` | `["reusable-ai-review.yml", "reusable-codex-review.yml"]` | The shared workflows that give a concurrency group in each of their jobs. |
91
95
 
92
96
  ## Commands
93
97
 
package/build/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { c as runCli } from "./run-MyvUGD5l.js";
2
+ import { c as runCli } from "./run-B7ftggFF.js";
3
3
  // src/cli.ts
4
4
  try {
5
5
  process.exitCode = runCli(process.argv.slice(2), {
package/build/index.d.ts CHANGED
@@ -155,6 +155,15 @@ export declare const requiredScripts: Rule;
155
155
  /** This function gives the value of a `roadmap: <file>` line, or undefined for another line, an empty value or an expression. */
156
156
  export declare function roadmapOfLine(line: string): string | undefined;
157
157
  export declare const roadmapParses: Rule;
158
+ /**
159
+ * This function gives the minute (1 to 59) of the schedules of a workflow: the FNV-1a hash of the repository and the
160
+ * file. Two repositories with the same workflow thus start at different minutes, and no schedule starts at minute 0,
161
+ * where GitHub has the most load.
162
+ */
163
+ export declare function scheduleMinute(repository: string, file: string): number;
164
+ /** This function gives `owner/name` from a git remote URL, or undefined for a URL that is not of GitHub. */
165
+ export declare function repositoryOfRemote(url: string): string | undefined;
166
+ export declare const runnerBudget: Rule;
158
167
  /** This function gives each path in the value of an entry field (a string, or the strings in an object). */
159
168
  export declare function pathsOf(value: unknown): string[];
160
169
  /** This function tells if a path is a source file: a file in `src/`, or a TypeScript file that is not a declaration file. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/rule.ts","../src/config.ts","../src/rules/cue-preset.ts","../src/rules/no-build-output.ts","../src/rules/no-local-paths.ts","../src/rules/pinned-git-deps.ts","../src/rules/release-files.ts","../src/rules/required-scripts.ts","../src/rules/roadmap-parses.ts","../src/rules/source-main.ts","../src/rules/tests-required.ts","../src/rules/tsconfig-test.ts","../src/rules/typed-files.ts","../src/rules/typed-scripts.ts","../src/rules/workspace-protocol.ts","../src/rules/index.ts","../src/run.ts","../src/workspace.ts"],"mappings":";UASiB;WACN;WACA;WACA;;;UAIM;;WAEN;;WAEA;WACA;;WAEA;;;KAIC;;KAGA,UAAU,SAAS,eAAe;;UAG7B;WACN;WACA,SAAS;WACT;;;KAIC,WAAW,SAAS;;UAGf;;WAEN;;WAEA;;WAEA;;WAEA;WACA,UAAU;;;UAIJ;;WAEN;;WAEA,aAAa;;WAEb,mBAAmB;;WAEnB,KAAK,SAAS;;WAEd;;EAET;;EAEA,IAAI;;;KAIM,uBAAuB;WAAqB;;;UAGvC;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA,kBAAkB;;WAElB,SAAS,SAAS,eAAe;EAC1C,MAAM,SAAS,aAAa,SAAS,UAAU;;;qBAIpC;;wBAGG,aAAa,UAAU,UAAU;;wBAOjC,OAAO,cAAc,gBAAgB;;wBAOrC,QAAQ,cAAc,eAAe;;qBAMxC,WAAY,gBAAgB;;qBAG5B,YAAa;;wBAGV,WAAW,cAAc;;;;;;wBASzB,WAAW;;wBA2BX,UAAU;;wBAUV,OAAO,cAAc;;qBAOxB,UAAW,aAAa;;;;;wBAMrB,aAAa,SAAS,KAAK,oDAAoD;;UC9K9E;;WAEN;;WAEA;;WAEA;;WAEA,SAAS;;;UAIH;;WAEN;;WAEA,OAAO,SAAS,eAAe;;;wBAW1B,eAAe,MAAM,OAAO;;;;;;;wBAU5B,YAAY,gBAAgB,gBAAgB,SAAS;;qBCnCxD;qBA2FA,WAAW;qBC/FX,eAAe;;qBCYf;;qBAGA,wBAAwB;qBAOxB,cAAc;;wBCnBX,eAAe;;;;;wBAaf,SAAS,cAAc;qBAqB1B,eAAe;qBCEf,cAAc;qBCrBd,iBAAiB;;wBCqCd,cAAc;qBAajB,eAAe;;wBChEZ,QAAQ;;wBAQR,aAAa;qBAKhB,YAAY;qBCVZ,eAAe;;wBCHZ,SAAS,0BAA0B;qBAKtC,cAAc;;wBC4CX,gBAAgB;;;;;wBA4BhB,UAAU,SAAS,SAAS,0BAA0B,cAAc,OAAM;qBA+C7E,YAAY;qBChGZ,cAAc;qBC9Bd,mBAAmB;;qBCWnB,gBAAgB;;UCPZ;WACN;WACA;WACA;;WAEA;WACA,iBAAiB;;WAEjB;;WAEA;;;UAIM;WACN,gBAAgB;;WAEhB;;;UAIM;;WAEN;;WAEA;;WAEA;WACA,MAAM,SAAS;;WAEf,iBAAiB;;;wBAaZ,WAAW,cAAc,iBAAgB,SAAiB;;wBAO1D,cAAc,cAAc,QAAQ,mBAAmB,UAAS,KAAK,gCAAqC;;wBAwB1G,UAAU,SAAS,eAAe;;wBA0ClC,aAAa,QAAQ;;wBA0BrB,gBAAgB,QAAQ;;wBAsBxB,YAAY,QAAQ;;wBAYpB,UAAU,QAAQ,+BAA+B,iBAAgB;;UAkBhE;WACN;WACA,KAAK,SAAS;WACd,SAAS;WACT,SAAS;;;qBAIP;;wBAwBG,OAAO,yBAAyB,IAAI;;;;;;wBCxNpC,aAAa,eAAe;;;;;wBA+C5B,YAAY,cAAc;;;;;;wBA8B1B,eAAe;;;;;;;wBAwCf,eAAe,cAAc"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/rule.ts","../src/config.ts","../src/rules/cue-preset.ts","../src/rules/no-build-output.ts","../src/rules/no-local-paths.ts","../src/rules/pinned-git-deps.ts","../src/rules/release-files.ts","../src/rules/required-scripts.ts","../src/rules/roadmap-parses.ts","../src/rules/runner-budget.ts","../src/rules/source-main.ts","../src/rules/tests-required.ts","../src/rules/tsconfig-test.ts","../src/rules/typed-files.ts","../src/rules/typed-scripts.ts","../src/rules/workspace-protocol.ts","../src/rules/index.ts","../src/run.ts","../src/workspace.ts"],"mappings":";UASiB;WACN;WACA;WACA;;;UAIM;;WAEN;;WAEA;WACA;;WAEA;;;KAIC;;KAGA,UAAU,SAAS,eAAe;;UAG7B;WACN;WACA,SAAS;WACT;;;KAIC,WAAW,SAAS;;UAGf;;WAEN;;WAEA;;WAEA;;WAEA;WACA,UAAU;;;UAIJ;;WAEN;;WAEA,aAAa;;WAEb,mBAAmB;;WAEnB,KAAK,SAAS;;WAEd;;EAET;;EAEA,IAAI;;;KAIM,uBAAuB;WAAqB;;;UAGvC;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA,kBAAkB;;WAElB,SAAS,SAAS,eAAe;EAC1C,MAAM,SAAS,aAAa,SAAS,UAAU;;;qBAIpC;;wBAGG,aAAa,UAAU,UAAU;;wBAOjC,OAAO,cAAc,gBAAgB;;wBAOrC,QAAQ,cAAc,eAAe;;qBAMxC,WAAY,gBAAgB;;qBAG5B,YAAa;;wBAGV,WAAW,cAAc;;;;;;wBASzB,WAAW;;wBA2BX,UAAU;;wBAUV,OAAO,cAAc;;qBAOxB,UAAW,aAAa;;;;;wBAMrB,aAAa,SAAS,KAAK,oDAAoD;;UC9K9E;;WAEN;;WAEA;;WAEA;;WAEA,SAAS;;;UAIH;;WAEN;;WAEA,OAAO,SAAS,eAAe;;;wBAW1B,eAAe,MAAM,OAAO;;;;;;;wBAU5B,YAAY,gBAAgB,gBAAgB,SAAS;;qBCnCxD;qBA2FA,WAAW;qBC/FX,eAAe;;qBCYf;;qBAGA,wBAAwB;qBAOxB,cAAc;;wBCnBX,eAAe;;;;;wBAaf,SAAS,cAAc;qBAqB1B,eAAe;qBCEf,cAAc;qBCrBd,iBAAiB;;wBCqCd,cAAc;qBAajB,eAAe;;;;;;wBCnBZ,eAAe,oBAAoB;;wBAUnC,mBAAmB;qBA4HtB,cAAc;;wBCnLX,QAAQ;;wBAQR,aAAa;qBAKhB,YAAY;qBCVZ,eAAe;;wBCQZ,SAAS,0BAA0B;qBAKtC,cAAc;;wBCiCX,gBAAgB;;;;;wBA4BhB,UAAU,SAAS,SAAS,0BAA0B,cAAc,OAAM;qBA+C7E,YAAY;qBChGZ,cAAc;qBC9Bd,mBAAmB;;qBCYnB,gBAAgB;;UCRZ;WACN;WACA;WACA;;WAEA;WACA,iBAAiB;;WAEjB;;WAEA;;;UAIM;WACN,gBAAgB;;WAEhB;;;UAIM;;WAEN;;WAEA;;WAEA;WACA,MAAM,SAAS;;WAEf,iBAAiB;;;wBAaZ,WAAW,cAAc,iBAAgB,SAAiB;;wBAO1D,cAAc,cAAc,QAAQ,mBAAmB,UAAS,KAAK,gCAAqC;;wBAwB1G,UAAU,SAAS,eAAe;;wBA0ClC,aAAa,QAAQ;;wBA0BrB,gBAAgB,QAAQ;;wBAsBxB,YAAY,QAAQ;;wBAYpB,UAAU,QAAQ,+BAA+B,iBAAgB;;UAkBhE;WACN;WACA,KAAK,SAAS;WACd,SAAS;WACT,SAAS;;;qBAIP;;wBAwBG,OAAO,yBAAyB,IAAI;;;;;;wBCxNpC,aAAa,eAAe;;;;;wBAsD5B,YAAY,cAAc;;;;;;wBA8B1B,eAAe;;;;;;;wBAwCf,eAAe,cAAc"}
package/build/index.js CHANGED
@@ -1 +1 @@
1
- export { k as DEFAULT_ALLOWED, F as DEPENDENCY_FIELDS, A as HOME_PATTERNS, u as RULES, N as STRICT_OPTIONS, t as USAGE, n as annotations, I as cleanPath, L as codePackages, p as configsOfScript, r as createContext, P as cuePreset, Z as defaultOptions, i as formatResult, q as globFolders, J as globToRegExp, R as hasFile, g as hasTests, z as inFolder, E as isGitSpecifier, D as isPinned, y as isSourcePath, B as keyLine, V as lineOf, a as listRules, H as matchesAny, M as noBuildOutput, j as noLocalPaths, Y as packageFolders, Q as parseConfig, U as parseJsonc, b as pathsOf, O as pinnedGitDeps, o as readConfig, W as readJsonc, T as releaseFiles, w as requiredScripts, S as roadmapOfLine, C as roadmapParses, s as runChecks, c as runCli, G as runGit, m as scriptsOf, x as sourceMain, K as specifiersOf, l as summaryMarkdown, v as testsRequired, _ as tsconfigTest, h as typedFiles, f as typedScripts, X as workspaceGlobs, d as workspaceProtocol } from "./run-MyvUGD5l.js";
1
+ export { M as DEFAULT_ALLOWED, R as DEPENDENCY_FIELDS, N as HOME_PATTERNS, u as RULES, I as STRICT_OPTIONS, t as USAGE, n as annotations, z as cleanPath, B as codePackages, p as configsOfScript, r as createContext, L as cuePreset, et as defaultOptions, i as formatResult, X as globFolders, Z as globToRegExp, V as hasFile, g as hasTests, H as inFolder, k as isGitSpecifier, A as isPinned, y as isSourcePath, U as keyLine, W as lineOf, a as listRules, G as matchesAny, F as noBuildOutput, P as noLocalPaths, Q as packageFolders, tt as parseConfig, K as parseJsonc, b as pathsOf, j as pinnedGitDeps, o as readConfig, q as readJsonc, O as releaseFiles, S as repositoryOfRemote, D as requiredScripts, T as roadmapOfLine, E as roadmapParses, s as runChecks, c as runCli, J as runGit, C as runnerBudget, w as scheduleMinute, m as scriptsOf, x as sourceMain, Y as specifiersOf, l as summaryMarkdown, v as testsRequired, _ as tsconfigTest, h as typedFiles, f as typedScripts, $ as workspaceGlobs, d as workspaceProtocol } from "./run-B7ftggFF.js";
@@ -130,12 +130,18 @@ function globToRegExp(glob) {
130
130
  }
131
131
  /** The characters that make a path segment a pattern. */
132
132
  const GLOB_CHARS = /[*?{]/;
133
+ /** This function removes the `/` characters at the end of a path, with a loop in place of a regular expression. */
134
+ function trimEndSlashes(path) {
135
+ let end = path.length;
136
+ while (end > 0 && path.charAt(end - 1) === "/") end -= 1;
137
+ return path.slice(0, end);
138
+ }
133
139
  /**
134
140
  * This function gives the folders under `root` that a glob names, as `/` paths relative to `root`,
135
141
  * in the order of the code units. It does not go into `node_modules` or a folder that starts with `.`.
136
142
  */
137
143
  function globFolders(root, glob) {
138
- const clean = glob.replace(/^\.\//, "").replace(/\/+$/, "");
144
+ const clean = trimEndSlashes(glob.startsWith("./") ? glob.slice(2) : glob);
139
145
  const segments = clean.split("/");
140
146
  const firstPattern = segments.findIndex((segment) => GLOB_CHARS.test(segment));
141
147
  if (firstPattern < 0) return existsSync(join(root, clean)) ? [clean] : [];
@@ -1611,7 +1617,7 @@ if (board) {
1611
1617
  * The rule `roadmap-parses`: each roadmap that a workflow gives to the Status page parses, on the pull request.
1612
1618
  */
1613
1619
  /** A workflow file. */
1614
- const WORKFLOW = /^\.github\/workflows\/[^/]+\.ya?ml$/;
1620
+ const WORKFLOW$1 = /^\.github\/workflows\/[^/]+\.ya?ml$/;
1615
1621
  /** This function tells if a line calls the Pages workflow of the template (`uses: ...reusable-pages.yml`). */
1616
1622
  function callsPages(line) {
1617
1623
  let text = line.trimStart();
@@ -1620,7 +1626,7 @@ function callsPages(line) {
1620
1626
  const value = text.slice(5).trim();
1621
1627
  return /(?:^|\/)reusable-pages\.ya?ml(?:@|$|\s)/.test(value);
1622
1628
  }
1623
- const indentOf = (line) => line.length - line.trimStart().length;
1629
+ const indentOf$1 = (line) => line.length - line.trimStart().length;
1624
1630
  /** This function tells if a line is `site-pages: false`: the site has no Status page. */
1625
1631
  function noStatusPage(line) {
1626
1632
  const text = line.trimStart();
@@ -1642,8 +1648,8 @@ function callsWithoutRoadmap(lines) {
1642
1648
  const found = [];
1643
1649
  lines.forEach((line, index) => {
1644
1650
  if (!callsPages(line)) return;
1645
- const indent = indentOf(line);
1646
- const inJob = (text) => text.trim() === "" || indentOf(text) >= indent;
1651
+ const indent = indentOf$1(line);
1652
+ const inJob = (text) => text.trim() === "" || indentOf$1(text) >= indent;
1647
1653
  let first = index;
1648
1654
  while (first > 0 && inJob(lines[first - 1] ?? "")) first -= 1;
1649
1655
  let last = index;
@@ -1685,7 +1691,7 @@ const roadmapParses = {
1685
1691
  if (files === void 0) return { skipped: "the root is not in a git repository" };
1686
1692
  const named = [];
1687
1693
  const breaks = [];
1688
- for (const file of files.filter((path) => WORKFLOW.test(path)).sort(byCode)) {
1694
+ for (const file of files.filter((path) => WORKFLOW$1.test(path)).sort(byCode)) {
1689
1695
  const lines = readFileSync(join(context.root, file), "utf8").split(/\r?\n/);
1690
1696
  lines.forEach((line, index) => {
1691
1697
  const roadmap = roadmapOfLine(line);
@@ -1735,6 +1741,251 @@ const roadmapParses = {
1735
1741
  return breaks;
1736
1742
  }
1737
1743
  };
1744
+ // src/rules/runner-budget.ts
1745
+ /**
1746
+ * The rule `runner-budget`: the workflows share the runners of the account. Each matrix has a `max-parallel`, each
1747
+ * workflow has a concurrency group, and each schedule starts at the minute of its repository and file.
1748
+ */
1749
+ /** A workflow file. */
1750
+ const WORKFLOW = /^\.github\/workflows\/[^/]+\.ya?ml$/;
1751
+ const indentOf = (line) => line.length - line.trimStart().length;
1752
+ /** This function removes a comment at the end of a value, and the quotes around it. */
1753
+ function valueOf(raw) {
1754
+ const comment = raw.indexOf(" #");
1755
+ let value = (comment >= 0 ? raw.slice(0, comment) : raw).trim();
1756
+ const quote = value.charAt(0);
1757
+ if (value.length >= 2 && (quote === "\"" || quote === "'") && value.endsWith(quote)) value = value.slice(1, -1).trim();
1758
+ return value;
1759
+ }
1760
+ /** This function gives the value of the key `key` on a line, or undefined when the line has another key. */
1761
+ function keyValue(line, key) {
1762
+ let text = line.trimStart();
1763
+ if (text.startsWith("- ")) text = text.slice(2).trimStart();
1764
+ if (!text.startsWith(`${key}:`)) return void 0;
1765
+ return valueOf(text.slice(key.length + 1));
1766
+ }
1767
+ /** This function gives the lines of the block under the line `index`: the next lines with a larger indent. */
1768
+ function blockEnd(lines, index) {
1769
+ const indent = indentOf(lines[index] ?? "");
1770
+ let end = index + 1;
1771
+ while (end < lines.length) {
1772
+ const line = lines[end] ?? "";
1773
+ if (line.trim() !== "" && indentOf(line) <= indent) break;
1774
+ end += 1;
1775
+ }
1776
+ return end;
1777
+ }
1778
+ /** This function gives the indent of the first key of the block under the line `index`, or undefined for an empty block. */
1779
+ function childIndent(lines, index) {
1780
+ const end = blockEnd(lines, index);
1781
+ for (let i = index + 1; i < end; i++) if ((lines[i] ?? "").trim() !== "") return indentOf(lines[i] ?? "");
1782
+ }
1783
+ /**
1784
+ * This function gives the minute (1 to 59) of the schedules of a workflow: the FNV-1a hash of the repository and the
1785
+ * file. Two repositories with the same workflow thus start at different minutes, and no schedule starts at minute 0,
1786
+ * where GitHub has the most load.
1787
+ */
1788
+ function scheduleMinute(repository, file) {
1789
+ let hash = 2166136261;
1790
+ for (const char of `${repository.toLowerCase()}/${file}`) {
1791
+ hash ^= char.codePointAt(0) ?? 0;
1792
+ hash = Math.imul(hash, 16777619) >>> 0;
1793
+ }
1794
+ return hash % 59 + 1;
1795
+ }
1796
+ /** This function gives `owner/name` from a git remote URL, or undefined for a URL that is not of GitHub. */
1797
+ function repositoryOfRemote(url) {
1798
+ const text = url.trim();
1799
+ for (const prefix of [
1800
+ "git@github.com:",
1801
+ "ssh://git@github.com/",
1802
+ "https://github.com/",
1803
+ "http://github.com/",
1804
+ "git+https://github.com/"
1805
+ ]) {
1806
+ if (!text.startsWith(prefix)) continue;
1807
+ let rest = text.slice(prefix.length);
1808
+ if (rest.endsWith("/")) rest = rest.slice(0, -1);
1809
+ if (rest.endsWith(".git")) rest = rest.slice(0, -4);
1810
+ const parts = rest.split("/");
1811
+ return parts.length === 2 && parts.every((part) => part !== "") ? rest : void 0;
1812
+ }
1813
+ }
1814
+ /** This function tells if a workflow is a shared workflow (`on: workflow_call`). Its caller gives the concurrency group. */
1815
+ function isShared(lines) {
1816
+ return lines.some((line) => {
1817
+ const text = line.trimStart();
1818
+ return text.startsWith("workflow_call:") || text === "workflow_call" || text === "- workflow_call" || text.startsWith("on:") && text.includes("workflow_call");
1819
+ });
1820
+ }
1821
+ /** This function gives the jobs of a workflow. */
1822
+ function jobsOf(lines) {
1823
+ const jobs = lines.findIndex((line) => indentOf(line) === 0 && line.startsWith("jobs:"));
1824
+ if (jobs < 0) return [];
1825
+ const jobIndent = childIndent(lines, jobs);
1826
+ const end = blockEnd(lines, jobs);
1827
+ const found = [];
1828
+ for (let i = jobs + 1; i < end; i++) {
1829
+ const line = lines[i] ?? "";
1830
+ if (line.trim() === "" || indentOf(line) !== jobIndent) continue;
1831
+ const keyIndent = childIndent(lines, i);
1832
+ const keys = lines.slice(i + 1, blockEnd(lines, i)).filter((text) => indentOf(text) === keyIndent);
1833
+ const uses = keys.map((text) => keyValue(text, "uses")).find((value) => value !== void 0);
1834
+ const at = uses === void 0 ? -1 : uses.indexOf(".github/workflows/");
1835
+ const calls = uses === void 0 || at < 0 ? void 0 : uses.slice(at + 18).split("@")[0] ?? "";
1836
+ found.push({
1837
+ name: line.trim().replace(/:$/, ""),
1838
+ line: i + 1,
1839
+ grouped: keys.some((text) => keyValue(text, "concurrency") !== void 0),
1840
+ ...calls === void 0 ? {} : { calls }
1841
+ });
1842
+ }
1843
+ return found;
1844
+ }
1845
+ const hasTopGroup = (lines) => lines.some((line) => indentOf(line) === 0 && line.startsWith("concurrency:"));
1846
+ /**
1847
+ * This function gives the breaks of the concurrency groups. A workflow with no group at the top needs one in each job.
1848
+ * A job that calls a shared workflow of `grouped` gets its group from the jobs of that workflow. A shared workflow gets
1849
+ * its group from its caller, but a shared workflow of `grouped` has a group in each job.
1850
+ */
1851
+ function concurrencyBreaks(file, lines, grouped) {
1852
+ const name = file.slice(file.lastIndexOf("/") + 1);
1853
+ const jobs = jobsOf(lines);
1854
+ if (isShared(lines)) {
1855
+ if (!grouped.includes(name)) return [];
1856
+ return jobs.filter((job) => !job.grouped).map((job) => ({
1857
+ file,
1858
+ line: job.line,
1859
+ message: `${file}: the job ${job.name} has no concurrency group, and its callers rely on it (the option grouped).`
1860
+ }));
1861
+ }
1862
+ if (hasTopGroup(lines)) return [];
1863
+ return jobs.filter((job) => !job.grouped && !(job.calls !== void 0 && grouped.includes(job.calls))).map((job) => ({
1864
+ file,
1865
+ line: job.line,
1866
+ message: `${file}: the job ${job.name} has no concurrency group, and the workflow has none.`
1867
+ }));
1868
+ }
1869
+ /** This function gives the breaks of the matrices: each `strategy` with a `matrix` has a `max-parallel` of `limit` or less. */
1870
+ function matrixBreaks(file, lines, limit) {
1871
+ const breaks = [];
1872
+ lines.forEach((line, index) => {
1873
+ if (keyValue(line, "strategy") === void 0) return;
1874
+ const keyIndent = childIndent(lines, index);
1875
+ const keys = lines.slice(index + 1, blockEnd(lines, index)).filter((text) => indentOf(text) === keyIndent);
1876
+ if (!keys.some((text) => keyValue(text, "matrix") !== void 0)) return;
1877
+ const raw = keys.map((text) => keyValue(text, "max-parallel")).find((value) => value !== void 0);
1878
+ const value = raw === void 0 ? NaN : Number(raw);
1879
+ if (raw === void 0) breaks.push({
1880
+ file,
1881
+ line: index + 1,
1882
+ message: `${file}: a matrix has no max-parallel.`
1883
+ });
1884
+ else if (!Number.isInteger(value) || value < 1 || value > limit) breaks.push({
1885
+ file,
1886
+ line: index + 1,
1887
+ message: `${file}: a matrix has max-parallel ${raw}, and the most is ${String(limit)}.`
1888
+ });
1889
+ });
1890
+ return breaks;
1891
+ }
1892
+ /**
1893
+ * This function gives the minute field of a schedule that starts `perHour` times in each hour, at equal steps. One start is at
1894
+ * `minute`: `"18"` for 1, `"18,48"` for 2. The list is in the order of the numbers.
1895
+ */
1896
+ function minuteField(minute, perHour) {
1897
+ const step = 60 / perHour;
1898
+ return Array.from({ length: perHour }, (_, k) => (minute + k * step) % 60).sort((a, b) => a - b).join(",");
1899
+ }
1900
+ /** This function gives the number of starts in each hour of a minute field (`"*\/30"` or `"5,35"` give 2), or 1 when it cannot tell. */
1901
+ function startsPerHour(field) {
1902
+ const step = /^\*\/(\d+)$/.exec(field);
1903
+ const count = step ? 60 / Number(step[1]) : field.split(",").length;
1904
+ return Number.isInteger(count) && count >= 1 && 60 % count === 0 ? count : 1;
1905
+ }
1906
+ /**
1907
+ * This function gives the breaks of the schedules: the minute of each `cron` is the minute of the repository and the file. A
1908
+ * schedule that starts more than once in each hour starts at equal steps from that minute (`18,48` for each 30 minutes).
1909
+ */
1910
+ function cronBreaks(file, lines, minute) {
1911
+ const breaks = [];
1912
+ lines.forEach((line, index) => {
1913
+ const value = keyValue(line, "cron");
1914
+ if (value === void 0) return;
1915
+ const fields = value.split(" ").filter((field) => field !== "");
1916
+ const wanted = minuteField(minute, startsPerHour(fields[0] ?? ""));
1917
+ if (fields[0] === wanted) return;
1918
+ const expected = [wanted, ...fields.slice(1)].join(" ");
1919
+ breaks.push({
1920
+ file,
1921
+ line: index + 1,
1922
+ message: `${file}: the schedule "${value}" starts at minute ${fields[0] ?? "?"}, and the minute of this repository and file is ${String(minute)}.`,
1923
+ fix: `cron: "${expected}"`
1924
+ });
1925
+ });
1926
+ return breaks;
1927
+ }
1928
+ const runnerBudget = {
1929
+ id: "runner-budget",
1930
+ title: "Each matrix has a max-parallel of 3 or less, each workflow has a concurrency group, and each schedule starts at the minute that the repository and the file give.",
1931
+ reason: "All repositories of the account share 40 runners, and heavy work keeps at most 28 of them. On 2026-10-30, a matrix with no max-parallel and the sync pull requests of about 20 repositories filled 39 of the 40 runners, with 88 jobs in the queue. Each repository copied the weekly scan at `23 5 * * 1`, so all scans started at the same minute. A workflow with no concurrency group starts a new run on each push, and the old runs keep their runners.",
1932
+ fix: "Add `max-parallel: 3` (or less) under `strategy`. Add a concurrency group at the top of the workflow (`concurrency: { group: <name>-${{ github.ref }}, cancel-in-progress: true }`), or in each job. Change the minute of each `cron` to the minute that the message gives; the hour and the days stay.",
1933
+ sources: [{
1934
+ repo: "fleet",
1935
+ rule: "runner-slots",
1936
+ doc: "docs/STRATEGY.md (2026-10-30, the runner slots: a cap of 40, heavy work at most 28)"
1937
+ }],
1938
+ options: {
1939
+ maxParallel: {
1940
+ type: "number",
1941
+ default: 3,
1942
+ description: "The largest max-parallel of a matrix."
1943
+ },
1944
+ minute: {
1945
+ type: "boolean",
1946
+ default: true,
1947
+ description: "When false, the rule does not examine the minute of the schedules."
1948
+ },
1949
+ grouped: {
1950
+ type: "strings",
1951
+ default: ["reusable-ai-review.yml", "reusable-codex-review.yml"],
1952
+ description: "The shared workflows that give a concurrency group in each of their jobs. A job that calls one needs no group of its own."
1953
+ }
1954
+ },
1955
+ check(context, options) {
1956
+ const files = context.gitFiles();
1957
+ if (files === void 0) return { skipped: "the root is not in a git repository" };
1958
+ const workflows = files.filter((path) => WORKFLOW.test(path)).sort(byCode);
1959
+ if (workflows.length === 0) return { skipped: "the repository has no workflow" };
1960
+ const remote = context.git([
1961
+ "remote",
1962
+ "get-url",
1963
+ "origin"
1964
+ ]);
1965
+ const repository = context.env["GITHUB_REPOSITORY"] ?? (remote === void 0 ? void 0 : repositoryOfRemote(remote));
1966
+ const limit = Number(options["maxParallel"]);
1967
+ const grouped = Array.isArray(options["grouped"]) ? options["grouped"] : [];
1968
+ const breaks = [];
1969
+ for (const file of workflows) {
1970
+ let text;
1971
+ try {
1972
+ text = readFileSync(join(context.root, file), "utf8");
1973
+ } catch {
1974
+ continue;
1975
+ }
1976
+ const lines = text.split(/\r?\n/).map((line) => line.trimStart().startsWith("#") ? "" : line);
1977
+ breaks.push(...matrixBreaks(file, lines, limit), ...concurrencyBreaks(file, lines, grouped));
1978
+ if (options["minute"] !== false) {
1979
+ if (lines.some((line) => keyValue(line, "cron") !== void 0) && repository === void 0) breaks.push({
1980
+ file,
1981
+ message: `${file} has a schedule, and the rule cannot find the repository (GITHUB_REPOSITORY, or a GitHub URL of the remote origin).`
1982
+ });
1983
+ else if (repository !== void 0) breaks.push(...cronBreaks(file, lines, scheduleMinute(repository, file)));
1984
+ }
1985
+ }
1986
+ return breaks;
1987
+ }
1988
+ };
1738
1989
  // src/rules/source-main.ts
1739
1990
  /**
1740
1991
  * The rule `source-main`: a workspace package is a source package, and a public package moves its
@@ -1915,12 +2166,26 @@ const testsRequired = {
1915
2166
  * The rule `tsconfig-test`: each TypeScript package has a `tsconfig.test.json`, and its typecheck
1916
2167
  * examines it.
1917
2168
  */
1918
- /** The path of a test file: `*.test.*` or `*.spec.*` of JavaScript or TypeScript, or a file in a folder `__tests__`. */
1919
- const TEST_FILE = /(?:^|\/)(?:[^/]+\.(?:test|spec)\.[cm]?[jt]sx?|__tests__\/.+)$/;
2169
+ /** The ends of the name of a test file: `.test.` or `.spec.`, then an extension of JavaScript or TypeScript. */
2170
+ const TEST_ENDS = ["test", "spec"].flatMap((kind) => [
2171
+ "",
2172
+ "c",
2173
+ "m"
2174
+ ].flatMap((module) => ["j", "t"].flatMap((lang) => ["", "x"].map((jsx) => `.${kind}.${module}${lang}s${jsx}`))));
2175
+ /**
2176
+ * This function tells if a path is a test file: `*.test.*` or `*.spec.*` of JavaScript or TypeScript, or a file in a
2177
+ * folder `__tests__`. It uses string operations, with no regular expression, so a long path takes linear time.
2178
+ */
2179
+ function isTestFile(path) {
2180
+ const segments = path.split("/");
2181
+ const name = segments[segments.length - 1] ?? "";
2182
+ if (name !== "" && segments.slice(0, -1).includes("__tests__")) return true;
2183
+ return TEST_ENDS.some((end) => name.length > end.length && name.endsWith(end));
2184
+ }
1920
2185
  /** This function tells if git tracks a test file in the package folder `folder` (`""` is the root). */
1921
2186
  function hasTests(files, folder) {
1922
2187
  const prefix = folder === "" ? "" : `${folder}/`;
1923
- return files.some((path) => path.startsWith(prefix) && TEST_FILE.test(path.slice(prefix.length)));
2188
+ return files.some((path) => path.startsWith(prefix) && isTestFile(path.slice(prefix.length)));
1924
2189
  }
1925
2190
  const tsconfigTest = {
1926
2191
  id: "tsconfig-test",
@@ -2397,7 +2662,8 @@ const RULES = [
2397
2662
  typedScripts,
2398
2663
  typedFiles,
2399
2664
  testsRequired,
2400
- roadmapParses
2665
+ roadmapParses,
2666
+ runnerBudget
2401
2667
  ];
2402
2668
  // src/run.ts
2403
2669
  /**
@@ -2547,8 +2813,8 @@ function formatResult(result) {
2547
2813
  if (result.failed) out.push("", "To turn a rule off or to keep an exception, add a reason in the field conventions of package.json (`conventions --list`).");
2548
2814
  return `${out.join("\n")}\n`;
2549
2815
  }
2550
- /** This function escapes the text of a cell of a Markdown table. */
2551
- const cell = (text) => text.replace(/\|/g, "\\|").replace(/\r?\n/g, " ");
2816
+ /** This function escapes the text of a cell of a Markdown table: first each backslash, then each `|`. */
2817
+ const cell = (text) => text.replace(/\\/g, "\\\\").replace(/\|/g, "\\|").replace(/\r?\n/g, " ");
2552
2818
  /** This function gives the result as Markdown for the summary of a GitHub Actions run. */
2553
2819
  function summaryMarkdown(result) {
2554
2820
  const out = [
@@ -2687,6 +2953,6 @@ function runCli(args, io) {
2687
2953
  if (summary) appendFileSync(summary, summaryMarkdown(result));
2688
2954
  return result.failed ? 1 : 0;
2689
2955
  }
2690
- export { HOME_PATTERNS as A, keyLine as B, roadmapParses as C, isPinned as D, isGitSpecifier as E, DEPENDENCY_FIELDS as F, runGit as G, matchesAny as H, cleanPath as I, globToRegExp as J, specifiersOf as K, codePackages as L, noBuildOutput as M, STRICT_OPTIONS as N, pinnedGitDeps as O, cuePreset as P, parseConfig as Q, hasFile as R, roadmapOfLine as S, releaseFiles as T, parseJsonc as U, lineOf as V, readJsonc as W, workspaceGlobs as X, packageFolders as Y, defaultOptions as Z, tsconfigTest as _, listRules as a, pathsOf as b, runCli as c, workspaceProtocol as d, typedScripts as f, hasTests as g, typedFiles as h, formatResult as i, noLocalPaths as j, DEFAULT_ALLOWED as k, summaryMarkdown as l, scriptsOf as m, annotations as n, readConfig as o, configsOfScript as p, globFolders as q, createContext as r, runChecks as s, USAGE as t, RULES as u, testsRequired as v, requiredScripts as w, sourceMain as x, isSourcePath as y, inFolder as z };
2956
+ export { workspaceGlobs as $, isPinned as A, codePackages as B, runnerBudget as C, requiredScripts as D, roadmapParses as E, noBuildOutput as F, matchesAny as G, inFolder as H, STRICT_OPTIONS as I, runGit as J, parseJsonc as K, cuePreset as L, DEFAULT_ALLOWED as M, HOME_PATTERNS as N, releaseFiles as O, noLocalPaths as P, packageFolders as Q, DEPENDENCY_FIELDS as R, repositoryOfRemote as S, roadmapOfLine as T, keyLine as U, hasFile as V, lineOf as W, globFolders as X, specifiersOf as Y, globToRegExp as Z, tsconfigTest as _, listRules as a, pathsOf as b, runCli as c, workspaceProtocol as d, defaultOptions as et, typedScripts as f, hasTests as g, typedFiles as h, formatResult as i, pinnedGitDeps as j, isGitSpecifier as k, summaryMarkdown as l, scriptsOf as m, annotations as n, readConfig as o, configsOfScript as p, readJsonc as q, createContext as r, runChecks as s, USAGE as t, parseConfig as tt, RULES as u, testsRequired as v, scheduleMinute as w, sourceMain as x, isSourcePath as y, cleanPath as z };
2691
2957
 
2692
- //# sourceMappingURL=run-MyvUGD5l.js.map
2958
+ //# sourceMappingURL=run-B7ftggFF.js.map