@theholocron/cli 5.0.0-alpha.274 → 5.0.0-alpha.275

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
@@ -222,6 +222,7 @@ const COMMAND_CONTEXTS = {
222
222
  "doctor notifications": "workspace",
223
223
  "doctor environments": "workspace",
224
224
  "doctor dns": "workspace",
225
+ "doctor repo": "workspace",
225
226
  "doctor secrets": "workspace",
226
227
  "doctor tokens": "workspace",
227
228
  "doctor monitoring": "workspace",
@@ -1459,6 +1460,13 @@ const doctorNotificationsEntry = {
1459
1460
  }],
1460
1461
  supportsDryRun: false
1461
1462
  };
1463
+ // src/commands/doctor-repo/doctor-repo.entry.ts
1464
+ const doctorRepoEntry = {
1465
+ name: "doctor repo",
1466
+ description: "Check the repository settings against the config (read-only): description, topics, labels, teams, protection, security",
1467
+ positionals: [],
1468
+ supportsDryRun: false
1469
+ };
1462
1470
  // src/commands/doctor-secrets/doctor-secrets.entry.ts
1463
1471
  const doctorSecretsEntry = {
1464
1472
  name: "doctor secrets",
@@ -1687,6 +1695,7 @@ const COMMAND_REGISTRY = [
1687
1695
  doctorNotificationsEntry,
1688
1696
  doctorEnvironmentsEntry,
1689
1697
  doctorDnsEntry,
1698
+ doctorRepoEntry,
1690
1699
  doctorSecretsEntry,
1691
1700
  doctorTokensEntry,
1692
1701
  doctorVariablesEntry,
@@ -4624,7 +4633,7 @@ async function runDoctorDns(input) {
4624
4633
  });
4625
4634
  else if (!loader.has("dns")) {
4626
4635
  const why = whyMissing(loader, "dns", "no `dns` provider to check them with");
4627
- for (const zone of zones) rows.push(row$2(zone, "skip", why));
4636
+ for (const zone of zones) rows.push(row$3(zone, "skip", why));
4628
4637
  } else {
4629
4638
  const dns = loader.get("dns");
4630
4639
  for (const zone of zones) rows.push(await checkZone(dns, zone, expected.filter((e) => e.zone === zone).map((e) => e.record)));
@@ -4644,7 +4653,7 @@ async function runDoctorDns(input) {
4644
4653
  ...status === "skip" ? { reason: [...new Set(rows.map((r) => r.detail))].join("; ") } : {}
4645
4654
  };
4646
4655
  }
4647
- function row$2(zone, status, detail, problems = []) {
4656
+ function row$3(zone, status, detail, problems = []) {
4648
4657
  return {
4649
4658
  id: `dns-${zone}`,
4650
4659
  title: `${zone} records exist`,
@@ -4662,9 +4671,9 @@ async function checkZone(dns, zone, wanted) {
4662
4671
  equal: (want, found) => sameContent(want.content, found.content) && (want.proxied !== true || found.proxied === true),
4663
4672
  show: (r) => `${r.content}${r.proxied ? " (proxied)" : ""}`
4664
4673
  });
4665
- return problems.length > 0 ? row$2(zone, "fail", `${problems.length} problem(s)`, problems) : row$2(zone, "ok", `${wanted.length} of ${wanted.length} exist`);
4674
+ return problems.length > 0 ? row$3(zone, "fail", `${problems.length} problem(s)`, problems) : row$3(zone, "ok", `${wanted.length} of ${wanted.length} exist`);
4666
4675
  } catch (err) {
4667
- return err instanceof MissingTokenError ? row$2(zone, "skip", err.message) : row$2(zone, "fail", errorMessage(err));
4676
+ return err instanceof MissingTokenError ? row$3(zone, "skip", err.message) : row$3(zone, "fail", errorMessage(err));
4668
4677
  }
4669
4678
  }
4670
4679
  // src/commands/doctor-dns/doctor-dns.command.ts
@@ -6028,27 +6037,563 @@ async function runDoctorNotifications(input) {
6028
6037
  }, print);
6029
6038
  return finish();
6030
6039
  }
