@theholocron/cli 5.0.0-alpha.419 → 5.0.0-alpha.420

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
@@ -637,6 +637,7 @@ commands and the config are provider-neutral; Discord is the first provider.
637
637
  | `holocron doctor logs` | Does each Axiom dataset the setup ships logs to exist, and does the token reach it? Rows: `token is accepted` (a 401 fails), one `dataset for <service>` for the CLI (`HOLOCRON_AXIOM_DATASET`, resolved by the logger's own chain), Sentinel (`SENTINEL_AXIOM_DATASET`) and any other `dev.serve.logging.datasetVar` (a 404 fails and names the fix), `organization` (`HOLOCRON_AXIOM_ORG`, then `AXIOM_ORG`), and an `info` row per dataset with the `retentionDays` Axiom reports (or says it reported none). Reads through the optional `Logs.readDataset` / `Logs.checkToken`; never creates a dataset or prints a token. A name or token that cannot be read is a skip. Read-only |
638
638
  | `holocron doctor environments` | Do the deployment environments exist? The ones `repo setup` creates (`staging`, `production`, when an `environments` provider is configured) plus every environment `repo.secrets.environments` names. One row. A missing one fails; an extra one is never a problem; no provider with some named is a skip |
639
639
  | `holocron doctor project [--post [channel]]` | Does each board `providers.projects.boards` declares exist and match its template? One row per board, status list, field, view and automation rule; the board's extras and the items `project reconcile` would fix (no status, closed but not done, open blocker but not blocked, blocked without a blocker) are `info` rows, never a failure. A template file that does not read fails, naming the file. Read-only; `--post` shares the failing rows through the `notifications` bot. |
640
+ | `holocron doctor shared-values [--strict] [--allow NAME]...` | Does a secret hold the same value in two layers? Reads `<org/repo> - local`, `- dev`, `- ci` and `- prod` in memory and compares the concealed entries by a salted hash made fresh per run; prints names only, one row per pair of layers (`info`, shown as skipped; `--strict` fails), and `info` rows for `ci` variables missing from or different in `dev`. `doctor.sharedVariables` and `--allow` leave out names shared on purpose; a layer that cannot be read is a skip, a missing `local` is silent. Read-only |
640
641
  | `holocron doctor variable-owners` | Does a variable name live in more than one place? Reads the names (never a value) of the 1Password Environments the config names and of the GitHub Actions secrets and variables, and fails for a name two places hold, unless a `repo.secrets.sync` / `repo.variables.sync` entry made the copy, `doctor.sharedVariables` lists it, or both places are instances of one `githubApps` App. A bare name beside its prefixed one (`X`, `HOLOCRON_X`) is an `info` row; a place that cannot be read is a skip. Read-only |
641
642
  | `holocron doctor credentials` | Does the credentials environment exist, and does it hold every variable the configured plugins take? One row per variable and provider (`ok`, `fail` when missing, `skip` for an optional one not set), listing names only: it never reads a value, and says which spelling of the environment's name matched. |
642
643
  | `holocron doctor repo` | Do the repository settings `repo setup` writes match the config? One row per group the config declares: description and homepage, default branch and merge settings, topics, custom properties, team access, branch protection; labels and security settings are always checked. Read-only. Reads through optional `Source` methods (`getRepoInfo`, `getProperties`, `listLabels`, `listTeamAccess`, `getRulesetDetail`, `getSecurity`); a group that cannot be read is a skip, not a failure |
@@ -930,8 +931,8 @@ the local override exists to exempt.
930
931
  `package bump-versions`, `package move-tag`, `sync github`, `repo upgrade node`,
931
932
  `repo upgrade deps`, `new plugin`, `auth`, `notifications setup`,
932
933
  `notifications channel add`, `notifications link`,
933
- `notifications sync-roles`, `doctor ci`, `doctor credentials`, `doctor dns`, `doctor environments`, `doctor monitoring`, `doctor notifications`, `doctor project`, `doctor repo`, `doctor secrets`, `doctor tokens`, `doctor variable-owners`, `doctor variables`
934
- `notifications sync-roles`, `project reconcile`, `doctor ci`, `doctor credentials`, `doctor dns`, `doctor environments`, `doctor monitoring`, `doctor notifications`, `doctor repo`, `doctor secrets`, `doctor tokens`, `doctor variable-owners`, `doctor variables`
934
+ `notifications sync-roles`, `doctor ci`, `doctor credentials`, `doctor dns`, `doctor environments`, `doctor monitoring`, `doctor notifications`, `doctor project`, `doctor repo`, `doctor secrets`, `doctor shared-values`, `doctor tokens`, `doctor variable-owners`, `doctor variables`
935
+ `notifications sync-roles`, `project reconcile`, `doctor ci`, `doctor credentials`, `doctor dns`, `doctor environments`, `doctor monitoring`, `doctor notifications`, `doctor repo`, `doctor secrets`, `doctor shared-values`, `doctor tokens`, `doctor variable-owners`, `doctor variables`
935
936
  - `src/commands/deep-checks/` — `DEEP_CHECKS`, the registry every `doctor <capability>` is
936
937
  listed in; the shared row renderer and `declaredVsActual` helper are in `@theholocron/kyber/ui`
937
938
  - `src/interactive-menu/` — the interactive fallback's Holocron data: `command-catalog`
package/dist/cli.mjs CHANGED
@@ -1071,6 +1071,7 @@ const COMMAND_CONTEXTS = {
1071
1071
  "doctor monitoring": "workspace",
1072
1072
  "doctor variables": "workspace",
1073
1073
  "doctor variable-owners": "workspace",
1074
+ "doctor shared-values": "workspace",
1074
1075
  "doctor ci": "repo-aware",
1075
1076
  probe: "workspace",
1076
1077
  provider: "workspace",
@@ -2433,6 +2434,20 @@ const doctorSecretsEntry = {
2433
2434
  positionals: [],
2434
2435
  supportsDryRun: false
2435
2436
  };
2437
+ // src/commands/doctor-shared-values/doctor-shared-values.entry.ts
2438
+ const doctorSharedValuesEntry = {
2439
+ name: "doctor shared-values",
2440
+ description: "Find secrets that hold the same value in two layers: local, dev, ci and prod (read-only, names only)",
2441
+ positionals: [],
2442
+ options: [{
2443
+ key: "strict",
2444
+ flag: "--strict",
2445
+ type: "confirm",
2446
+ default: false,
2447
+ message: "Fail when a secret is shared between two layers?"
2448
+ }],
2449
+ supportsDryRun: false
2450
+ };
2436
2451
  // src/commands/doctor-tokens/doctor-tokens.entry.ts
2437
2452
  const doctorTokensEntry = {
2438
2453
  name: "doctor tokens",
@@ -2975,6 +2990,7 @@ const registry = createCommandRegistry([
2975
2990
  doctorTokensEntry,
2976
2991
  doctorVariablesEntry,
2977
2992
  doctorVariableOwnersEntry,
2993
+ doctorSharedValuesEntry,
2978
2994
  doctorCiEntry,
2979
2995
  notificationsSetupEntry,
2980
2996
  notificationsCreateServerEntry,
@@ -6571,7 +6587,7 @@ function row$7(name, what, status, detail) {
6571
6587
  };
6572
6588
  }
6573
6589
  /** An error's message with the secrets it was handed taken out, so nothing read from the vault is ever printed. */
6574
- function scrubbed(err, secrets) {
6590
+ function scrubbed$1(err, secrets) {
6575
6591
  return secrets.filter(Boolean).reduce((text, secret) => text.split(secret).join("[redacted]"), errorMessage(err));
6576
6592
  }
6577
6593
  /** The App's id and key from its vault environment, or the reason they cannot be had. */
@@ -6614,7 +6630,7 @@ async function checkInstance(instance, loader, input) {
6614
6630
  const owner = app.owner ? `, owned by ${app.owner.login}` : "";
6615
6631
  return [row$7(name, "reachable", "ok", `${app.slug}${owner}, settings: ${appSettingsUrl(app)}`), ...appRows(name, manifest, app, installations)];
6616
6632
  } catch (err) {
6617
- return [row$7(name, "reachable", "fail", `cannot call GitHub as the App: ${scrubbed(err, secrets)}`)];
6633
+ return [row$7(name, "reachable", "fail", `cannot call GitHub as the App: ${scrubbed$1(err, secrets)}`)];
6618
6634
  }
6619
6635
  }
6620
6636
  // src/commands/doctor-github-app/doctor-github-app.command.ts
@@ -6981,7 +6997,7 @@ const doctorNotificationsArgs = (y) => y.option("scope", {
6981
6997
  });
6982
6998
  // src/commands/notification-check-rows/notification-check-rows.ts
6983
6999
  /** A step that could not be tried: the reason is the detail, and it is not a failure. */
6984
- function skipRow(id, title, reason) {
7000
+ function skipRow$1(id, title, reason) {
6985
7001
  return {
6986
7002
  id,
6987
7003
  title,
@@ -7010,8 +7026,8 @@ const TITLE = "bot holds the server-wide permissions it needs";
7010
7026
  */
7011
7027
  function botPermissionChecks(input) {
7012
7028
  const { found } = input;
7013
- if (!found) return [skipRow("bot-permissions", TITLE, "not checked: could not read the server")];
7014
- if (found.botPermissionsError) return [skipRow("bot-permissions", TITLE, `not checked: could not read the bot's roles (${sanitizeDetail(found.botPermissionsError)})`)];
7029
+ if (!found) return [skipRow$1("bot-permissions", TITLE, "not checked: could not read the server")];
7030
+ if (found.botPermissionsError) return [skipRow$1("bot-permissions", TITLE, `not checked: could not read the bot's roles (${sanitizeDetail(found.botPermissionsError)})`)];
7015
7031
  const { botPermissions } = found;
7016
7032
  if (!botPermissions) return [];
7017
7033
  const { missing, inviteUrl } = botPermissions;
@@ -7807,9 +7823,9 @@ const SUBSCRIPTIONS_TITLE = "monitoring alert channel is subscribed to the check
7807
7823
  const same$3 = (a, b) => a.toLowerCase() === b.toLowerCase();
7808
7824
  const shown$5 = (s) => sanitizeDetail(s);
7809
7825
  const skipAll = (reason) => [
7810
- skipRow(WEBHOOK_ID$1, WEBHOOK_TITLE$1, reason),
7811
- skipRow(CHANNEL_ID, CHANNEL_TITLE, reason),
7812
- skipRow(SUBSCRIPTIONS_ID, SUBSCRIPTIONS_TITLE, reason)
7826
+ skipRow$1(WEBHOOK_ID$1, WEBHOOK_TITLE$1, reason),
7827
+ skipRow$1(CHANNEL_ID, CHANNEL_TITLE, reason),
7828
+ skipRow$1(SUBSCRIPTIONS_ID, SUBSCRIPTIONS_TITLE, reason)
7813
7829
  ];
7814
7830
  /**
7815
7831
  * The steps of `doctor notifications` that check the monitoring provider's feed into Discord: the webhook it posts
@@ -7874,7 +7890,7 @@ async function monitoringFeedChecks(input) {
7874
7890
  for (const check of state.deactivated) subscriptionProblems.push(`${label}: ${shown$5(names.name)} has ${shown$5(check)} switched off`);
7875
7891
  }
7876
7892
  const n = fed.length;
7877
- return [resultRow(WEBHOOK_ID$1, WEBHOOK_TITLE$1, webhookProblems, `${n} of ${n} as declared`), ...channelSkip === void 0 ? [resultRow(CHANNEL_ID, CHANNEL_TITLE, channelProblems, `${n} of ${n} as declared`), resultRow(SUBSCRIPTIONS_ID, SUBSCRIPTIONS_TITLE, subscriptionProblems, `${n} of ${n} subscribed`)] : [skipRow(CHANNEL_ID, CHANNEL_TITLE, channelSkip), skipRow(SUBSCRIPTIONS_ID, SUBSCRIPTIONS_TITLE, channelSkip)]];
7893
+ return [resultRow(WEBHOOK_ID$1, WEBHOOK_TITLE$1, webhookProblems, `${n} of ${n} as declared`), ...channelSkip === void 0 ? [resultRow(CHANNEL_ID, CHANNEL_TITLE, channelProblems, `${n} of ${n} as declared`), resultRow(SUBSCRIPTIONS_ID, SUBSCRIPTIONS_TITLE, subscriptionProblems, `${n} of ${n} subscribed`)] : [skipRow$1(CHANNEL_ID, CHANNEL_TITLE, channelSkip), skipRow$1(SUBSCRIPTIONS_ID, SUBSCRIPTIONS_TITLE, channelSkip)]];
7878
7894
  }
7879
7895
  const localRedirectUri = (port) => `http://localhost:${port}/callback`;
7880
7896
  /**
@@ -8470,9 +8486,9 @@ async function notificationsWorkflowChecks(input) {
8470
8486
  if (!source?.readFile) {
8471
8487
  const reason = source ? `the \`${source.providerName}\` provider cannot read a file` : input.sourceMissingReason;
8472
8488
  return [
8473
- skipRow(PRESENT_ID, PRESENT_TITLE, reason),
8474
- skipRow(WIRED_ID, WIRED_TITLE, "not checked: the workflow could not be read"),
8475
- skipRow(NAMES_ID, NAMES_TITLE, "not checked: the workflow could not be read")
8489
+ skipRow$1(PRESENT_ID, PRESENT_TITLE, reason),
8490
+ skipRow$1(WIRED_ID, WIRED_TITLE, "not checked: the workflow could not be read"),
8491
+ skipRow$1(NAMES_ID, NAMES_TITLE, "not checked: the workflow could not be read")
8476
8492
  ];
8477
8493
  }
8478
8494
  let text;
@@ -8488,14 +8504,14 @@ async function notificationsWorkflowChecks(input) {
8488
8504
  detail: reason,
8489
8505
  problems: []
8490
8506
  },
8491
- skipRow(WIRED_ID, WIRED_TITLE, "not checked: the workflow could not be read"),
8492
- skipRow(NAMES_ID, NAMES_TITLE, "not checked: the workflow could not be read")
8507
+ skipRow$1(WIRED_ID, WIRED_TITLE, "not checked: the workflow could not be read"),
8508
+ skipRow$1(NAMES_ID, NAMES_TITLE, "not checked: the workflow could not be read")
8493
8509
  ];
8494
8510
  }
8495
8511
  if (text === void 0) return [
8496
8512
  resultRow(PRESENT_ID, PRESENT_TITLE, [`${NOTIFICATIONS_WORKFLOW_PATH} is missing: without it a failed run or a release posts nothing to Discord`], ""),
8497
- skipRow(WIRED_ID, WIRED_TITLE, "not checked: the workflow is missing"),
8498
- skipRow(NAMES_ID, NAMES_TITLE, "not checked: the workflow is missing")
8513
+ skipRow$1(WIRED_ID, WIRED_TITLE, "not checked: the workflow is missing"),
8514
+ skipRow$1(NAMES_ID, NAMES_TITLE, "not checked: the workflow is missing")
8499
8515
  ];
8500
8516
  const read = [...text.matchAll(/secrets\.(HOLOCRON_NOTIFY_[A-Z0-9_]+)/g)].map((m) => m[1]);
8501
8517
  const readSet = upper(read);
@@ -8561,9 +8577,9 @@ function prFeedChecks(input) {
8561
8577
  if (!found) {
8562
8578
  const reason = "not checked: could not read the server";
8563
8579
  return [
8564
- skipRow("pr-feed-forum", FORUM_TITLE, reason),
8565
- skipRow("pr-feed-tags", TAGS_TITLE, reason),
8566
- skipRow("pr-feed-bot", BOT_TITLE, reason)
8580
+ skipRow$1("pr-feed-forum", FORUM_TITLE, reason),
8581
+ skipRow$1("pr-feed-tags", TAGS_TITLE, reason),
8582
+ skipRow$1("pr-feed-bot", BOT_TITLE, reason)
8567
8583
  ];
8568
8584
  }
8569
8585
  const forumProblems = [];
@@ -8633,22 +8649,22 @@ async function relayChecks(input) {
8633
8649
  const relay = layout.relay;
8634
8650
  if (!relay?.host || !wantsRelay(layout)) return [];
8635
8651
  if (!input.errors) return [
8636
- skipRow(ANSWERS_ID, ANSWERS_TITLE, input.errorsMissingReason),
8637
- skipRow(WORKER_ID, WORKER_TITLE, input.errorsMissingReason),
8638
- skipRow(BINDINGS_ID, BINDINGS_TITLE, input.errorsMissingReason),
8639
- skipRow(WEBHOOK_ID, WEBHOOK_TITLE, input.errorsMissingReason)
8652
+ skipRow$1(ANSWERS_ID, ANSWERS_TITLE, input.errorsMissingReason),
8653
+ skipRow$1(WORKER_ID, WORKER_TITLE, input.errorsMissingReason),
8654
+ skipRow$1(BINDINGS_ID, BINDINGS_TITLE, input.errorsMissingReason),
8655
+ skipRow$1(WEBHOOK_ID, WEBHOOK_TITLE, input.errorsMissingReason)
8640
8656
  ];
8641
8657
  const source = input.errors.providerName;
8642
8658
  const rows = [];
8643
8659
  rows.push(resultRow(ANSWERS_ID, ANSWERS_TITLE, await answers(`https://${relay.host}/${source}`, input.fetch ?? fetch), `https://${shown$2(relay.host)}/${shown$2(source)} answered 401`));
8644
8660
  const script = relay.script ?? "comlink";
8645
8661
  const route = `${relay.host}/*`;
8646
- const skipWorker = (reason) => [skipRow(WORKER_ID, WORKER_TITLE, reason), skipRow(BINDINGS_ID, BINDINGS_TITLE, reason)];
8662
+ const skipWorker = (reason) => [skipRow$1(WORKER_ID, WORKER_TITLE, reason), skipRow$1(BINDINGS_ID, BINDINGS_TITLE, reason)];
8647
8663
  if (!input.workers) rows.push(...skipWorker(input.workersMissingReason));
8648
8664
  else if (!input.workers.inspectScript) rows.push(...skipWorker(`the \`${input.workers.providerName}\` provider cannot read its Workers`));
8649
8665
  else try {
8650
8666
  const state = await input.workers.inspectScript(script, relay.host);
8651
- if (!state.exists) rows.push(resultRow(WORKER_ID, WORKER_TITLE, [`no Worker named ${shown$2(script)}`], ""), skipRow(BINDINGS_ID, BINDINGS_TITLE, `not checked: no Worker named ${shown$2(script)}`));
8667
+ if (!state.exists) rows.push(resultRow(WORKER_ID, WORKER_TITLE, [`no Worker named ${shown$2(script)}`], ""), skipRow$1(BINDINGS_ID, BINDINGS_TITLE, `not checked: no Worker named ${shown$2(script)}`));
8652
8668
  else {
8653
8669
  const bound = new Set(state.bindingNames.map((n) => n.toUpperCase()));
8654
8670
  const wanted = [relayWebhookBinding(source), relaySecretBinding(source)];
@@ -8656,14 +8672,14 @@ async function relayChecks(input) {
8656
8672
  }
8657
8673
  } catch (err) {
8658
8674
  const reason = missingTokenReason(err);
8659
- rows.push(...reason === void 0 ? [resultRow(WORKER_ID, WORKER_TITLE, [shown$2(describeError(err))], ""), skipRow(BINDINGS_ID, BINDINGS_TITLE, "not checked: could not read the Worker")] : skipWorker(reason));
8675
+ rows.push(...reason === void 0 ? [resultRow(WORKER_ID, WORKER_TITLE, [shown$2(describeError(err))], ""), skipRow$1(BINDINGS_ID, BINDINGS_TITLE, "not checked: could not read the Worker")] : skipWorker(reason));
8660
8676
  }
8661
8677
  rows.push(webhookRow(input, source));
8662
8678
  return rows;
8663
8679
  }
8664
8680
  /** The error feed's webhook is on its channel, with a picture when the layout or the provider gives one. */
8665
8681
  function webhookRow(input, source) {
8666
- if (!input.found) return skipRow(WEBHOOK_ID, WEBHOOK_TITLE, "not checked: could not read the server");
8682
+ if (!input.found) return skipRow$1(WEBHOOK_ID, WEBHOOK_TITLE, "not checked: could not read the server");
8667
8683
  const channel = input.layout.categories.flatMap((cat) => cat.channels ?? []).find((c) => c.feeds?.errors);
8668
8684
  const feed = channel.feeds.errors;
8669
8685
  const name = errorsFeedWebhook(feed, { providerName: source });
@@ -8693,7 +8709,7 @@ async function sentryRelayChecks(input) {
8693
8709
  const { layout, errors } = input;
8694
8710
  const tracker = layout.relay?.errors;
8695
8711
  if (!tracker || !wantsRelay(layout)) return [];
8696
- const skipBoth = (reason) => [skipRow(INTEGRATION_ID, INTEGRATION_TITLE, reason), skipRow(RULE_ID, RULE_TITLE, reason)];
8712
+ const skipBoth = (reason) => [skipRow$1(INTEGRATION_ID, INTEGRATION_TITLE, reason), skipRow$1(RULE_ID, RULE_TITLE, reason)];
8697
8713
  if (!errors) return skipBoth(input.errorsMissingReason);
8698
8714
  if (!errors.inspectRelay) return skipBoth(`the \`${errors.providerName}\` provider cannot read its relay`);
8699
8715
  const name = tracker.integration ?? "Comlink";
@@ -8708,7 +8724,7 @@ async function sentryRelayChecks(input) {
8708
8724
  } catch (err) {
8709
8725
  const noToken = missingTokenReason(err);
8710
8726
  if (noToken !== void 0) return skipBoth(noToken);
8711
- return [resultRow(INTEGRATION_ID, INTEGRATION_TITLE, [shown$1(describeError(err))], ""), skipRow(RULE_ID, RULE_TITLE, "not checked: could not read the integration")];
8727
+ return [resultRow(INTEGRATION_ID, INTEGRATION_TITLE, [shown$1(describeError(err))], ""), skipRow$1(RULE_ID, RULE_TITLE, "not checked: could not read the integration")];
8712
8728
  }
8713
8729
  const expected = `https://${layout.relay.host}/${errors.providerName}`;
8714
8730
  const integrationProblems = [];
@@ -11208,6 +11224,273 @@ const doctorSecretsCommand = {
11208
11224
  })).status === "fail") process.exitCode = 1;
11209
11225
  }
11210
11226
  };
11227
+ // src/commands/doctor-shared-values/compare-layers.ts
11228
+ /**
11229
+ * Finds, for every pair of layers, the secrets that hold the same value. A value is never compared as text: each is
11230
+ * turned into an HMAC under a salt made fresh for this call, so a digest means nothing outside it and is held only in
11231
+ * these maps. The result carries names, never a value or a digest.
11232
+ *
11233
+ * Only concealed entries are compared. An empty value is ignored. The same value under two names counts (`A = B`). A pair where either name is in `allow`
11234
+ * (compared without regard to case) is left out.
11235
+ *
11236
+ * @param layers - The layers that were read, in `local, dev, ci, prod` order.
11237
+ * @param allow - Names shared on purpose.
11238
+ * @returns One entry per pair of layers, `names` empty when nothing is shared.
11239
+ */
11240
+ function compareLayers(layers, allow) {
11241
+ const salt = randomBytes(32);
11242
+ const allowed = new Set(allow.map((name) => name.toUpperCase()));
11243
+ const digests = layers.map((layer) => {
11244
+ const byDigest = /* @__PURE__ */ new Map();
11245
+ for (const { name, value, concealed } of layer.entries) {
11246
+ if (!concealed || !value) continue;
11247
+ const digest = createHmac("sha256", salt).update(value).digest("hex");
11248
+ byDigest.set(digest, [...byDigest.get(digest) ?? [], name]);
11249
+ }
11250
+ return byDigest;
11251
+ });
11252
+ const pairs = [];
11253
+ for (let later = 1; later < layers.length; later++) for (let earlier = 0; earlier < later; earlier++) {
11254
+ const names = /* @__PURE__ */ new Set();
11255
+ for (const [digest, laterNames] of digests[later]) for (const a of laterNames) for (const b of digests[earlier].get(digest) ?? []) {
11256
+ if (allowed.has(a.toUpperCase()) || allowed.has(b.toUpperCase())) continue;
11257
+ names.add(a.toUpperCase() === b.toUpperCase() ? a : `${a} = ${b}`);
11258
+ }
11259
+ pairs.push({
11260
+ layer: layers[later].layer,
11261
+ other: layers[earlier].layer,
11262
+ names: [...names].sort()
11263
+ });
11264
+ }
11265
+ return pairs;
11266
+ }
11267
+ // src/commands/doctor-shared-values/compare-variables.ts
11268
+ /**
11269
+ * Compares the variables (the entries a vault holds visible) of `ci` with those of `dev`. The organization's constants
11270
+ * live in `ci` and have a copy in `dev`, with no fallback between layers (#2058), so a name `ci` has and `dev` lacks, or
11271
+ * one whose value differs, is drift. A `dev` value may differ on purpose, which is why the caller reports it as `info`.
11272
+ * Names only come back: the values are compared in memory and dropped. Names are compared without regard to case, and
11273
+ * a name in `allow` is left out.
11274
+ *
11275
+ * @param layers - The layers that were read.
11276
+ * @param allow - Names shared on purpose.
11277
+ * @returns `undefined` when `ci` or `dev` was not read, so there is nothing to compare.
11278
+ */
11279
+ function compareVariables(layers, allow) {
11280
+ const ci = layers.find((l) => l.layer === "ci");
11281
+ const dev = layers.find((l) => l.layer === "dev");
11282
+ if (!ci || !dev) return void 0;
11283
+ const allowed = new Set(allow.map((name) => name.toUpperCase()));
11284
+ const variables = (layer) => new Map(layer.entries.filter((e) => !e.concealed).map((e) => [e.name.toUpperCase(), e]));
11285
+ const inDev = variables(dev);
11286
+ const missing = [];
11287
+ const differs = [];
11288
+ for (const [key, entry] of variables(ci)) {
11289
+ if (allowed.has(key)) continue;
11290
+ const copy = inDev.get(key);
11291
+ if (!copy) missing.push(entry.name);
11292
+ else if (copy.value !== entry.value) differs.push(entry.name);
11293
+ }
11294
+ return {
11295
+ missing: missing.sort(),
11296
+ differs: differs.sort()
11297
+ };
11298
+ }
11299
+ // src/commands/doctor-shared-values/read-layers.ts
11300
+ /** An error's text with every value read so far taken out, so a vault's message can never carry one to the output. */
11301
+ function scrubbed(err, known) {
11302
+ return known.reduce((text, value) => text.split(value).join("[redacted]"), describeError(err));
11303
+ }
11304
+ /**
11305
+ * Reads each layer's Environment (`<slug> - local|dev|ci|prod`) in memory, every entry with its `concealed` flag.
11306
+ *
11307
+ * A provider that implements `readEnvironmentEntries` says which entries are concealed. One
11308
+ * that only has `readEnvironment` cannot say, so every entry is kept and one skipped row says so: the allow-list is
11309
+ * then the way to leave a visible value out. A layer that cannot be read is a skipped row naming it and why; `local`
11310
+ * is optional, so an unreadable one is silent. Nothing read here is printed or logged.
11311
+ *
11312
+ * @param vault - A `vault` provider that can read an environment.
11313
+ * @param slug - The `<org>/<repo>` the Environments are named from.
11314
+ */
11315
+ async function readLayers(vault, slug) {
11316
+ const layers = [];
11317
+ const rows = [];
11318
+ const known = [];
11319
+ let blind = false;
11320
+ for (const layer of ENVIRONMENT_LAYERS) {
11321
+ const environment = layerEnvironment(slug, layer);
11322
+ let entries;
11323
+ try {
11324
+ if (vault.readEnvironmentEntries) entries = await vault.readEnvironmentEntries(environment);
11325
+ else {
11326
+ const values = await vault.readEnvironment(environment);
11327
+ entries = Object.entries(values).map(([name, value]) => ({
11328
+ name,
11329
+ value,
11330
+ concealed: true
11331
+ }));
11332
+ blind = true;
11333
+ }
11334
+ } catch (err) {
11335
+ if (layer === "local") continue;
11336
+ rows.push({
11337
+ id: `skip:${layer}`,
11338
+ title: `Environment "${environment}"`,
11339
+ status: "skip",
11340
+ detail: `could not read it: ${scrubbed(err, known)}`,
11341
+ problems: []
11342
+ });
11343
+ continue;
11344
+ }
11345
+ known.push(...entries.map((e) => e.value).filter(Boolean));
11346
+ layers.push({
11347
+ layer,
11348
+ environment,
11349
+ entries
11350
+ });
11351
+ }
11352
+ if (blind) rows.unshift({
11353
+ id: "concealed",
11354
+ title: `${vault.providerName} cannot say which entries are concealed`,
11355
+ status: "skip",
11356
+ detail: "info: every entry is compared; list a visible value that is meant to be shared in `doctor.sharedVariables`",
11357
+ problems: []
11358
+ });
11359
+ return {
11360
+ layers,
11361
+ rows
11362
+ };
11363
+ }
11364
+ // src/commands/doctor-shared-values/doctor-shared-values.ts
11365
+ /**
11366
+ * `holocron doctor shared-values` — does a secret hold the same value in two layers?
11367
+ *
11368
+ * A leak from CI should not expose what a laptop holds, so the layers (`<org/repo> - local|dev|ci|prod`) keep their
11369
+ * own values (#2058, #2059). Read-only: it reads each layer's Environment in memory through the `vault` provider and
11370
+ * compares the concealed entries by a salted hash made fresh for the run. It prints names only, one row per pair of
11371
+ * layers; no value, hash or length reaches the output, a log or an error. A shared secret is an `info` row (shown as
11372
+ * skipped) and the exit stays 0, unless `--strict` makes it a failure. A name in `doctor.sharedVariables` or passed
11373
+ * with `--allow` is shared on purpose and left out. A layer that cannot be read is a skipped row; `local` missing is silent.
11374
+ */
11375
+ function skipRow(id, title, detail) {
11376
+ return {
11377
+ id,
11378
+ title,
11379
+ status: "skip",
11380
+ detail,
11381
+ problems: []
11382
+ };
11383
+ }
11384
+ async function runDoctorSharedValues(input) {
11385
+ const print = input.print ?? ((line) => console.log(line));
11386
+ const logger = input.logger ?? getLogger();
11387
+ const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
11388
+ await loader.load();
11389
+ assertPluginsResolvable$1(loader, "doctor shared-values");
11390
+ const rows = [];
11391
+ let compared = 0;
11392
+ let shared = 0;
11393
+ let drifted = 0;
11394
+ const vault = loader.has("vault") ? loader.get("vault") : void 0;
11395
+ if (!vault?.readEnvironment && !vault?.readEnvironmentEntries) rows.push(skipRow("vault", "read the layers", vault ? `${vault.providerName} cannot read an environment's variables` : "needs a `vault` provider in holocron.config.ts (1password)"));
11396
+ else {
11397
+ let slug;
11398
+ try {
11399
+ slug = await repoSlug(input.context.repoRoot, input.gitExec);
11400
+ } catch (err) {
11401
+ rows.push(skipRow("slug", "name the layers", describeError(err)));
11402
+ }
11403
+ if (slug !== void 0) {
11404
+ const read = await readLayers(vault, slug);
11405
+ rows.push(...read.rows);
11406
+ const allow = [...input.loaded.resolved.doctor.sharedVariables ?? [], ...input.allow ?? []];
11407
+ for (const pair of compareLayers(read.layers, allow)) {
11408
+ compared++;
11409
+ shared += pair.names.length;
11410
+ const title = `${pair.layer} = ${pair.other}`;
11411
+ if (pair.names.length === 0) {
11412
+ rows.push({
11413
+ id: `pair:${pair.layer}:${pair.other}`,
11414
+ title,
11415
+ status: "ok",
11416
+ detail: "no secret shares a value",
11417
+ problems: []
11418
+ });
11419
+ continue;
11420
+ }
11421
+ const what = `${pair.names.length === 1 ? "1 secret shares a value" : `${pair.names.length} secrets share a value`} between ${pair.other} and ${pair.layer}: ${pair.names.join(", ")}`;
11422
+ rows.push({
11423
+ id: `pair:${pair.layer}:${pair.other}`,
11424
+ title,
11425
+ status: input.strict ? "fail" : "skip",
11426
+ detail: input.strict ? what : `info: ${what}`,
11427
+ problems: []
11428
+ });
11429
+ }
11430
+ const drift = compareVariables(read.layers, allow);
11431
+ for (const [what, names] of [["missing from dev, present in ci", drift?.missing ?? []], ["differ between ci and dev", drift?.differs ?? []]]) {
11432
+ if (names.length === 0) continue;
11433
+ drifted += names.length;
11434
+ rows.push({
11435
+ id: `variables:${what.split(" ")[0]}`,
11436
+ title: `variables ${what}`,
11437
+ status: "skip",
11438
+ detail: `info: ${names.length} variable${names.length === 1 ? "" : "s"}: ${names.join(", ")}`,
11439
+ problems: []
11440
+ });
11441
+ }
11442
+ if (read.layers.length < 2) rows.push(skipRow("pairs", "compare the layers", "fewer than two layers could be read, so there is nothing to compare"));
11443
+ }
11444
+ }
11445
+ printCheckRows(rows, print);
11446
+ print(`${compared} pair${compared === 1 ? "" : "s"} compared, ${shared} shared name${shared === 1 ? "" : "s"}, ${drifted} variable${drifted === 1 ? "" : "s"} drifting`);
11447
+ const summary = summariseChecks(rows);
11448
+ printCheckSummary(summary, print);
11449
+ const status = summary.fail > 0 ? "fail" : summary.ok === 0 ? "skip" : "ok";
11450
+ logger.info({
11451
+ ...summary,
11452
+ status,
11453
+ compared,
11454
+ shared
11455
+ }, "doctor shared-values");
11456
+ return {
11457
+ status,
11458
+ rows,
11459
+ summary,
11460
+ ...status === "skip" ? { reason: [...new Set(rows.map((r) => r.detail))].join("; ") } : {}
11461
+ };
11462
+ }
11463
+ // src/commands/doctor-shared-values/doctor-shared-values.command.ts
11464
+ const doctorSharedValuesArgs = (y) => y.option("strict", {
11465
+ type: "boolean",
11466
+ default: false,
11467
+ describe: "Fail (exit 1) when a secret holds the same value in two layers, instead of reporting it as info"
11468
+ }).option("allow", {
11469
+ type: "string",
11470
+ array: true,
11471
+ describe: "A name shared on purpose; repeat for more. `doctor.sharedVariables` in the config lists them too"
11472
+ });
11473
+ const doctorSharedValuesCommand = {
11474
+ command: "shared-values",
11475
+ describe: "Find secrets that hold the same value in two layers: local, dev, ci and prod (read-only, names only)",
11476
+ builder: doctorSharedValuesArgs,
11477
+ handler: async (argv) => {
11478
+ const tokens = tokenContext$1(argv.token);
11479
+ if (!tokens) return;
11480
+ const loaded = await loadConfig(argv.cwd);
11481
+ applyResolvedConfig(argv, loaded.resolved);
11482
+ if ((await runDoctorSharedValues({
11483
+ loaded,
11484
+ context: {
11485
+ repoRoot: argv.cwd,
11486
+ ...tokens,
11487
+ org: resolveOrg(argv, loaded.resolved)
11488
+ },
11489
+ strict: argv.strict === true,
11490
+ allow: argv.allow ?? []
11491
+ })).status === "fail") process.exitCode = 1;
11492
+ }
11493
+ };
11211
11494
  // src/commands/doctor-variable-owners/create-loaders.ts
11212
11495
  /**
11213
11496
  * The loader that lists an Environment's variable names. Built with `readCredentials: false`, so the `credentials`
@@ -11932,6 +12215,19 @@ const DEEP_CHECKS = [
11932
12215
  };
11933
12216
  }
11934
12217
  },
12218
+ {
12219
+ name: "shared-values",
12220
+ capability: "vault",
12221
+ command: doctorSharedValuesCommand,
12222
+ async run(input) {
12223
+ const report = await runDoctorSharedValues(input);
12224
+ return {
12225
+ status: report.status,
12226
+ summary: report.summary,
12227
+ ...report.reason ? { reason: report.reason } : {}
12228
+ };
12229
+ }
12230
+ },
11935
12231
  {
11936
12232
  name: "ci",
11937
12233
  capability: "source",