@theholocron/cli 5.0.0-alpha.261 → 5.0.0-alpha.263

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
@@ -111,13 +111,13 @@ Every command is tagged with how much of a repo it needs:
111
111
  | ------------ | -------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
112
112
  | `global` | the CLI binary alone | `version`, `clone`, `new repo` / `plugin`, `repo upgrade …`, `auth set` / `check`, `package …`, `run lint commit-msg`, `skills …` |
113
113
  | `repo-aware` | `./holocron.config`, walking up from cwd, no plugins | `run`, `run ci`, `config show`, `repo sync readme`, `deploy on-release` |
114
- | `workspace` | the `@theholocron/holocron-plugin-*` packages resolvable | `doctor`, `repo setup`, `repo sync`, `secrets …`, `deploy`, `sync github` |
114
+ | `workspace` | the `@theholocron/holocron-plugin-*` packages resolvable | `doctor`, `repo setup`, `repo sync`, `repo cleanup branches`, `secrets …`, `deploy`, `sync github` |
115
115
 
116
116
  A `workspace` command run from a bare global install (no plugins next to the
117
117
  CLI) fails with one actionable line — install the plugins as devDependencies or
118
118
  use `pnpm exec holocron <cmd>`. `auth check` degrades to "token present,
119
119
  verification skipped" instead. `holocron --help` prints the grouping; see