6031
- // src/commands/doctor-notifications/doctor-notifications.command.ts
6032
- const doctorNotificationsCommand = {
6033
- command: "notifications",
6034
- 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)",
6035
- builder: doctorNotificationsArgs,
6040
+ // src/commands/doctor-notifications/doctor-notifications.command.ts
6041
+ const doctorNotificationsCommand = {
6042
+ command: "notifications",
6043
+ 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)",
6044
+ builder: doctorNotificationsArgs,
6045
+ handler: async (argv) => {
6046
+ const tokens = tokenContext(argv.token);
6047
+ if (!tokens) return;
6048
+ const loaded = await loadConfig(argv.cwd);
6049
+ applyResolvedConfig(argv, loaded.resolved);
6050
+ if ((await runDoctorNotifications({
6051
+ loaded,
6052
+ context: {
6053
+ repoRoot: argv.cwd,
6054
+ ...tokens,
6055
+ org: resolveOrg(argv, loaded.resolved)
6056
+ },
6057
+ ...argv.scope ? { scope: parseScope(argv.scope) } : {},
6058
+ ...argv.provider ? { provider: argv.provider } : {},
6059
+ ...argv.builtOnly ? { builtOnly: true } : {},
6060
+ ...argv.deliver ? { deliver: true } : {}
6061
+ })).status === "fail") process.exitCode = 1;
6062
+ }
6063
+ };
6064
+ // src/commands/setup/branch-protection.ts
6065
+ const RULESET_NAME = "holocron-default-branch";
6066
+ function buildClassicProtectionPayload(requiredChecks = []) {
6067
+ return {
6068
+ required_status_checks: requiredChecks.length > 0 ? {
6069
+ strict: false,
6070
+ contexts: requiredChecks
6071
+ } : null,
6072
+ enforce_admins: false,
6073
+ required_pull_request_reviews: {
6074
+ required_approving_review_count: 0,
6075
+ dismiss_stale_reviews: false,
6076
+ require_code_owner_reviews: false
6077
+ },
6078
+ restrictions: null,
6079
+ allow_force_pushes: false,
6080
+ allow_deletions: false
6081
+ };
6082
+ }
6083
+ function buildRulesetPayload(requiredChecks = []) {
6084
+ const rules = [
6085
+ { type: "deletion" },
6086
+ { type: "non_fast_forward" },
6087
+ {
6088
+ type: "pull_request",
6089
+ parameters: {
6090
+ required_approving_review_count: 0,
6091
+ dismiss_stale_reviews_on_push: false,
6092
+ require_code_owner_review: false,
6093
+ require_last_push_approval: false,
6094
+ required_review_thread_resolution: true,
6095
+ require_extra_approval_for_unattributed_changes: false
6096
+ }
6097
+ }
6098
+ ];
6099
+ if (requiredChecks.length > 0) rules.push({
6100
+ type: "required_status_checks",
6101
+ parameters: {
6102
+ required_status_checks: requiredChecks.map((context) => ({ context })),
6103
+ strict_required_status_checks_policy: false
6104
+ }
6105
+ });
6106
+ return {
6107
+ name: RULESET_NAME,
6108
+ target: "branch",
6109
+ enforcement: "active",
6110
+ bypass_actors: [{
6111
+ actor_id: 4,
6112
+ actor_type: "RepositoryRole",
6113
+ bypass_mode: "always"
6114
+ }],
6115
+ conditions: { ref_name: {
6116
+ include: ["~DEFAULT_BRANCH"],
6117
+ exclude: []
6118
+ } },
6119
+ rules
6120
+ };
6121
+ }
6122
+ async function upsertBranchProtection(source, dryRun, requiredChecks) {
6123
+ const step = `upsert ruleset ${RULESET_NAME}`;
6124
+ if (dryRun) return {
6125
+ capability: "source",
6126
+ step,
6127
+ status: "dry-run"
6128
+ };
6129
+ try {
6130
+ const found = (await source.listRulesets()).find((r) => r.name === RULESET_NAME);
6131
+ if (found) {
6132
+ await source.updateRuleset(found.id, buildRulesetPayload(requiredChecks));
6133
+ return {
6134
+ capability: "source",
6135
+ step,
6136
+ status: "ok",
6137
+ message: "updated"
6138
+ };
6139
+ }
6140
+ await source.createRuleset(buildRulesetPayload(requiredChecks));
6141
+ return {
6142
+ capability: "source",
6143
+ step,
6144
+ status: "ok",
6145
+ message: "created"
6146
+ };
6147
+ } catch (err) {
6148
+ if (!(err instanceof ProviderApiError$1) || err.status !== 403) return {
6149
+ capability: "source",
6150
+ step,
6151
+ status: "fail",
6152
+ message: errorMessage(err)
6153
+ };
6154
+ }
6155
+ try {
6156
+ const repo = await source.getRepo();
6157
+ await source.protectBranch(repo.defaultBranch, buildClassicProtectionPayload(requiredChecks));
6158
+ return {
6159
+ capability: "source",
6160
+ step,
6161
+ status: "ok",
6162
+ message: `classic protection on ${repo.defaultBranch}`
6163
+ };
6164
+ } catch (err) {
6165
+ if (err instanceof ProviderApiError$1 && err.status === 403) return {
6166
+ capability: "source",
6167
+ step,
6168
+ status: "skip",
6169
+ message: "branch protection unavailable on private repos without GitHub Pro/Team"
6170
+ };
6171
+ return {
6172
+ capability: "source",
6173
+ step,
6174
+ status: "fail",
6175
+ message: errorMessage(err)
6176
+ };
6177
+ }
6178
+ }
6179
+ // src/commands/setup/labels.ts
6180
+ const CANONICAL_LABELS = [
6181
+ {
6182
+ name: "bug",
6183
+ color: "d73a4a",
6184
+ description: "Something isn't working"
6185
+ },
6186
+ {
6187
+ name: "chore",
6188
+ color: "ededed",
6189
+ description: "Maintenance, no user-facing change"
6190
+ },
6191
+ {
6192
+ name: "ci",
6193
+ color: "0075ca",
6194
+ description: "CI/CD pipeline changes"
6195
+ },
6196
+ {
6197
+ name: "dependencies",
6198
+ color: "0366d6",
6199
+ description: "Dependency update"
6200
+ },
6201
+ {
6202
+ name: "documentation",
6203
+ color: "0075ca",
6204
+ description: "Documentation only"
6205
+ },
6206
+ {
6207
+ name: "duplicate",
6208
+ color: "cfd3d7",
6209
+ description: "Already reported"
6210
+ },
6211
+ {
6212
+ name: "enhancement",
6213
+ color: "a2eeef",
6214
+ description: "New feature or request"
6215
+ },
6216
+ {
6217
+ name: "good first issue",
6218
+ color: "7057ff",
6219
+ description: "Good for newcomers"
6220
+ },
6221
+ {
6222
+ name: "help wanted",
6223
+ color: "008672",
6224
+ description: "Extra attention needed"
6225
+ },
6226
+ {
6227
+ name: "invalid",
6228
+ color: "e4e669",
6229
+ description: "Doesn't seem right"
6230
+ },
6231
+ {
6232
+ name: "performance",
6233
+ color: "fbca04",
6234
+ description: "Performance improvement"
6235
+ },
6236
+ {
6237
+ name: "question",
6238
+ color: "d876e3",
6239
+ description: "Further information requested"
6240
+ },
6241
+ {
6242
+ name: "refactor",
6243
+ color: "cfd3d7",
6244
+ description: "Code restructuring"
6245
+ },
6246
+ {
6247
+ name: "released",
6248
+ color: "ededed",
6249
+ description: "Included in a release"
6250
+ },
6251
+ {
6252
+ name: "test",
6253
+ color: "bfd4f2",
6254
+ description: "Test-related changes"
6255
+ },
6256
+ {
6257
+ name: "triage",
6258
+ color: "e4e669",
6259
+ description: "Needs investigation"
6260
+ },
6261
+ {
6262
+ name: "wontfix",
6263
+ color: "ffffff",
6264
+ description: "Won't be addressed"
6265
+ }
6266
+ ];
6267
+ const STALE_LABELS = [
6268
+ "github_actions",
6269
+ "javascript",
6270
+ "autorelease: pending",
6271
+ "autorelease: tagged",
6272
+ "released on @alpha"
6273
+ ];
6274
+ // src/commands/setup/repo-settings.ts
6275
+ const BALANCED_REPO_SETTINGS = {
6276
+ allow_squash_merge: true,
6277
+ allow_merge_commit: false,
6278
+ allow_rebase_merge: false,
6279
+ allow_auto_merge: true,
6280
+ allow_update_branch: true,
6281
+ delete_branch_on_merge: true,
6282
+ has_issues: true,
6283
+ has_discussions: true,
6284
+ has_projects: true,
6285
+ has_wiki: false
6286
+ };
6287
+ // src/commands/doctor-repo/repo-checks.ts
6288
+ const quote = (value) => JSON.stringify(value);
6289
+ const onOff = (value) => value ? "on" : "off";
6290
+ /**
6291
+ * The groups of repository settings `repo setup` writes through the `source` capability, each only when the config
6292
+ * declares it (labels and security toggles are always written, so they are always checked). Variables, secrets and
6293
+ * environments are separate checks. Pages, `CODEOWNERS` and the generated files are not compared here.
6294
+ */
6295
+ function repoChecks(config, repoRoot) {
6296
+ const repo = config.repo;
6297
+ const preset = repo?.protection && repo.protection !== "none" ? repo.protection : void 0;
6298
+ const checks = [];
6299
+ if (config.description || config.homepage) checks.push({
6300
+ id: "repo-description",
6301
+ title: "description and homepage match",
6302
+ needs: "getRepoInfo",
6303
+ async run(source) {
6304
+ const info = await source.getRepoInfo();
6305
+ const declared = /* @__PURE__ */ new Map();
6306
+ if (config.description) declared.set("description", config.description);
6307
+ if (config.homepage) declared.set("homepage", config.homepage);
6308
+ return {
6309
+ problems: declaredVsActual(declared, /* @__PURE__ */ new Map([["description", info.description ?? ""], ["homepage", info.homepage ?? ""]]), {
6310
+ noun: "repository field",
6311
+ flagExtra: false,
6312
+ show: quote
6313
+ }),
6314
+ checked: declared.size
6315
+ };
6316
+ }
6317
+ });
6318
+ if (repo?.defaultBranch || preset) checks.push({
6319
+ id: "repo-settings",
6320
+ title: "default branch and settings match",
6321
+ needs: "getRepoInfo",
6322
+ async run(source) {
6323
+ const info = await source.getRepoInfo();
6324
+ const declared = new Map(Object.entries(preset ? BALANCED_REPO_SETTINGS : {}));
6325
+ if (repo?.defaultBranch) declared.set("default_branch", repo.defaultBranch);
6326
+ return {
6327
+ problems: declaredVsActual(declared, new Map(Object.entries(info.settings)), {
6328
+ noun: "repository setting",
6329
+ flagExtra: false,
6330
+ show: quote
6331
+ }),
6332
+ checked: declared.size
6333
+ };
6334
+ }
6335
+ });
6336
+ if (repo?.topics && repo.topics.length > 0) {
6337
+ const topics = repo.topics;
6338
+ checks.push({
6339
+ id: "repo-topics",
6340
+ title: "topics match",
6341
+ needs: "getRepoInfo",
6342
+ async run(source) {
6343
+ const info = await source.getRepoInfo();
6344
+ return {
6345
+ problems: declaredVsActual(new Map(topics.map((t) => [t, true])), new Map(info.topics.map((t) => [t, true])), { noun: "topic" }),
6346
+ checked: topics.length
6347
+ };
6348
+ }
6349
+ });
6350
+ }
6351
+ const properties = declaredProperties(config);
6352
+ if (properties.size > 0) checks.push({
6353
+ id: "repo-properties",
6354
+ title: "custom properties match",
6355
+ needs: "getProperties",
6356
+ async run(source) {
6357
+ const found = await source.getProperties();
6358
+ const actual = new Map(Object.entries(found).map(([name, v]) => [name, Array.isArray(v) ? v.join(",") : v]));
6359
+ return {
6360
+ problems: declaredVsActual(properties, actual, {
6361
+ noun: "property",
6362
+ flagExtra: false,
6363
+ show: quote
6364
+ }),
6365
+ checked: properties.size
6366
+ };
6367
+ }
6368
+ });
6369
+ checks.push({
6370
+ id: "repo-labels",
6371
+ title: "labels match",
6372
+ needs: "listLabels",
6373
+ async run(source) {
6374
+ const found = await source.listLabels();
6375
+ const actual = new Map(found.map((l) => [l.name.toLowerCase(), l]));
6376
+ const problems = declaredVsActual(new Map(CANONICAL_LABELS.map((l) => [l.name, l])), actual, {
6377
+ noun: "label",
6378
+ flagExtra: false,
6379
+ equal: (a, b) => a.color === b.color && a.description === b.description,
6380
+ show: (l) => `${l.color} ${quote(l.description)}`
6381
+ });
6382
+ for (const name of STALE_LABELS) if (actual.has(name)) problems.push(`stale label ${name} (repo setup removes it)`);
6383
+ return {
6384
+ problems,
6385
+ checked: CANONICAL_LABELS.length
6386
+ };
6387
+ }
6388
+ });
6389
+ if (repo?.teams && repo.teams.length > 0) {
6390
+ const teams = repo.teams;
6391
+ checks.push({
6392
+ id: "repo-teams",
6393
+ title: "team access matches",
6394
+ needs: "listTeamAccess",
6395
+ async run(source) {
6396
+ const found = await source.listTeamAccess();
6397
+ return {
6398
+ problems: declaredVsActual(new Map(teams.map(teamPermission)), new Map(found.map((t) => [t.slug, t.permission])), {
6399
+ noun: "team",
6400
+ flagExtra: false,
6401
+ show: quote
6402
+ }),
6403
+ checked: teams.length
6404
+ };
6405
+ }
6406
+ });
6407
+ }
6408
+ if (preset) checks.push({
6409
+ id: "repo-protection",
6410
+ title: "branch protection matches",
6411
+ needs: "getRulesetDetail",
6412
+ async run(source) {
6413
+ let rulesets;
6414
+ try {
6415
+ rulesets = await source.listRulesets();
6416
+ } catch (err) {
6417
+ if (err instanceof ProviderApiError$1 && err.status === 403) return { skip: "rulesets are not available on this plan (classic branch protection is not read)" };
6418
+ throw err;
6419
+ }
6420
+ const found = rulesets.find((r) => r.name === RULESET_NAME);
6421
+ if (!found) return {
6422
+ problems: [`missing ruleset ${RULESET_NAME}`],
6423
+ checked: 1
6424
+ };
6425
+ const detail = await source.getRulesetDetail(found.id);
6426
+ const required = preset === "strict" ? strictChecks(config, repoRoot) : [];
6427
+ const rules = [
6428
+ "deletion",
6429
+ "non_fast_forward",
6430
+ "pull_request",
6431
+ ...required.length > 0 ? ["required_status_checks"] : []
6432
+ ];
6433
+ return {
6434
+ problems: [
6435
+ ...declaredVsActual(/* @__PURE__ */ new Map([["enforcement", "active"]]), /* @__PURE__ */ new Map([["enforcement", detail.enforcement]]), {
6436
+ noun: "ruleset",
6437
+ show: quote
6438
+ }),
6439
+ ...declaredVsActual(new Map(rules.map((r) => [r, true])), new Map(detail.ruleTypes.map((r) => [r, true])), { noun: "ruleset rule" }),
6440
+ ...declaredVsActual(new Map(required.map((c) => [c, true])), new Map(detail.requiredChecks.map((c) => [c, true])), { noun: "required check" })
6441
+ ],
6442
+ checked: 1 + rules.length + required.length
6443
+ };
6444
+ }
6445
+ });
6446
+ checks.push({
6447
+ id: "repo-security",
6448
+ title: "security settings match",
6449
+ needs: "getSecurity",
6450
+ async run(source) {
6451
+ const found = await source.getSecurity();
6452
+ const wanted = {
6453
+ vulnerabilityAlerts: true,
6454
+ automatedSecurityFixes: true,
6455
+ secretScanning: true,
6456
+ secretScanningPushProtection: true,
6457
+ privateVulnerabilityReporting: true,
6458
+ codeScanningDefaultSetup: !(config.tasks ?? []).map((e) => typeof e === "string" ? e : e.name).includes("security.codeScanning")
6459
+ };
6460
+ const declared = new Map(Object.entries(wanted).filter(([k]) => k in found));
6461
+ if (declared.size === 0) return { skip: "the provider reported none of the security settings" };
6462
+ return {
6463
+ problems: declaredVsActual(declared, new Map(Object.entries(found)), {
6464
+ noun: "security setting",
6465
+ flagExtra: false,
6466
+ show: onOff
6467
+ }),
6468
+ checked: declared.size
6469
+ };
6470
+ }
6471
+ });
6472
+ return checks;
6473
+ }
6474
+ function teamPermission(entry) {
6475
+ return typeof entry === "string" ? [entry, "push"] : [entry.slug, entry.permission];
6476
+ }
6477
+ /** The custom properties the config declares (and the protection level `repo setup` stamps), as text. */
6478
+ function declaredProperties(config) {
6479
+ const repo = config.repo;
6480
+ const out = /* @__PURE__ */ new Map();
6481
+ if (repo?.protection && repo.protection !== "none") out.set("holocron_branch_protection_level", repo.protection);
6482
+ const manual = repo?.properties ?? {};
6483
+ if (manual.lifecycle) out.set("lifecycle", manual.lifecycle);
6484
+ if (manual.open_source !== void 0) out.set("open_source", String(manual.open_source));
6485
+ if (manual.runtime_environment) out.set("runtime_environment", manual.runtime_environment);
6486
+ if (manual.uses_external_packages !== void 0) out.set("uses_external_packages", String(manual.uses_external_packages));
6487
+ return out;
6488
+ }
6489
+ /** The status checks a `strict` ruleset requires, derived from the task manifest exactly as `repo setup` does. */
6490
+ function strictChecks(config, repoRoot) {
6491
+ const tasksConfig = { tasks: config.tasks };
6492
+ if (config.extraRequiredChecks) tasksConfig.extraRequiredChecks = config.extraRequiredChecks;
6493
+ return ["DCO", ...createAstromech({
6494
+ cwd: repoRoot,
6495
+ config: tasksConfig,
6496
+ logger: getLogger()
6497
+ }).requiredChecks()];
6498
+ }
6499
+ // src/commands/doctor-repo/doctor-repo.ts
6500
+ /**
6501
+ * `holocron doctor repo` — do the repository settings `repo setup` writes match the config?
6502
+ *
6503
+ * Read-only. One row per group `repo setup` manages through the `source` capability, each only when the config
6504
+ * declares it: description and homepage, default branch and merge settings, topics, custom properties, labels, team
6505
+ * access, branch protection and security settings (see {@link repoChecks}). Something that exists but is not declared
6506
+ * is a problem only where `repo setup` would remove it (topics, stale labels, a ruleset's rules). A group that cannot
6507
+ * be read because there is no provider, the provider lacks the read method or the token is missing is a skip with the
6508
+ * reason, not a failure. Variables, secrets and environments have their own checks.
6509
+ */
6510
+ async function runDoctorRepo(input) {
6511
+ const print = input.print ?? ((line) => console.log(line));
6512
+ const logger = input.logger ?? getLogger();
6513
+ const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
6514
+ await loader.load();
6515
+ assertPluginsResolvable(loader, "doctor repo");
6516
+ const checks = repoChecks(input.loaded.resolved, input.context.repoRoot);
6517
+ const rows = [];
6518
+ if (!loader.has("source")) {
6519
+ const why = whyMissing(loader, "source", "no `source` provider to read the repository with");
6520
+ for (const check of checks) rows.push(row$2(check, { skip: why }));
6521
+ } else {
6522
+ const source = loader.get("source");
6523
+ for (const check of checks) {
6524
+ if (typeof source[check.needs] !== "function") {
6525
+ rows.push(row$2(check, { skip: `provider does not implement ${check.needs}` }));
6526
+ continue;
6527
+ }
6528
+ try {
6529
+ rows.push(row$2(check, await check.run(source)));
6530
+ } catch (err) {
6531
+ if (err instanceof MissingTokenError) rows.push(row$2(check, { skip: err.message }));
6532
+ else rows.push({
6533
+ id: check.id,
6534
+ title: check.title,
6535
+ status: "fail",
6536
+ detail: errorMessage(err),
6537
+ problems: []
6538
+ });
6539
+ }
6540
+ }
6541
+ }
6542
+ printCheckRows(rows, print);
6543
+ const summary = summariseChecks(rows);
6544
+ printCheckSummary(summary, print);
6545
+ const status = summary.fail > 0 ? "fail" : summary.ok === 0 ? "skip" : "ok";
6546
+ logger.info({
6547
+ ...summary,
6548
+ status
6549
+ }, "doctor repo");
6550
+ return {
6551
+ status,
6552
+ rows,
6553
+ summary,
6554
+ ...status === "skip" ? { reason: rows.map((r) => r.detail).join("; ") } : {}
6555
+ };
6556
+ }
6557
+ function row$2(check, result) {
6558
+ const { id, title } = check;
6559
+ if ("skip" in result) return {
6560
+ id,
6561
+ title,
6562
+ status: "skip",
6563
+ detail: result.skip,
6564
+ problems: []
6565
+ };
6566
+ if (result.problems.length > 0) return {
6567
+ id,
6568
+ title,
6569
+ status: "fail",
6570
+ detail: `${result.problems.length} problem(s)`,
6571
+ problems: result.problems
6572
+ };
6573
+ return {
6574
+ id,
6575
+ title,
6576
+ status: "ok",
6577
+ detail: `${result.checked} of ${result.checked} match`,
6578
+ problems: []
6579
+ };
6580
+ }
6581
+ // src/commands/doctor-repo/doctor-repo.command.ts
6582
+ const doctorRepoCommand = {
6583
+ command: "repo",
6584
+ describe: "Check the repository settings against the config (read-only): description, topics, labels, teams, protection, security",
6036
6585
  handler: async (argv) => {
6037
6586
  const tokens = tokenContext(argv.token);
6038
6587
  if (!tokens) return;
6039
6588
  const loaded = await loadConfig(argv.cwd);
6040
6589
  applyResolvedConfig(argv, loaded.resolved);
6041
- if ((await runDoctorNotifications({
6590
+ if ((await runDoctorRepo({
6042
6591
  loaded,
6043
6592
  context: {
6044
6593
  repoRoot: argv.cwd,
6045
6594
  ...tokens,
6046
6595
  org: resolveOrg(argv, loaded.resolved)
6047
- },
6048
- ...argv.scope ? { scope: parseScope(argv.scope) } : {},
6049
- ...argv.provider ? { provider: argv.provider } : {},
6050
- ...argv.builtOnly ? { builtOnly: true } : {},
6051
- ...argv.deliver ? { deliver: true } : {}
6596
+ }
6052
6597
  })).status === "fail") process.exitCode = 1;
6053
6598
  }
6054
6599
  };
@@ -6646,6 +7191,19 @@ const DEEP_CHECKS = [
6646
7191
  };
6647
7192
  }
6648
7193
  },
7194
+ {
7195
+ name: "repo",
7196
+ capability: "source",
7197
+ command: doctorRepoCommand,
7198
+ async run(input) {
7199
+ const report = await runDoctorRepo(input);
7200
+ return {
7201
+ status: report.status,
7202
+ summary: report.summary,
7203
+ ...report.reason ? { reason: report.reason } : {}
7204
+ };
7205
+ }
7206
+ },
6649
7207
  {
6650
7208
  name: "secrets",
6651
7209
  capability: "secrets",
@@ -12883,101 +13441,6 @@ async function readWorkspacePackageJsons(repoRoot, workspacePackages) {
12883
13441
  }
12884
13442
  return results;
12885
13443
  }
12886
- // src/commands/setup/labels.ts
12887
- const CANONICAL_LABELS = [
12888
- {
12889
- name: "bug",
12890
- color: "d73a4a",
12891
- description: "Something isn't working"
12892
- },
12893
- {
12894
- name: "chore",
12895
- color: "ededed",
12896
- description: "Maintenance, no user-facing change"
12897
- },
12898
- {
12899
- name: "ci",
12900
- color: "0075ca",
12901
- description: "CI/CD pipeline changes"
12902
- },
12903
- {
12904
- name: "dependencies",
12905
- color: "0366d6",
12906
- description: "Dependency update"
12907
- },
12908
- {
12909
- name: "documentation",
12910
- color: "0075ca",
12911
- description: "Documentation only"
12912
- },
12913
- {
12914
- name: "duplicate",
12915
- color: "cfd3d7",
12916
- description: "Already reported"
12917
- },
12918
- {
12919
- name: "enhancement",
12920
- color: "a2eeef",
12921
- description: "New feature or request"
12922
- },
12923
- {
12924
- name: "good first issue",
12925
- color: "7057ff",
12926
- description: "Good for newcomers"
12927
- },
12928
- {
12929
- name: "help wanted",
12930
- color: "008672",
12931
- description: "Extra attention needed"
12932
- },
12933
- {
12934
- name: "invalid",
12935
- color: "e4e669",
12936
- description: "Doesn't seem right"
12937
- },
12938
- {
12939
- name: "performance",
12940
- color: "fbca04",
12941
- description: "Performance improvement"
12942
- },
12943
- {
12944
- name: "question",
12945
- color: "d876e3",
12946
- description: "Further information requested"
12947
- },
12948
- {
12949
- name: "refactor",
12950
- color: "cfd3d7",
12951
- description: "Code restructuring"
12952
- },
12953
- {
12954
- name: "released",
12955
- color: "ededed",
12956
- description: "Included in a release"
12957
- },
12958
- {
12959
- name: "test",
12960
- color: "bfd4f2",
12961
- description: "Test-related changes"
12962
- },
12963
- {
12964
- name: "triage",
12965
- color: "e4e669",
12966
- description: "Needs investigation"
12967
- },
12968
- {
12969
- name: "wontfix",
12970
- color: "ffffff",
12971
- description: "Won't be addressed"
12972
- }
12973
- ];
12974
- const STALE_LABELS = [
12975
- "github_actions",
12976
- "javascript",
12977
- "autorelease: pending",
12978
- "autorelease: tagged",
12979
- "released on @alpha"
12980
- ];
12981
13444
  // src/commands/setup/agent-prompts-data.ts
12982
13445
  /**
12983
13446
  * Canonical AI engineering workflow role prompts.
@@ -13386,121 +13849,6 @@ async function installAgentPrompts({ repoRoot }) {
13386
13849
  });
13387
13850
  return `wrote ${Object.keys(AGENT_PROMPTS).length} prompt files to ${AGENTS_PROMPTS_ROOT}/`;
13388
13851
  }
13389
- // src/commands/setup/branch-protection.ts
13390
- const RULESET_NAME = "holocron-default-branch";
13391
- function buildClassicProtectionPayload(requiredChecks = []) {
13392
- return {
13393
- required_status_checks: requiredChecks.length > 0 ? {
13394
- strict: false,
13395
- contexts: requiredChecks
13396
- } : null,
13397
- enforce_admins: false,
13398
- required_pull_request_reviews: {
13399
- required_approving_review_count: 0,
13400
- dismiss_stale_reviews: false,
13401
- require_code_owner_reviews: false
13402
- },
13403
- restrictions: null,
13404
- allow_force_pushes: false,
13405
- allow_deletions: false
13406
- };
13407
- }
13408
- function buildRulesetPayload(requiredChecks = []) {
13409
- const rules = [
13410
- { type: "deletion" },
13411
- { type: "non_fast_forward" },
13412
- {
13413
- type: "pull_request",
13414
- parameters: {
13415
- required_approving_review_count: 0,
13416
- dismiss_stale_reviews_on_push: false,
13417
- require_code_owner_review: false,
13418
- require_last_push_approval: false,
13419
- required_review_thread_resolution: true,
13420
- require_extra_approval_for_unattributed_changes: false
13421
- }
13422
- }
13423
- ];
13424
- if (requiredChecks.length > 0) rules.push({
13425
- type: "required_status_checks",
13426
- parameters: {
13427
- required_status_checks: requiredChecks.map((context) => ({ context })),
13428
- strict_required_status_checks_policy: false
13429
- }
13430
- });
13431
- return {
13432
- name: RULESET_NAME,
13433
- target: "branch",
13434
- enforcement: "active",
13435
- bypass_actors: [{
13436
- actor_id: 4,
13437
- actor_type: "RepositoryRole",
13438
- bypass_mode: "always"
13439
- }],
13440
- conditions: { ref_name: {
13441
- include: ["~DEFAULT_BRANCH"],
13442
- exclude: []
13443
- } },
13444
- rules
13445
- };
13446
- }
13447
- async function upsertBranchProtection(source, dryRun, requiredChecks) {
13448
- const step = `upsert ruleset ${RULESET_NAME}`;
13449
- if (dryRun) return {
13450
- capability: "source",
13451
- step,
13452
- status: "dry-run"
13453
- };
13454
- try {
13455
- const found = (await source.listRulesets()).find((r) => r.name === RULESET_NAME);
13456
- if (found) {
13457
- await source.updateRuleset(found.id, buildRulesetPayload(requiredChecks));
13458
- return {
13459
- capability: "source",
13460
- step,
13461
- status: "ok",
13462
- message: "updated"
13463
- };
13464
- }
13465
- await source.createRuleset(buildRulesetPayload(requiredChecks));
13466
- return {
13467
- capability: "source",
13468
- step,
13469
- status: "ok",
13470
- message: "created"
13471
- };
13472
- } catch (err) {
13473
- if (!(err instanceof ProviderApiError$1) || err.status !== 403) return {
13474
- capability: "source",
13475
- step,
13476
- status: "fail",
13477
- message: errorMessage(err)
13478
- };
13479
- }
13480
- try {
13481
- const repo = await source.getRepo();
13482
- await source.protectBranch(repo.defaultBranch, buildClassicProtectionPayload(requiredChecks));
13483
- return {
13484
- capability: "source",
13485
- step,
13486
- status: "ok",
13487
- message: `classic protection on ${repo.defaultBranch}`
13488
- };
13489
- } catch (err) {
13490
- if (err instanceof ProviderApiError$1 && err.status === 403) return {
13491
- capability: "source",
13492
- step,
13493
- status: "skip",
13494
- message: "branch protection unavailable on private repos without GitHub Pro/Team"
13495
- };
13496
- return {
13497
- capability: "source",
13498
- step,
13499
- status: "fail",
13500
- message: errorMessage(err)
13501
- };
13502
- }
13503
- }
13504
13852
  // src/commands/setup/engineering.ts
13505
13853
  async function writeIfAbsent(filePath, content) {
13506
13854
  try {
@@ -13522,19 +13870,6 @@ async function installEngineeringStructure({ repoRoot }) {
13522
13870
  for (const [path, content] of writes) if (await writeIfAbsent(path, content)) results.push(path.replace(repoRoot + "/", ""));
13523
13871
  return results.length > 0 ? `created: ${results.join(", ")}` : "all files already exist — nothing to write";
13524
13872
  }
13525
- // src/commands/setup/repo-settings.ts
13526
- const BALANCED_REPO_SETTINGS = {
13527
- allow_squash_merge: true,
13528
- allow_merge_commit: false,
13529
- allow_rebase_merge: false,
13530
- allow_auto_merge: true,
13531
- allow_update_branch: true,
13532
- delete_branch_on_merge: true,
13533
- has_issues: true,
13534
- has_discussions: true,
13535
- has_projects: true,
13536
- has_wiki: false
13537
- };
13538
13873
  // src/commands/setup/run-step/run-step.ts
13539
13874
  async function runStep(capability, step, dryRun, body, opts = {}) {
13540
13875
  const result = await execStep(capability, step, dryRun, body, opts);