@theholocron/cli 5.3.0 → 5.4.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.mjs CHANGED
@@ -508,17 +508,26 @@ const doctorCiEntry = {
508
508
  name: "doctor ci",
509
509
  description: "Check the repo against the flat task vocabulary: aliases, caller names, the ci aggregate, home (read-only)",
510
510
  positionals: [],
511
- options: [{
512
- key: "shadow",
513
- flag: "--shadow",
514
- type: "confirm",
515
- message: "Also compare Sentinel's shadow aggregate with the Actions one?"
516
- }, {
517
- key: "remote",
518
- flag: "--remote",
519
- type: "confirm",
520
- message: "Also check the hosted files over the network (the ci-v1 tag, what callers name at it, the frozen copies)?"
521
- }],
511
+ options: [
512
+ {
513
+ key: "shadow",
514
+ flag: "--shadow",
515
+ type: "confirm",
516
+ message: "Also compare Sentinel's shadow aggregate with the Actions one?"
517
+ },
518
+ {
519
+ key: "remote",
520
+ flag: "--remote",
521
+ type: "confirm",
522
+ message: "Also check the hosted files over the network (the ci-v1 tag, what callers name at it, the frozen copies)?"
523
+ },
524
+ {
525
+ key: "scan",
526
+ flag: "--scan",
527
+ type: "confirm",
528
+ message: "Also list the org's repositories still calling the frozen .github files (clones every repo)?"
529
+ }
530
+ ],
522
531
  skipOptions: [
523
532
  "all",
524
533
  "repo",
@@ -14458,7 +14467,7 @@ const FROZEN_NOTICE = "DEPRECATED — frozen copy";
14458
14467
  const API = "https://api.github.com";
14459
14468
  const RAW = "https://raw.githubusercontent.com";
14460
14469
  // src/commands/doctor-ci/frozen-row.ts
14461
- const ID$10 = "frozen";
14470
+ const ID$11 = "frozen";
14462
14471
  const TITLE$11 = `the workflows left in ${DOT_GITHUB_REPO} say they are frozen`;
14463
14472
  /**
14464
14473
  * The `frozen` row: every workflow still in `theholocron/.github` carries the deprecation notice, so nobody mistakes a
@@ -14468,7 +14477,7 @@ const TITLE$11 = `the workflows left in ${DOT_GITHUB_REPO} say they are frozen`;
14468
14477
  async function frozenRow(read) {
14469
14478
  const listing = await read(`${API}/repos/${DOT_GITHUB_REPO}/contents/.github/workflows`);
14470
14479
  if (listing.status !== 200) return {
14471
- id: ID$10,
14480
+ id: ID$11,
14472
14481
  title: TITLE$11,
14473
14482
  status: "skip",
14474
14483
  detail: `could not list them (HTTP ${listing.status || "no answer"})`,
@@ -14479,7 +14488,7 @@ async function frozenRow(read) {
14479
14488
  names = JSON.parse(listing.text).map((entry) => entry.name).filter((name) => typeof name === "string" && /\.ya?ml$/.test(name)).sort();
14480
14489
  } catch {
14481
14490
  return {
14482
- id: ID$10,
14491
+ id: ID$11,
14483
14492
  title: TITLE$11,
14484
14493
  status: "skip",
14485
14494
  detail: "the listing was not JSON",
@@ -14492,7 +14501,7 @@ async function frozenRow(read) {
14492
14501
  })));
14493
14502
  const unread = files.find(({ res }) => res.status !== 200);
14494
14503
  if (unread) return {
14495
- id: ID$10,
14504
+ id: ID$11,
14496
14505
  title: TITLE$11,
14497
14506
  status: "skip",
14498
14507
  detail: `could not read ${unread.name} (HTTP ${unread.res.status || "no answer"})`,
@@ -14500,14 +14509,14 @@ async function frozenRow(read) {
14500
14509
  };
14501
14510
  const unmarked = files.filter(({ res }) => !res.text.split("\n", 15).some((line) => line.includes(FROZEN_NOTICE)));
14502
14511
  if (unmarked.length > 0) return {
14503
- id: ID$10,
14512
+ id: ID$11,
14504
14513
  title: TITLE$11,
14505
14514
  status: "fail",
14506
14515
  detail: `${unmarked.length} of ${files.length} carry no notice`,
14507
14516
  problems: unmarked.map(({ name }) => `${name}: no "${FROZEN_NOTICE}" notice`)
14508
14517
  };
14509
14518
  return {
14510
- id: ID$10,
14519
+ id: ID$11,
14511
14520
  title: TITLE$11,
14512
14521
  status: "ok",
14513
14522
  detail: `${files.length} of ${files.length} carry the notice`,
@@ -14532,7 +14541,7 @@ function hostedPaths(workflows) {
14532
14541
  })).sort((a, b) => a.path.localeCompare(b.path));
14533
14542
  }
14534
14543
  // src/commands/doctor-ci/refs-row.ts
14535
- const ID$9 = "refs";
14544
+ const ID$10 = "refs";
14536
14545
  const TITLE$10 = `every ${CI_TAG} reference resolves`;
14537
14546
  /** A workflow file holds itself at its path; an action is a folder with an `action.yml` (or `.yaml`) in it. */
14538
14547
  async function resolves(read, path) {
@@ -14549,7 +14558,7 @@ async function resolves(read, path) {
14549
14558
  async function refsRow(workflows, read) {
14550
14559
  const paths = hostedPaths(workflows);
14551
14560
  if (paths.length === 0) return {
14552
- id: ID$9,
14561
+ id: ID$10,
14553
14562
  title: TITLE$10,
14554
14563
  status: "skip",
14555
14564
  detail: `no workflow names a file at ${CI_TAG}`,
@@ -14563,7 +14572,7 @@ async function refsRow(workflows, read) {
14563
14572
  if (unread.length > 0) {
14564
14573
  const first = unread[0];
14565
14574
  return {
14566
- id: ID$9,
14575
+ id: ID$10,
14567
14576
  title: TITLE$10,
14568
14577
  status: "skip",
14569
14578
  detail: `could not read ${first.hosted.path} (HTTP ${first.status || "no answer"})`,
@@ -14572,14 +14581,14 @@ async function refsRow(workflows, read) {
14572
14581
  }
14573
14582
  const missing = answers.filter(({ status }) => status === 404);
14574
14583
  if (missing.length > 0) return {
14575
- id: ID$9,
14584
+ id: ID$10,
14576
14585
  title: TITLE$10,
14577
14586
  status: "fail",
14578
14587
  detail: `${missing.length} of ${paths.length} missing at ${CI_TAG}`,
14579
14588
  problems: missing.map(({ hosted }) => `${hosted.path}: not at ${CI_TAG} (named by ${hosted.files.join(", ")})`)
14580
14589
  };
14581
14590
  return {
14582
- id: ID$9,
14591
+ id: ID$10,
14583
14592
  title: TITLE$10,
14584
14593
  status: "ok",
14585
14594
  detail: `${paths.length} found at ${CI_TAG}`,
@@ -14587,7 +14596,7 @@ async function refsRow(workflows, read) {
14587
14596
  };
14588
14597
  }
14589
14598
  // src/commands/doctor-ci/tag-row.ts
14590
- const ID$8 = "tag";
14599
+ const ID$9 = "tag";
14591
14600
  const TITLE$9 = `${CI_TAG} exists in ${HOLOCRON_REPO}`;
14592
14601
  /** The `tag` row: the tag every caller pins the hosted files to exists. A read that fails or is rate limited is a skip, not a fail. */
14593
14602
  async function tagRow(read) {
@@ -14595,7 +14604,7 @@ async function tagRow(read) {
14595
14604
  if (res.status === 200) {
14596
14605
  const sha = /"sha"\s*:\s*"([0-9a-f]{7,40})"/.exec(res.text)?.[1];
14597
14606
  return {
14598
- id: ID$8,
14607
+ id: ID$9,
14599
14608
  title: TITLE$9,
14600
14609
  status: "ok",
14601
14610
  detail: sha ? `at ${sha.slice(0, 9)}` : "found",
@@ -14603,14 +14612,14 @@ async function tagRow(read) {
14603
14612
  };
14604
14613
  }
14605
14614
  if (res.status === 404) return {
14606
- id: ID$8,
14615
+ id: ID$9,
14607
14616
  title: TITLE$9,
14608
14617
  status: "fail",
14609
14618
  detail: "no such tag",
14610
14619
  problems: [`${HOLOCRON_REPO} has no ${CI_TAG} tag, so every caller that pins it fails to resolve`]
14611
14620
  };
14612
14621
  return {
14613
- id: ID$8,
14622
+ id: ID$9,
14614
14623
  title: TITLE$9,
14615
14624
  status: "skip",
14616
14625
  detail: `could not read the tag (HTTP ${res.status || "no answer"})`,
@@ -14626,6 +14635,273 @@ async function remoteRows(workflows, read) {
14626
14635
  await frozenRow(read)
14627
14636
  ];
14628
14637
  }
14638
+ // src/commands/probe/references/clone-org.ts
14639
+ const SKIP_DIRS$1 = /* @__PURE__ */ new Set([".git", "node_modules"]);
14640
+ const MAX_FILE_BYTES = 5242880;
14641
+ /** How often, and how long apart, removing a clone is tried again when something is still writing into it. */
14642
+ const REMOVE_RETRIES = 10;
14643
+ const REMOVE_RETRY_DELAY_MS = 200;
14644
+ /**
14645
+ * The arguments of `gh repo clone` for `org/name` into `dest`: a shallow, quiet clone that runs none of the user's git
14646
+ * hooks. The probe only reads, and a global hook (`core.hooksPath`, `init.templateDir`) such as a `post-checkout` that
14647
+ * starts `ctags` in the background writes `.git/tags` after the clone has returned, which made removing the clone fail
14648
+ * with `ENOTEMPTY` (#2913). `-c` takes effect before the files are checked out.
14649
+ */
14650
+ function cloneArgs(org, name, dest) {
14651
+ return [
14652
+ "repo",
14653
+ "clone",
14654
+ `${org}/${name}`,
14655
+ dest,
14656
+ "--",
14657
+ "--depth",
14658
+ "1",
14659
+ "--quiet",
14660
+ "-c",
14661
+ "core.hooksPath=/dev/null"
14662
+ ];
14663
+ }
14664
+ /**
14665
+ * Removes a scratch directory, trying again when something still writes into it. A process the clone left running can
14666
+ * recreate a file while the directory is being deleted; `rmSync` retries `ENOTEMPTY` (and `EBUSY`, `EPERM`) itself.
14667
+ */
14668
+ function removeScratch(path, remove = rmSync) {
14669
+ remove(path, {
14670
+ recursive: true,
14671
+ force: true,
14672
+ maxRetries: REMOVE_RETRIES,
14673
+ retryDelay: REMOVE_RETRY_DELAY_MS
14674
+ });
14675
+ }
14676
+ /** Every text file under `dir`: not in `.git` or `node_modules`, under 5 MiB, and without a NUL in its first KiB. */
14677
+ function* textFiles(dir, root = dir) {
14678
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
14679
+ if (SKIP_DIRS$1.has(entry.name)) continue;
14680
+ const path = join(dir, entry.name);
14681
+ if (entry.isDirectory()) yield* textFiles(path, root);
14682
+ else if (entry.isFile() && statSync(path).size < MAX_FILE_BYTES) {
14683
+ const buffer = readFileSync(path);
14684
+ if (!buffer.subarray(0, 1024).includes(0)) yield {
14685
+ path: relative(root, path),
14686
+ text: buffer.toString("utf8")
14687
+ };
14688
+ }
14689
+ }
14690
+ }
14691
+ /**
14692
+ * Shallow-clones the default branch of each active (not archived) repository of `org` with `gh`, one at a time, and
14693
+ * removes every clone when the scan ends. Cloning, rather than GitHub code search, because search skips repositories
14694
+ * that are not indexed and gives no guarantee of completeness.
14695
+ */
14696
+ function cloneOrg(org) {
14697
+ return JSON.parse(execFileSync("gh", [
14698
+ "repo",
14699
+ "list",
14700
+ org,
14701
+ "--limit",
14702
+ "200",
14703
+ "--json",
14704
+ "name,isArchived,isTemplate"
14705
+ ], { encoding: "utf8" })).filter((repo) => !repo.isArchived).sort((a, b) => a.name.localeCompare(b.name)).map((repo) => ({
14706
+ name: repo.name,
14707
+ isTemplate: repo.isTemplate,
14708
+ files() {
14709
+ const scratch = mkdtempSync(join(tmpdir(), "refs-"));
14710
+ const dest = join(scratch, repo.name);
14711
+ execFileSync("gh", cloneArgs(org, repo.name, dest), { stdio: "pipe" });
14712
+ try {
14713
+ return [...textFiles(dest)];
14714
+ } finally {
14715
+ removeScratch(scratch);
14716
+ }
14717
+ }
14718
+ }));
14719
+ /* v8 ignore stop */
14720
+ }
14721
+ // src/commands/probe/references/find-references.ts
14722
+ const CALL = /^-?\s*uses:\s/;
14723
+ /** The repository that hosts the files; its own references are the starters and shims, not callers. */
14724
+ const HOST_REPO = ".github";
14725
+ /** What a reference points at, from the text after the needle. */
14726
+ function kindOf$1(line, needle) {
14727
+ const rest = line.slice(line.indexOf(needle) + needle.length);
14728
+ if (rest.startsWith("workflows/")) return "workflow";
14729
+ if (rest.startsWith("actions/")) return "action";
14730
+ return "other";
14731
+ }
14732
+ /** Every line of every file of `repo` that contains `needle`. */
14733
+ function findReferences(repo, needle) {
14734
+ const found = [];
14735
+ for (const file of repo.files()) file.text.split("\n").forEach((line, index) => {
14736
+ if (!line.includes(needle)) return;
14737
+ found.push({
14738
+ repo: repo.name,
14739
+ file: file.path,
14740
+ line: index + 1,
14741
+ kind: kindOf$1(line, needle),
14742
+ text: line.trim()
14743
+ });
14744
+ });
14745
+ return found;
14746
+ }
14747
+ /**
14748
+ * Whether a reference is a live call: a `uses:` line in a YAML file, which is what GitHub reads. Tests, docs and specs
14749
+ * name the path on purpose (the legacy-path detection, a test that nothing spells it, a record of the move), so they are
14750
+ * references to list but not calls to wait on.
14751
+ */
14752
+ function isCall(ref) {
14753
+ return /\.ya?ml$/.test(ref.file) && CALL.test(ref.text);
14754
+ }
14755
+ // src/commands/probe/references/references-probes.ts
14756
+ function scan(repos, needle) {
14757
+ return {
14758
+ repos,
14759
+ found: repos.flatMap((repo) => findReferences(repo, needle))
14760
+ };
14761
+ }
14762
+ function summarise$2(ctx, repos, found, needle, max) {
14763
+ ctx.say({
14764
+ status: "heading",
14765
+ label: `References to ${needle}`
14766
+ });
14767
+ for (const repo of repos) {
14768
+ const own = found.filter((ref) => ref.repo === repo.name);
14769
+ const files = new Set(own.map((ref) => ref.file)).size;
14770
+ const count = (kind) => own.filter((ref) => ref.kind === kind).length;
14771
+ ctx.say({
14772
+ status: "info",
14773
+ label: repo.name === ".github" ? `${repo.name} (host)` : repo.name,
14774
+ detail: `${files} files: ${count("workflow")} workflow, ${count("action")} action, ${count("other")} other; ${own.filter(isCall).length} live calls`
14775
+ });
14776
+ }
14777
+ const outside = found.filter((ref) => ref.repo !== HOST_REPO);
14778
+ const calls = outside.filter(isCall).length;
14779
+ const inside = found.length - outside.length;
14780
+ const detail = `${outside.length} references in all (tests, docs and specs may name the path on purpose), ${inside} more inside ${HOST_REPO}`;
14781
+ if (calls > max) ctx.say({
14782
+ status: "fail",
14783
+ label: `${calls} live calls outside ${HOST_REPO}`,
14784
+ detail: `more than the ${max} allowed; ${detail}`
14785
+ });
14786
+ else ctx.say({
14787
+ status: "ok",
14788
+ label: `${calls} live calls outside ${HOST_REPO}`,
14789
+ detail
14790
+ });
14791
+ }
14792
+ /**
14793
+ * `ci refs` counts the references to the reusable workflows and composite actions hosted in `<org>/.github` across
14794
+ * every active repository of the org. It is the exit test for removing the forwarding shims there: they can go when
14795
+ * no live call outside `.github` is left (a `uses:` line in a YAML file; see {@link isCall}). It fails above `<max>`,
14796
+ * which defaults to 0, so the exit code is the test (#2915). `ci ref-list` prints each reference with its file and line.
14797
+ */
14798
+ function ciProbes(org, clone = cloneOrg) {
14799
+ const needle = (name) => `${name}/.github/.github/`;
14800
+ const read = (ctx) => {
14801
+ if (!org) {
14802
+ ctx.say({
14803
+ status: "fail",
14804
+ label: "no org",
14805
+ detail: "the config has no org to scan"
14806
+ });
14807
+ return null;
14808
+ }
14809
+ return {
14810
+ org,
14811
+ ...scan(clone(org), needle(org))
14812
+ };
14813
+ };
14814
+ return {
14815
+ refs: {
14816
+ 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).",
14817
+ writes: false,
14818
+ async run(ctx) {
14819
+ const result = read(ctx);
14820
+ if (!result) return;
14821
+ const max = ctx.args?.[0] === void 0 ? 0 : Number(ctx.args[0]);
14822
+ if (!Number.isInteger(max) || max < 0) {
14823
+ ctx.say({
14824
+ status: "fail",
14825
+ label: `\`${ctx.args[0]}\` is not a number`,
14826
+ detail: "usage: ci refs [max]"
14827
+ });
14828
+ return;
14829
+ }
14830
+ summarise$2(ctx, result.repos, result.found, needle(result.org), max);
14831
+ }
14832
+ },
14833
+ "ref-list": {
14834
+ summary: "List every reference to the org's .github workflows and actions, with file and line.",
14835
+ writes: false,
14836
+ async run(ctx) {
14837
+ const result = read(ctx);
14838
+ if (!result) return;
14839
+ for (const ref of result.found) ctx.say({
14840
+ status: "info",
14841
+ label: `${ref.repo}:${ref.file}:${ref.line}`,
14842
+ detail: `${ref.kind}: ${ref.text}`
14843
+ });
14844
+ ctx.say({
14845
+ status: "ok",
14846
+ label: `${result.found.length} references`
14847
+ });
14848
+ }
14849
+ }
14850
+ };
14851
+ }
14852
+ // src/commands/doctor-ci/repos-row.ts
14853
+ const ID$8 = "repos";
14854
+ /**
14855
+ * The `repos` row (`doctor ci --scan`): which repositories of the org still call the frozen workflows and actions in
14856
+ * `<org>/.github` (a live `uses:` line, the same count `holocron probe ci refs` makes). Each is named with how many
14857
+ * calls it has. It clones every active repository, so it is never part of `doctor --all`. With no org, or a scan that
14858
+ * cannot run (no `gh`, no network), the row is a skip, never a failure.
14859
+ */
14860
+ function reposRow(org, clone = cloneOrg) {
14861
+ const title = `no repository of ${org ?? "the org"} still calls the frozen ${HOST_REPO} files`;
14862
+ if (!org) return {
14863
+ id: ID$8,
14864
+ title,
14865
+ status: "skip",
14866
+ detail: "the config has no org to scan",
14867
+ problems: []
14868
+ };
14869
+ let repos;
14870
+ let calls;
14871
+ try {
14872
+ repos = clone(org);
14873
+ const needle = `${org}/${HOST_REPO}/.github/`;
14874
+ calls = /* @__PURE__ */ new Map();
14875
+ for (const repo of repos) {
14876
+ if (repo.name === ".github") continue;
14877
+ const live = findReferences(repo, needle).filter(isCall).length;
14878
+ if (live > 0) calls.set(repo.name, live);
14879
+ }
14880
+ } catch (err) {
14881
+ const reason = err instanceof Error ? err.message.split("\n")[0] : "unknown error";
14882
+ return {
14883
+ id: ID$8,
14884
+ title,
14885
+ status: "skip",
14886
+ detail: `could not scan the org (${reason})`,
14887
+ problems: []
14888
+ };
14889
+ }
14890
+ if (calls.size === 0) return {
14891
+ id: ID$8,
14892
+ title,
14893
+ status: "ok",
14894
+ detail: `${repos.length} repositories scanned`,
14895
+ problems: []
14896
+ };
14897
+ return {
14898
+ id: ID$8,
14899
+ title,
14900
+ status: "fail",
14901
+ detail: `${calls.size} of ${repos.length} repositories`,
14902
+ problems: [...calls].map(([name, count]) => `${name}: ${count} live call${count === 1 ? "" : "s"}`)
14903
+ };
14904
+ }
14629
14905
  // src/commands/doctor-ci/shadow-verdict.ts
14630
14906
  /**
14631
14907
  * The verdict of the newest run named `name` among a commit's check runs: still running is `pending`, a completed
@@ -14787,6 +15063,7 @@ async function runDoctorCi(input) {
14787
15063
  aggregateRow(callers, aggregateChecks(tasksConfig).expected, aggregatePoster(tasksConfig)),
14788
15064
  homeRow(callers),
14789
15065
  ...input.remote ? await remoteRows(io.workflows(), input.fetchText ?? fetchText) : [],
15066
+ ...input.scan ? [reposRow(input.context.org ?? config.org, input.scanRepos)] : [],
14790
15067
  ...input.shadow ? await shadowRows(input) : []
14791
15068
  ];
14792
15069
  printCheckRows(rows, print);
@@ -14813,6 +15090,9 @@ const doctorCiCommand = {
14813
15090
  }).option("remote", {
14814
15091
  type: "boolean",
14815
15092
  describe: "Also check the hosted files over the network: the ci-v1 tag, every file and action the workflows name at it, and the frozen copies in theholocron/.github (public URLs, no token)"
15093
+ }).option("scan", {
15094
+ type: "boolean",
15095
+ describe: "Also list the org's repositories that still call the frozen theholocron/.github files (clones every repository with gh; not part of doctor --all)"
14816
15096
  }).option("limit", {
14817
15097
  type: "number",
14818
15098
  describe: "With --shadow: how many of the newest pull requests to read (default 40)"
@@ -14827,10 +15107,11 @@ const doctorCiCommand = {
14827
15107
  context: {
14828
15108
  repoRoot: argv.cwd,
14829
15109
  ...tokens,
14830
- ...argv.shadow ? { org: resolveOrg(argv, loaded.resolved) } : {}
15110
+ ...argv.shadow || argv.scan ? { org: resolveOrg(argv, loaded.resolved) } : {}
14831
15111
  },
14832
15112
  ...argv.shadow ? { shadow: true } : {},
14833
15113
  ...argv.remote ? { remote: true } : {},
15114
+ ...argv.scan ? { scan: true } : {},
14834
15115
  ...argv.limit !== void 0 ? { shadowLimit: Number(argv.limit) } : {}
14835
15116
  })).status === "fail") process.exitCode = 1;
14836
15117
  }
@@ -24061,7 +24342,10 @@ const DEEP_CHECKS = [
24061
24342
  capability: "source",
24062
24343
  command: doctorCiCommand,
24063
24344
  async run(input) {
24064
- const report = await runDoctorCi(input);
24345
+ const report = await runDoctorCi({
24346
+ ...input,
24347
+ remote: true
24348
+ });
24065
24349
  return {
24066
24350
  status: report.status,
24067
24351
  summary: report.summary
@@ -30402,7 +30686,7 @@ async function runSecretsSync(input) {
30402
30686
  environment: input.environmentId,
30403
30687
  reason: logReason(err)
30404
30688
  }, "sync secrets: vault read failed");
30405
- return summarise$2([{
30689
+ return summarise$1([{
30406
30690
  destination: `vault:${vault.providerName}`,
30407
30691
  scope: `environment=${input.environmentId}`,
30408
30692
  key: "(all)",
@@ -30519,7 +30803,7 @@ async function runSecretsSync(input) {
30519
30803
  }
30520
30804
  }
30521
30805
  }
30522
- return summarise$2(rows, logger, print, dryRun);
30806
+ return summarise$1(rows, logger, print, dryRun);
30523
30807
  }
30524
30808
  /**
30525
30809
  * Record the vault keys a deployment or Worker filter left out: one skipped row each (names only; the value is never
@@ -30557,7 +30841,7 @@ async function readAccess(secrets, scope, print) {
30557
30841
  }
30558
30842
  }
30559
30843
  /** Log every row, then print and log the summary. Shared by a finished run and one that stopped at the vault. */
30560
- function summarise$2(rows, logger, print, dryRun) {
30844
+ function summarise$1(rows, logger, print, dryRun) {
30561
30845
  for (const r of rows) logger[r.status === "fail" ? "warn" : "info"]({
30562
30846
  destination: r.destination,
30563
30847
  scope: r.scope,
@@ -34284,13 +34568,13 @@ function generateHolocronConfig(opts) {
34284
34568
  lines.push(``);
34285
34569
  return lines.join("\n");
34286
34570
  }
34287
- const SKIP_DIRS$1 = [
34571
+ const SKIP_DIRS = [
34288
34572
  ".git",
34289
34573
  "node_modules",
34290
34574
  "dist",
34291
34575
  ".turbo"
34292
34576
  ];
34293
- const defaultWalkFiles = (dir) => walkFilesSync(dir, { skip: SKIP_DIRS$1 });
34577
+ const defaultWalkFiles = (dir) => walkFilesSync(dir, { skip: SKIP_DIRS });
34294
34578
  function isBinary(content) {
34295
34579
  for (let i = 0; i < Math.min(content.length, 8e3); i++) if (content.charCodeAt(i) === 0) return true;
34296
34580
  return false;
@@ -35792,13 +36076,13 @@ function planDeps(root) {
35792
36076
  };
35793
36077
  }
35794
36078
  // src/commands/probe/deps/report-deps.ts
35795
- const kindOf$1 = (section) => section === "peerDependencies" ? "peer" : section === "devDependencies" ? "dev" : "prod";
36079
+ const kindOf = (section) => section === "peerDependencies" ? "peer" : section === "devDependencies" ? "dev" : "prod";
35796
36080
  /** Every package that uses a dependency, with how. */
35797
36081
  function usersOf(row) {
35798
36082
  const byPkg = /* @__PURE__ */ new Map();
35799
36083
  for (const e of row.edges) {
35800
36084
  const kinds = byPkg.get(e.pkg) ?? /* @__PURE__ */ new Set();
35801
- kinds.add(kindOf$1(e.section));
36085
+ kinds.add(kindOf(e.section));
35802
36086
  byPkg.set(e.pkg, kinds);
35803
36087
  }
35804
36088
  return [...byPkg.entries()].map(([pkg, kinds]) => ({
@@ -35819,7 +36103,7 @@ function detail(p, filter) {
35819
36103
  for (const e of r.edges) {
35820
36104
  const entry = byGroup.get(e.group) ?? /* @__PURE__ */ new Map();
35821
36105
  const kinds = entry.get(e.pkg) ?? /* @__PURE__ */ new Set();
35822
- kinds.add(kindOf$1(e.section));
36106
+ kinds.add(kindOf(e.section));
35823
36107
  entry.set(e.pkg, kinds);
35824
36108
  byGroup.set(e.group, entry);
35825
36109
  }
@@ -36613,7 +36897,7 @@ function writeLcov(ctx, repoRoot, packages) {
36613
36897
  function percent(documented, total) {
36614
36898
  return `${total === 0 ? 100 : Math.round(100 * documented / total)}%`;
36615
36899
  }
36616
- function summarise$1(ctx, packages) {
36900
+ function summarise(ctx, packages) {
36617
36901
  let total = 0;
36618
36902
  let documented = 0;
36619
36903
  ctx.say({
@@ -36665,7 +36949,7 @@ function docsCoverageProbes(repoRoot, typedoc = runTypedoc(repoRoot), diff = rea
36665
36949
  async run(ctx) {
36666
36950
  const packages = measure();
36667
36951
  writeLcov(ctx, repoRoot, packages);
36668
- summarise$1(ctx, packages);
36952
+ summarise(ctx, packages);
36669
36953
  }
36670
36954
  },
36671
36955
  patch: {
@@ -36732,7 +37016,7 @@ function docsCoverageProbes(repoRoot, typedoc = runTypedoc(repoRoot), diff = rea
36732
37016
  mkdirSync(dirname(file), { recursive: true });
36733
37017
  writeFileSync(file, toLcov(packages));
36734
37018
  });
36735
- summarise$1(ctx, packages);
37019
+ summarise(ctx, packages);
36736
37020
  }
36737
37021
  }
36738
37022
  };
@@ -37002,220 +37286,6 @@ function listProbes(groups) {
37002
37286
  }
37003
37287
  return lines;
37004
37288
  }
37005
- // src/commands/probe/references/clone-org.ts
37006
- const SKIP_DIRS = /* @__PURE__ */ new Set([".git", "node_modules"]);
37007
- const MAX_FILE_BYTES = 5242880;
37008
- /** How often, and how long apart, removing a clone is tried again when something is still writing into it. */
37009
- const REMOVE_RETRIES = 10;
37010
- const REMOVE_RETRY_DELAY_MS = 200;
37011
- /**
37012
- * The arguments of `gh repo clone` for `org/name` into `dest`: a shallow, quiet clone that runs none of the user's git
37013
- * hooks. The probe only reads, and a global hook (`core.hooksPath`, `init.templateDir`) such as a `post-checkout` that
37014
- * starts `ctags` in the background writes `.git/tags` after the clone has returned, which made removing the clone fail
37015
- * with `ENOTEMPTY` (#2913). `-c` takes effect before the files are checked out.
37016
- */
37017
- function cloneArgs(org, name, dest) {
37018
- return [
37019
- "repo",
37020
- "clone",
37021
- `${org}/${name}`,
37022
- dest,
37023
- "--",
37024
- "--depth",
37025
- "1",
37026
- "--quiet",
37027
- "-c",
37028
- "core.hooksPath=/dev/null"
37029
- ];
37030
- }
37031
- /**
37032
- * Removes a scratch directory, trying again when something still writes into it. A process the clone left running can
37033
- * recreate a file while the directory is being deleted; `rmSync` retries `ENOTEMPTY` (and `EBUSY`, `EPERM`) itself.
37034
- */
37035
- function removeScratch(path, remove = rmSync) {
37036
- remove(path, {
37037
- recursive: true,
37038
- force: true,
37039
- maxRetries: REMOVE_RETRIES,
37040
- retryDelay: REMOVE_RETRY_DELAY_MS
37041
- });
37042
- }
37043
- /** Every text file under `dir`: not in `.git` or `node_modules`, under 5 MiB, and without a NUL in its first KiB. */
37044
- function* textFiles(dir, root = dir) {
37045
- for (const entry of readdirSync(dir, { withFileTypes: true })) {
37046
- if (SKIP_DIRS.has(entry.name)) continue;
37047
- const path = join(dir, entry.name);
37048
- if (entry.isDirectory()) yield* textFiles(path, root);
37049
- else if (entry.isFile() && statSync(path).size < MAX_FILE_BYTES) {
37050
- const buffer = readFileSync(path);
37051
- if (!buffer.subarray(0, 1024).includes(0)) yield {
37052
- path: relative(root, path),
37053
- text: buffer.toString("utf8")
37054
- };
37055
- }
37056
- }
37057
- }
37058
- /**
37059
- * Shallow-clones the default branch of each active (not archived) repository of `org` with `gh`, one at a time, and
37060
- * removes every clone when the scan ends. Cloning, rather than GitHub code search, because search skips repositories
37061
- * that are not indexed and gives no guarantee of completeness.
37062
- */
37063
- function cloneOrg(org) {
37064
- return JSON.parse(execFileSync("gh", [
37065
- "repo",
37066
- "list",
37067
- org,
37068
- "--limit",
37069
- "200",
37070
- "--json",
37071
- "name,isArchived,isTemplate"
37072
- ], { encoding: "utf8" })).filter((repo) => !repo.isArchived).sort((a, b) => a.name.localeCompare(b.name)).map((repo) => ({
37073
- name: repo.name,
37074
- isTemplate: repo.isTemplate,
37075
- files() {
37076
- const scratch = mkdtempSync(join(tmpdir(), "refs-"));
37077
- const dest = join(scratch, repo.name);
37078
- execFileSync("gh", cloneArgs(org, repo.name, dest), { stdio: "pipe" });
37079
- try {
37080
- return [...textFiles(dest)];
37081
- } finally {
37082
- removeScratch(scratch);
37083
- }
37084
- }
37085
- }));
37086
- /* v8 ignore stop */
37087
- }
37088
- // src/commands/probe/references/find-references.ts
37089
- const CALL = /^-?\s*uses:\s/;
37090
- /** The repository that hosts the files; its own references are the starters and shims, not callers. */
37091
- const HOST_REPO = ".github";
37092
- /** What a reference points at, from the text after the needle. */
37093
- function kindOf(line, needle) {
37094
- const rest = line.slice(line.indexOf(needle) + needle.length);
37095
- if (rest.startsWith("workflows/")) return "workflow";
37096
- if (rest.startsWith("actions/")) return "action";
37097
- return "other";
37098
- }
37099
- /** Every line of every file of `repo` that contains `needle`. */
37100
- function findReferences(repo, needle) {
37101
- const found = [];
37102
- for (const file of repo.files()) file.text.split("\n").forEach((line, index) => {
37103
- if (!line.includes(needle)) return;
37104
- found.push({
37105
- repo: repo.name,
37106
- file: file.path,
37107
- line: index + 1,
37108
- kind: kindOf(line, needle),
37109
- text: line.trim()
37110
- });
37111
- });
37112
- return found;
37113
- }
37114
- /**
37115
- * Whether a reference is a live call: a `uses:` line in a YAML file, which is what GitHub reads. Tests, docs and specs
37116
- * name the path on purpose (the legacy-path detection, a test that nothing spells it, a record of the move), so they are
37117
- * references to list but not calls to wait on.
37118
- */
37119
- function isCall(ref) {
37120
- return /\.ya?ml$/.test(ref.file) && CALL.test(ref.text);
37121
- }
37122
- // src/commands/probe/references/references-probes.ts
37123
- function scan(repos, needle) {
37124
- return {
37125
- repos,
37126
- found: repos.flatMap((repo) => findReferences(repo, needle))
37127
- };
37128
- }
37129
- function summarise(ctx, repos, found, needle, max) {
37130
- ctx.say({
37131
- status: "heading",
37132
- label: `References to ${needle}`
37133
- });
37134
- for (const repo of repos) {
37135
- const own = found.filter((ref) => ref.repo === repo.name);
37136
- const files = new Set(own.map((ref) => ref.file)).size;
37137
- const count = (kind) => own.filter((ref) => ref.kind === kind).length;
37138
- ctx.say({
37139
- status: "info",
37140
- label: repo.name === ".github" ? `${repo.name} (host)` : repo.name,
37141
- detail: `${files} files: ${count("workflow")} workflow, ${count("action")} action, ${count("other")} other; ${own.filter(isCall).length} live calls`
37142
- });
37143
- }
37144
- const outside = found.filter((ref) => ref.repo !== HOST_REPO);
37145
- const calls = outside.filter(isCall).length;
37146
- const inside = found.length - outside.length;
37147
- const detail = `${outside.length} references in all (tests, docs and specs may name the path on purpose), ${inside} more inside ${HOST_REPO}`;
37148
- if (calls > max) ctx.say({
37149
- status: "fail",
37150
- label: `${calls} live calls outside ${HOST_REPO}`,
37151
- detail: `more than the ${max} allowed; ${detail}`
37152
- });
37153
- else ctx.say({
37154
- status: "ok",
37155
- label: `${calls} live calls outside ${HOST_REPO}`,
37156
- detail
37157
- });
37158
- }
37159
- /**
37160
- * `ci refs` counts the references to the reusable workflows and composite actions hosted in `<org>/.github` across
37161
- * every active repository of the org. It is the exit test for removing the forwarding shims there: they can go when
37162
- * no live call outside `.github` is left (a `uses:` line in a YAML file; see {@link isCall}). It fails above `<max>`,
37163
- * which defaults to 0, so the exit code is the test (#2915). `ci ref-list` prints each reference with its file and line.
37164
- */
37165
- function ciProbes(org, clone = cloneOrg) {
37166
- const needle = (name) => `${name}/.github/.github/`;
37167
- const read = (ctx) => {
37168
- if (!org) {
37169
- ctx.say({
37170
- status: "fail",
37171
- label: "no org",
37172
- detail: "the config has no org to scan"
37173
- });
37174
- return null;
37175
- }
37176
- return {
37177
- org,
37178
- ...scan(clone(org), needle(org))
37179
- };
37180
- };
37181
- return {
37182
- refs: {
37183
- 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).",
37184
- writes: false,
37185
- async run(ctx) {
37186
- const result = read(ctx);
37187
- if (!result) return;
37188
- const max = ctx.args?.[0] === void 0 ? 0 : Number(ctx.args[0]);
37189
- if (!Number.isInteger(max) || max < 0) {
37190
- ctx.say({
37191
- status: "fail",
37192
- label: `\`${ctx.args[0]}\` is not a number`,
37193
- detail: "usage: ci refs [max]"
37194
- });
37195
- return;
37196
- }
37197
- summarise(ctx, result.repos, result.found, needle(result.org), max);
37198
- }
37199
- },
37200
- "ref-list": {
37201
- summary: "List every reference to the org's .github workflows and actions, with file and line.",
37202
- writes: false,
37203
- async run(ctx) {
37204
- const result = read(ctx);
37205
- if (!result) return;
37206
- for (const ref of result.found) ctx.say({
37207
- status: "info",
37208
- label: `${ref.repo}:${ref.file}:${ref.line}`,
37209
- detail: `${ref.kind}: ${ref.text}`
37210
- });
37211
- ctx.say({
37212
- status: "ok",
37213
- label: `${result.found.length} references`
37214
- });
37215
- }
37216
- }
37217
- };
37218
- }
37219
37289
  // src/commands/probe/specs/real-specs-io.ts
37220
37290
  /** The `specs check` probe's inputs from the real filesystem under `repoRoot`. */
37221
37291
  function realSpecsIo(repoRoot) {