120
- [Execution Contexts](https://theholocron.github.io/holocron/execution-contexts).
120
+ [Execution Contexts](https://docs.theholocron.dev/holocron/execution-contexts).
121
121
 
122
122
  ### Viewing the resolved config
123
123
 
@@ -589,6 +589,16 @@ Provider credentials for Discord: `discord.holonet` is the **bot token** (Bot
589
589
 
590
590
  See the [command pages](https://theholocron.dev/holocron/commands/notifications-setup/) for each command's options.
591
591
 
592
+ ## Cleaning up
593
+
594
+ - **`holocron repo cleanup branches [--local | --remote]`** — lists the branches whose pull request is merged,
595
+ grouped, each saying whether it lives locally, on the remote or both; then asks, and offers a checklist with the
596
+ proven-merged ones ticked. Proven merged means an ancestor of `origin/alpha` or `origin/main`, or the head (or an
597
+ ancestor, or one of the commits) of a merged pull request. Branches with more commits than their merged PR, with
598
+ an open PR, checked out (here or in a worktree), or never merged are listed unticked. `--dry-run` only lists;
599
+ `--yes` deletes every proven-merged branch without asking. Pull requests and remote branches come from the
600
+ `source` provider (`Source.listPullRequests`, `listPullRequestCommits`, `listBranches`, `deleteBranch`).
601
+
592
602
  ## Upgrading
593
603
 
594
604
  - **`holocron repo upgrade node <to>`** — patches every Node.js version pin
@@ -719,7 +729,7 @@ same paths in `holocron.config`'s `eslint.browserPackages`:
719
729
  ```ts
720
730
  export default defineConfig({
721
731
  eslint: {
722
- browserPackages: ["packages/github-client/src/app-auth"],
732
+ browserPackages: ["clients/github-client/src/app-auth"],
723
733
  },
724
734
  });
725
735
  ```
@@ -757,6 +767,9 @@ the local override exists to exempt.
757
767
  `repo upgrade deps`, `new plugin`, `auth`, `notifications setup`,
758
768
  `notifications channel add`, `notifications link`,
759
769
  `notifications sync-roles`, `doctor notifications`
770
+ - `src/commands/doctor-checks/` and `src/commands/deep-checks/` — the shared row
771
+ renderer and `declaredVsActual` helper, and `DEEP_CHECKS`, the registry every
772
+ `doctor <capability>` is listed in
760
773
  - `src/interactive-menu/` — the interactive fallback: `command-registry`
761
774
  (`COMMAND_REGISTRY`, each entry's `positionals`/`options`), `launch-menu`
762
775
  (Layers 1–2, picks + spawns a fresh `holocron <command>`), `child-argv`
package/dist/cli.mjs CHANGED
@@ -12,7 +12,7 @@ import chalk from "chalk";
12
12
  import search from "@inquirer/search";
13
13
  import { execFileSync, spawn, spawnSync } from "node:child_process";
14
14
  import ora from "ora";
15
- import { checkbox, confirm, input, password, select } from "@inquirer/prompts";
15
+ import { Separator, checkbox, confirm, input, password, select } from "@inquirer/prompts";
16
16
  import { createHash, createHmac, randomBytes, randomUUID } from "node:crypto";
17
17
  import { homedir, hostname, tmpdir, userInfo } from "node:os";
18
18
  import { PostHogSink } from "@theholocron/observability/analytics";
@@ -221,6 +221,7 @@ const COMMAND_CONTEXTS = {
221
221
  "monitoring resolve-checks": "workspace",
222
222
  "monitoring run-resolved": "global",
223
223
  "repo sync": "workspace",
224
+ "repo cleanup branches": "workspace",
224
225
  "sync github": "workspace"
225
226
  };
226
227
  /**
@@ -1683,6 +1684,26 @@ const COMMAND_REGISTRY = [
1683
1684
  positionals: [],
1684
1685
  supportsDryRun: true
1685
1686
  },
1687
+ {
1688
+ name: "repo cleanup branches",
1689
+ description: "List the branches whose pull request is merged and delete the ones you pick",
1690
+ positionals: [],
1691
+ options: [{
1692
+ key: "local",
1693
+ flag: "--local",
1694
+ type: "confirm",
1695
+ default: false,
1696
+ message: "Only the branches in this checkout?"
1697
+ }, {
1698
+ key: "remote",
1699
+ flag: "--remote",
1700
+ type: "confirm",
1701
+ default: false,
1702
+ message: "Only the branches on the remote?"
1703
+ }],
1704
+ skipOptions: ["yes", "repo"],
1705
+ supportsDryRun: false
1706
+ },
1686
1707
  {
1687
1708
  name: "run ci",
1688
1709
  description: "Run the merge-gating checks locally, in CI order — 'will CI pass?'",
@@ -2658,7 +2679,7 @@ var WorkspaceContextError = class extends Error {
2658
2679
  constructor(command, packages) {
2659
2680
  const [first, ...rest] = packages;
2660
2681
  const subject = rest.length > 0 ? `${first} (and ${rest.length} other${rest.length === 1 ? "" : "s"})` : first ?? "its plugins";
2661
- super(`\`${command}\` needs ${subject}, but no plugin package resolves here.\nRun it from a repo that has the \`@theholocron/holocron-plugin-*\` packages as devDependencies, or \`pnpm exec holocron ${command}\`. A global install can't resolve them — see https://theholocron.github.io/holocron/execution-contexts`);
2682
+ super(`\`${command}\` needs ${subject}, but no plugin package resolves here.\nRun it from a repo that has the \`@theholocron/holocron-plugin-*\` packages as devDependencies, or \`pnpm exec holocron ${command}\`. A global install can't resolve them — see https://docs.theholocron.dev/holocron/execution-contexts`);
2662
2683
  this.command = command;
2663
2684
  this.packages = packages;
2664
2685
  }
@@ -3861,6 +3882,21 @@ function logReason(err) {
3861
3882
  const root = err instanceof Error && err.cause !== void 0 ? err.cause : err;
3862
3883
  return errorMessage(root);
3863
3884
  }
3885
+ // src/commands/doctor-checks/print-check-rows.ts
3886
+ /** One row per step, titles padded to the widest, each problem on its own indented line. */
3887
+ function printCheckRows(rows, print) {
3888
+ const width = Math.max(0, ...rows.map((row) => row.title.length));
3889
+ for (const row of rows) {
3890
+ print(statusRow(row.status, [row.title.padEnd(width), row.detail]));
3891
+ for (const problem of row.problems) print(` - ${problem}`);
3892
+ }
3893
+ }
3894
+ // src/commands/doctor-checks/print-check-summary.ts
3895
+ /** A blank line, then the closing `N ok, N fail, N skipped`. */
3896
+ function printCheckSummary(summary, print) {
3897
+ print("");
3898
+ print(style.header(`${summary.ok} ok, ${summary.fail} fail, ${summary.skip} skipped`));
3899
+ }
3864
3900
  // src/commands/notifications-channel-add/avatar.ts
3865
3901
  /**
3866
3902
  * Read a webhook avatar named in a layout: a file path (from the directory the CLI runs in) or an
@@ -4943,8 +4979,11 @@ async function runDoctorNotifications(input) {
4943
4979
  };
4944
4980
  const refuse = (message, reason = message) => {
4945
4981
  print(` ${style.fail(message)}`);
4946
- print("");
4947
- print(style.header("0 ok, 1 fail, 0 skipped"));
4982
+ printCheckSummary({
4983
+ ok: 0,
4984
+ fail: 1,
4985
+ skip: 0
4986
+ }, print);
4948
4987
  logger.warn({ reason }, "doctor notifications");
4949
4988
  return {
4950
4989
  status: "fail",
@@ -5377,49 +5416,74 @@ async function runDoctorNotifications(input) {
5377
5416
  } catch (err) {
5378
5417
  failed("server-owner", OWNER_TITLE, shown(describeProviderError(err)));
5379
5418
  }
5380
- const width = Math.max(...checks.map((c) => c.title.length));
5381
- for (const check of checks) {
5382
- print(statusRow(check.status === "pass" ? "ok" : "fail", [check.title.padEnd(width), check.detail]));
5383
- for (const problem of check.problems) print(` - ${problem}`);
5384
- }
5419
+ printCheckRows(checks.map((check) => ({
5420
+ ...check,
5421
+ status: check.status === "pass" ? "ok" : "fail"
5422
+ })), print);
5385
5423
  if (deliveryNote) {
5386
5424
  print("");
5387
5425
  print(` ${style.skip(`note: ${deliveryNote}`)}`);
5388
5426
  }
5389
5427
  const summary = summarise();
5390
- print("");
5391
- print(style.header(`${summary.pass} ok, ${summary.fail} fail, ${summary.skip} skipped`));
5428
+ printCheckSummary({
5429
+ ok: summary.pass,
5430
+ fail: summary.fail,
5431
+ skip: summary.skip
5432
+ }, print);
5392
5433
  return finish();
5393
5434
  }
5394
- // src/commands/doctor-notifications/doctor-notifications.command.ts
5395
- const doctorNotificationsCommand = {
5396
- command: "notifications",
5397
- describe: "Check the layout against the server and the secrets store, step by step (a full run leaves one test post in the test channel; --built-only posts nothing unless --deliver)",
5398
- builder: doctorNotificationsArgs,
5399
- handler: async (argv) => {
5400
- const tokens = tokenContext(argv.token);
5401
- if (!tokens) return;
5402
- const loaded = await loadConfig(argv.cwd);
5403
- applyResolvedConfig(argv, loaded.resolved);
5404
- if ((await runDoctorNotifications({
5405
- loaded,
5406
- context: {
5407
- repoRoot: argv.cwd,
5408
- ...tokens,
5409
- org: resolveOrg(argv, loaded.resolved)
5435
+ // src/commands/deep-checks/deep-checks.ts
5436
+ /**
5437
+ * Every `doctor <capability>` deep check, in the order `doctor --all` runs them. Adding one is an entry here
5438
+ * plus its `COMMAND_CONTEXTS` and `COMMAND_REGISTRY` entries; `deep-checks.test.ts` fails without them.
5439
+ */
5440
+ const DEEP_CHECKS = [{
5441
+ name: "notifications",
5442
+ capability: "notifications",
5443
+ command: {
5444
+ command: "notifications",
5445
+ describe: "Check the layout against the server and the secrets store, step by step (a full run leaves one test post in the test channel; --built-only posts nothing unless --deliver)",
5446
+ builder: doctorNotificationsArgs,
5447
+ handler: async (argv) => {
5448
+ const tokens = tokenContext(argv.token);
5449
+ if (!tokens) return;
5450
+ const loaded = await loadConfig(argv.cwd);
5451
+ applyResolvedConfig(argv, loaded.resolved);
5452
+ if ((await runDoctorNotifications({
5453
+ loaded,
5454
+ context: {
5455
+ repoRoot: argv.cwd,
5456
+ ...tokens,
5457
+ org: resolveOrg(argv, loaded.resolved)
5458
+ },
5459
+ ...argv.scope ? { scope: parseScope(argv.scope) } : {},
5460
+ ...argv.provider ? { provider: argv.provider } : {},
5461
+ ...argv.builtOnly ? { builtOnly: true } : {},
5462
+ ...argv.deliver ? { deliver: true } : {}
5463
+ })).status === "fail") process.exitCode = 1;
5464
+ }
5465
+ },
5466
+ async run(input) {
5467
+ const report = await runDoctorNotifications(input);
5468
+ return {
5469
+ status: report.status,
5470
+ summary: {
5471
+ ok: report.summary.pass,
5472
+ fail: report.summary.fail,
5473
+ skip: report.summary.skip
5410
5474
  },
5411
- ...argv.scope ? { scope: parseScope(argv.scope) } : {},
5412
- ...argv.provider ? { provider: argv.provider } : {},
5413
- ...argv.builtOnly ? { builtOnly: true } : {},
5414
- ...argv.deliver ? { deliver: true } : {}
5415
- })).status === "fail") process.exitCode = 1;
5475
+ ...report.message ? { reason: report.message } : {}
5476
+ };
5416
5477
  }
5417
- };
5478
+ }];
5418
5479
  // src/commands/doctor/doctor.args.ts
5419
- const doctorArgs = (y) => y.option("repo", {
5420
- type: "string",
5421
- describe: "Repo coords (\"owner/name\"). Defaults to plugin-specific resolution."
5422
- }).command(doctorNotificationsCommand);
5480
+ const doctorArgs = (y) => {
5481
+ const withRepo = y.option("repo", {
5482
+ type: "string",
5483
+ describe: "Repo coords (\"owner/name\"). Defaults to plugin-specific resolution."
5484
+ });
5485
+ return DEEP_CHECKS.reduce((acc, check) => acc.command(check.command), withRepo);
5486
+ };
5423
5487
  // src/commands/doctor/doctor.ts
5424
5488
  /**
5425
5489
  * `holocron doctor` — load the config, instantiate every capability,
@@ -13136,6 +13200,361 @@ const setupCommand = {
13136
13200
  })).summary.fail > 0) process.exitCode = 1;
13137
13201
  }
13138
13202
  };
13203
+ // src/commands/repo-cleanup-branches/classify-branches.ts
13204
+ /** The merged PRs that had this branch as their head, newest first (the order the provider lists them). */
13205
+ function mergedFor(name, closed) {
13206
+ return closed.filter((pr) => pr.merged && pr.branch === name);
13207
+ }
13208
+ /**
13209
+ * Whether a merged PR accounts for a branch's tip: it is the PR's head, an ancestor of it, or (when the head
13210
+ * commit is not in the checkout) one of the PR's own commits. The provider is asked for the commits last, and
13211
+ * only for a branch the cheaper checks did not settle.
13212
+ */
13213
+ async function accounts(pr, tip, input) {
13214
+ if (pr.headSha === void 0) return (await input.pullRequestCommits(pr.number)).includes(tip);
13215
+ if (tip === pr.headSha || input.git.isAncestor(tip, pr.headSha)) return true;
13216
+ return (await input.pullRequestCommits(pr.number)).includes(tip);
13217
+ }
13218
+ async function classifyOne(ref, input) {
13219
+ if (input.git.isMergedIntoBase(ref.sha)) return {
13220
+ ref,
13221
+ group: "merged"
13222
+ };
13223
+ const merged = mergedFor(ref.name, input.closedPullRequests);
13224
+ for (const pr of merged) if (await accounts(pr, ref.sha, input)) return {
13225
+ ref,
13226
+ group: "squash-merged",
13227
+ pr: pr.number
13228
+ };
13229
+ const newest = merged[0];
13230
+ if (newest) return {
13231
+ ref,
13232
+ group: "has-extra",
13233
+ pr: newest.number
13234
+ };
13235
+ return {
13236
+ ref,
13237
+ group: input.closedPullRequests.some((pr) => pr.branch === ref.name) ? "closed-unmerged" : "no-pr"
13238
+ };
13239
+ }
13240
+ /**
13241
+ * Sorts branches, local and remote, into what is proven merged and what is not. A branch is skipped outright
13242
+ * when it is excluded (a base branch, or locally the checked-out one or one a worktree has out) or has an open
13243
+ * PR; the rest are classified by {@link BranchGroup}. Nothing here deletes.
13244
+ */
13245
+ async function classifyBranches(input) {
13246
+ const open = new Set(input.openPullRequests.map((pr) => pr.branch));
13247
+ const classification = {
13248
+ classified: [],
13249
+ skipped: []
13250
+ };
13251
+ for (const ref of input.branches) {
13252
+ const excluded = input.excluded(ref);
13253
+ if (excluded) classification.skipped.push({
13254
+ ref,
13255
+ reason: excluded
13256
+ });
13257
+ else if (open.has(ref.name)) classification.skipped.push({
13258
+ ref,
13259
+ reason: "open-pr"
13260
+ });
13261
+ else classification.classified.push(await classifyOne(ref, input));
13262
+ }
13263
+ return classification;
13264
+ }
13265
+ // src/commands/repo-cleanup-branches/group-branches.ts
13266
+ /**
13267
+ * One row per branch name and group: a branch on both sides that classifies the same on each is one entry
13268
+ * listing both places. A name whose two refs classify differently (the remote moved on) is two entries.
13269
+ * Newest first by local commit date; a remote-only branch has no date and follows, by name.
13270
+ */
13271
+ function groupBranches(classified) {
13272
+ const entries = /* @__PURE__ */ new Map();
13273
+ for (const { ref, group, pr } of classified) {
13274
+ const key = `${group}:${ref.name}`;
13275
+ const entry = entries.get(key) ?? {
13276
+ name: ref.name,
13277
+ group,
13278
+ ...pr === void 0 ? {} : { pr },
13279
+ locations: []
13280
+ };
13281
+ entry.locations.push(ref.where);
13282
+ if (ref.date !== void 0 && (entry.date === void 0 || ref.date > entry.date)) entry.date = ref.date;
13283
+ entries.set(key, entry);
13284
+ }
13285
+ return [...entries.values()].sort((a, b) => (b.date ?? "").localeCompare(a.date ?? "") || a.name.localeCompare(b.name));
13286
+ }
13287
+ // src/commands/repo-cleanup-branches/constants.ts
13288
+ /** The long-lived branches: never deleted, and what a branch must be an ancestor of (as `origin/<name>`) to count as merged. */
13289
+ const BASE_BRANCHES = ["alpha", "main"];
13290
+ // src/commands/repo-cleanup-branches/local-git.ts
13291
+ /** `git` run in `cwd`, no shell: its trimmed stdout and stderr, and whether it exited 0. */
13292
+ function git(cwd, args) {
13293
+ const r = spawnSync("git", args, {
13294
+ cwd,
13295
+ encoding: "utf8"
13296
+ });
13297
+ return {
13298
+ out: (r.stdout ?? "").trim(),
13299
+ ok: r.status === 0,
13300
+ err: (r.stderr ?? "").trim()
13301
+ };
13302
+ }
13303
+ /** {@link LocalGit} over the checkout at `cwd`. */
13304
+ function createLocalGit(cwd) {
13305
+ return {
13306
+ branches() {
13307
+ const { out } = git(cwd, [
13308
+ "for-each-ref",
13309
+ "--format=%(refname:short)%09%(objectname)%09%(committerdate:iso-strict)",
13310
+ "refs/heads"
13311
+ ]);
13312
+ return out.split("\n").filter(Boolean).map((line) => {
13313
+ const [name = "", sha = "", date = ""] = line.split(" ");
13314
+ return {
13315
+ name,
13316
+ sha,
13317
+ date,
13318
+ where: "local"
13319
+ };
13320
+ });
13321
+ },
13322
+ currentBranch() {
13323
+ return git(cwd, [
13324
+ "symbolic-ref",
13325
+ "--quiet",
13326
+ "--short",
13327
+ "HEAD"
13328
+ ]).out || void 0;
13329
+ },
13330
+ worktreeBranches() {
13331
+ return git(cwd, [
13332
+ "worktree",
13333
+ "list",
13334
+ "--porcelain"
13335
+ ]).out.split("\n").filter((line) => line.startsWith("branch refs/heads/")).map((line) => line.slice(18));
13336
+ },
13337
+ isMergedIntoBase(sha) {
13338
+ return BASE_BRANCHES.some((base) => git(cwd, [
13339
+ "merge-base",
13340
+ "--is-ancestor",
13341
+ sha,
13342
+ `origin/${base}`
13343
+ ]).ok);
13344
+ },
13345
+ isAncestor(sha, of) {
13346
+ return git(cwd, [
13347
+ "merge-base",
13348
+ "--is-ancestor",
13349
+ sha,
13350
+ of
13351
+ ]).ok;
13352
+ },
13353
+ deleteBranch(name) {
13354
+ const r = git(cwd, [
13355
+ "branch",
13356
+ "-D",
13357
+ "--",
13358
+ name
13359
+ ]);
13360
+ if (!r.ok) throw new Error(r.err || `git branch -D ${name} failed`);
13361
+ }
13362
+ };
13363
+ }
13364
+ // src/commands/repo-cleanup-branches/run-cleanup-branches.ts
13365
+ const GROUPS = [
13366
+ "merged",
13367
+ "squash-merged",
13368
+ "has-extra",
13369
+ "closed-unmerged",
13370
+ "no-pr"
13371
+ ];
13372
+ /** The two groups that are proven merged: ticked in the checklist, and what `--yes` deletes. */
13373
+ const SAFE = ["merged", "squash-merged"];
13374
+ const GROUP_LABEL = {
13375
+ merged: "merged (an ancestor of a base branch)",
13376
+ "squash-merged": "squash-merged (its PR merged and the branch holds nothing beyond it)",
13377
+ "has-extra": "merged PR, but the branch has more commits",
13378
+ "closed-unmerged": "PR closed without merging",
13379
+ "no-pr": "no PR and not merged"
13380
+ };
13381
+ const SKIP_LABEL = {
13382
+ base: "base branch",
13383
+ current: "checked out",
13384
+ worktree: "checked out in a worktree",
13385
+ "open-pr": "has an open PR"
13386
+ };
13387
+ /** A row's label: the name, where it lives, when it was last committed to (local only) and its PR. */
13388
+ function rowLabel(entry) {
13389
+ const detail = [entry.date?.slice(0, 10), entry.pr === void 0 ? void 0 : `PR #${entry.pr}`].filter(Boolean);
13390
+ return `${entry.name} [${entry.locations.join(", ")}]${detail.length > 0 ? ` ${style.dim(detail.join(" "))}` : ""}`;
13391
+ }
13392
+ /**
13393
+ * Classifies the branches against the provider's pull requests, shows them grouped, and deletes the ones
13394
+ * chosen. With no flag it covers local and remote branches, each row saying where the branch lives.
13395
+ *
13396
+ * - `--dry-run` stops after the list.
13397
+ * - `--yes` deletes every proven-merged branch without asking.
13398
+ * - Otherwise it asks, then offers a checklist of every branch with the proven-merged ones ticked.
13399
+ */
13400
+ async function runCleanupBranches(input) {
13401
+ const print = input.print ?? ((line) => console.log(line));
13402
+ const logger = input.logger ?? getLogger();
13403
+ const scope = input.scope ?? "both";
13404
+ const git = input.git ?? createLocalGit(input.context.repoRoot);
13405
+ // c8 ignore next -- real PluginLoader construction is integration-level; unit tests always supply loader
13406
+ const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
13407
+ await loader.load();
13408
+ assertPluginsResolvable(loader, "repo cleanup branches");
13409
+ if (!loader.has("source")) throw new Error("source capability is not configured — add a source provider to holocron.config.json");
13410
+ const source = loader.get("source");
13411
+ const { listPullRequests, listPullRequestCommits, listBranches, deleteBranch } = source;
13412
+ if (!listPullRequests || !listPullRequestCommits) throw new Error(`${source.providerName} source provider does not support listing pull requests`);
13413
+ if (scope !== "local" && (!listBranches || !deleteBranch)) throw new Error(`${source.providerName} source provider does not support listing and deleting remote branches`);
13414
+ const worktrees = new Set(scope === "remote" ? [] : git.worktreeBranches());
13415
+ const current = scope === "remote" ? void 0 : git.currentBranch();
13416
+ const refs = [];
13417
+ if (scope !== "remote") refs.push(...git.branches());
13418
+ if (scope !== "local") {
13419
+ const remote = await listBranches.call(source, input.repo);
13420
+ refs.push(...remote.map((b) => ({
13421
+ name: b.name,
13422
+ sha: b.sha,
13423
+ where: "remote"
13424
+ })));
13425
+ }
13426
+ const [openPullRequests, closedPullRequests] = await Promise.all([listPullRequests.call(source, "open", input.repo), listPullRequests.call(source, "closed", input.repo)]);
13427
+ const classification = await classifyBranches({
13428
+ branches: refs,
13429
+ git,
13430
+ excluded: (ref) => {
13431
+ if (BASE_BRANCHES.includes(ref.name)) return "base";
13432
+ if (ref.where === "remote") return void 0;
13433
+ if (ref.name === current) return "current";
13434
+ return worktrees.has(ref.name) ? "worktree" : void 0;
13435
+ },
13436
+ openPullRequests,
13437
+ closedPullRequests,
13438
+ pullRequestCommits: (number) => listPullRequestCommits.call(source, number, input.repo)
13439
+ });
13440
+ const entries = groupBranches(classification.classified);
13441
+ const report = {
13442
+ classification,
13443
+ deleted: [],
13444
+ failed: [],
13445
+ status: "ok"
13446
+ };
13447
+ print("");
13448
+ for (const group of GROUPS) {
13449
+ const rows = entries.filter((e) => e.group === group);
13450
+ const line = `${rows.length} ${GROUP_LABEL[group]}`;
13451
+ print(SAFE.includes(group) ? style.success(line) : style.warn(line));
13452
+ for (const row of rows) print(` ${rowLabel(row)}`);
13453
+ }
13454
+ if (classification.skipped.length > 0) {
13455
+ print(style.dim(`${classification.skipped.length} skipped`));
13456
+ for (const { ref, reason } of classification.skipped) print(style.dim(` ${ref.name} [${ref.where}] ${SKIP_LABEL[reason]}`));
13457
+ }
13458
+ print("");
13459
+ const safe = entries.filter((e) => SAFE.includes(e.group));
13460
+ if (input.context.dryRun === true) {
13461
+ print(style.dim(`Dry run: ${safe.length} branches are proven merged. Nothing was deleted.`));
13462
+ logger.info({
13463
+ proven: safe.length,
13464
+ deleted: 0
13465
+ }, "repo cleanup branches: dry run");
13466
+ return report;
13467
+ }
13468
+ if (entries.length === 0) return report;
13469
+ let chosen = safe;
13470
+ if (input.yes !== true) {
13471
+ if (!process.stdin.isTTY) throw new NonInteractiveError("`repo cleanup branches` asks which branches to delete — run it in a terminal, or pass --yes to delete the proven-merged ones, or --dry-run to only list them");
13472
+ if (!await confirm({
13473
+ message: "Choose branches to delete?",
13474
+ default: true
13475
+ })) return report;
13476
+ chosen = (await checkbox({
13477
+ message: "Delete which branches? (the proven-merged ones are ticked)",
13478
+ pageSize: 20,
13479
+ choices: GROUPS.flatMap((group) => {
13480
+ const rows = entries.filter((e) => e.group === group);
13481
+ if (rows.length === 0) return [];
13482
+ return [new Separator(`── ${GROUP_LABEL[group]} (${rows.length})`), ...rows.map((row) => ({
13483
+ name: rowLabel(row),
13484
+ value: entries.indexOf(row),
13485
+ checked: SAFE.includes(group)
13486
+ }))];
13487
+ })
13488
+ })).map((index) => entries[index]);
13489
+ }
13490
+ for (const entry of chosen) for (const where of entry.locations) try {
13491
+ if (where === "local") git.deleteBranch(entry.name);
13492
+ else await deleteBranch.call(source, entry.name, input.repo);
13493
+ report.deleted.push({
13494
+ name: entry.name,
13495
+ where
13496
+ });
13497
+ } catch (err) {
13498
+ report.failed.push({
13499
+ name: entry.name,
13500
+ where,
13501
+ message: errorMessage(err)
13502
+ });
13503
+ }
13504
+ for (const { name, where, message } of report.failed) print(style.fail(`${name} [${where}]: ${message}`));
13505
+ print(`Deleted ${report.deleted.length} of ${report.deleted.length + report.failed.length} branches.`);
13506
+ if (report.failed.length > 0) report.status = "fail";
13507
+ logger.info({
13508
+ deleted: report.deleted.length,
13509
+ failed: report.failed.length
13510
+ }, "repo cleanup branches: done");
13511
+ return report;
13512
+ }
13513
+ // src/commands/repo-cleanup-branches/repo-cleanup-branches.args.ts
13514
+ const repoCleanupBranchesArgs = (y) => y.option("local", {
13515
+ type: "boolean",
13516
+ describe: "Only the branches in this checkout (with neither --local nor --remote: both)"
13517
+ }).option("remote", {
13518
+ type: "boolean",
13519
+ describe: "Only the branches on the remote (with neither --local nor --remote: both)"
13520
+ }).option("yes", {
13521
+ type: "boolean",
13522
+ describe: "Delete every branch proven merged without asking. Without it a checklist asks."
13523
+ }).option("repo", {
13524
+ type: "string",
13525
+ describe: "Repo coords (\"owner/name\") to look branches and pull requests up in. Defaults to plugin-specific resolution."
13526
+ });
13527
+ // src/commands/repo-cleanup-branches/repo-cleanup-branches.command.ts
13528
+ const repoCleanupBranchesCommand = {
13529
+ command: "branches",
13530
+ describe: "List the branches whose pull request is merged and delete the ones you pick (local, remote or both)",
13531
+ builder: repoCleanupBranchesArgs,
13532
+ handler: async (argv) => {
13533
+ const tokens = tokenContext(argv.token);
13534
+ if (!tokens) return;
13535
+ const loaded = await loadConfig(argv.cwd);
13536
+ applyResolvedConfig(argv, loaded.resolved);
13537
+ if ((await runCleanupBranches({
13538
+ loaded,
13539
+ context: {
13540
+ repoRoot: argv.cwd,
13541
+ dryRun: argv.dryRun,
13542
+ ...tokens,
13543
+ org: resolveOrg(argv, loaded.resolved)
13544
+ },
13545
+ scope: argv.local && !argv.remote ? "local" : argv.remote && !argv.local ? "remote" : "both",
13546
+ ...argv.yes ? { yes: true } : {},
13547
+ ...argv.repo ? { repo: argv.repo } : {}
13548
+ })).status === "fail") process.exitCode = 1;
13549
+ }
13550
+ };
13551
+ // src/commands/repo/repo-cleanup.command.ts
13552
+ const repoCleanupCommand = {
13553
+ command: "cleanup",
13554
+ describe: "Clean up what a repo accumulates (merged branches)",
13555
+ builder: (y) => y.command(repoCleanupBranchesCommand).command(groupMenu("repo cleanup")),
13556
+ handler: () => {}
13557
+ };
13139
13558
  // src/commands/sync-readme/generate-readme.ts
13140
13559
  const SCRIPT_ORDER = [
13141
13560
  "build",
@@ -14650,8 +15069,8 @@ const repoUpgradeCommand = {
14650
15069
  // src/commands/repo/repo.command.ts
14651
15070
  const repoCommand = {
14652
15071
  command: "repo",
14653
- describe: "Set up, sync and upgrade the current repo",
14654
- builder: (y) => y.command(setupCommand).command(repoSyncCommand).command(repoUpgradeCommand).command(groupMenu("repo")),
15072
+ describe: "Set up, sync, upgrade and clean up the current repo",
15073
+ builder: (y) => y.command(setupCommand).command(repoSyncCommand).command(repoUpgradeCommand).command(repoCleanupCommand).command(groupMenu("repo")),
14655
15074
  handler: () => {}
14656
15075
  };
14657
15076
  // src/commands/run/run.args.ts
@@ -15768,7 +16187,7 @@ try {
15768
16187
  });
15769
16188
  finishCommand = startCommand(name);
15770
16189
  }).command(cloneCommand).command(doctorCommand).command(skillsCommand).command(runCommand).command(configShowCommand).command(authCommand).command(menuCommand(CLI_VERSION)).command(repoCommand).command(newCommand).command(probeCommand).command(secretsCommand).command(notificationsCommand).command(syncCommand).command(packageCommand).command(deployCommand).command(monitoringCommand).strict().help().epilogue(`Execution contexts:
15771
- global works from a bare 'npm i -g': ${commandsInContext("global").join(", ")}\n repo-aware needs ./holocron.config in cwd: ${commandsInContext("repo-aware").join(", ")}\n workspace also needs the plugin packages: ${commandsInContext("workspace").join(", ")}\n https://theholocron.github.io/holocron/execution-contexts`).fail((msg, err) => {
16190
+ global works from a bare 'npm i -g': ${commandsInContext("global").join(", ")}\n repo-aware needs ./holocron.config in cwd: ${commandsInContext("repo-aware").join(", ")}\n workspace also needs the plugin packages: ${commandsInContext("workspace").join(", ")}\n https://docs.theholocron.dev/holocron/execution-contexts`).fail((msg, err) => {
15772
16191
  if (err instanceof Error && USER_FACING_ERRORS.has(err.name)) {
15773
16192
  captureException(err);
15774
16193
  reportError(err.message);