@theholocron/cli 5.0.0-alpha.416 → 5.0.0-alpha.417

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
@@ -14,7 +14,7 @@ import { ConfigError, ConfigError as ConfigError$1, createConfigSystem, lastWins
14
14
  import { LoaderError, assertPluginsResolvable, createPluginSystem, isModuleNotFound, resolvePluginPackage } from "@theholocron/kyber/plugins";
15
15
  import { DEFAULT_ORG, DOT_GITHUB_REPO, HOLOCRON_REPO, KNOWN_TASKS, KNOWN_WORKFLOWS, LEGACY_NAMES, PNPM_BUILTIN_COMMANDS, PRERELEASE_CHANNEL, RELEASE_BRANCHES, RESERVED_SCRIPT_NAMES, SUITES, TASKS, aggregateChecks, checkPackageScripts, createAlexignore, createAlexrc, createAstromech, createCommitMsg, createDco, createDependabot, createDevmoji, createEditorconfig, createEditorconfigChecker, createHeader, createLabeler, createPreCommit, createPrePush, createPrepareCommitMsg, createYamlignore, createYamllint, defaultListDirs, defaultPaths, defaultReadJson, deployOnRelease, describeTasks, extractPreviewConfig, frozenReusablePaths, generateThinCallerContent, hostedReusableWorkflows, isDeprecated, isTask, legacyCaller, legacyCallerFile, legacyGate, legacyWorkflowKey, localize, mergeScripts, readWorkspacePackages, resolveTaskName, reusableTemplates, scriptName, stampDeprecated, workflowFile, workflowKey, workflowKeys, workspacePackages } from "@theholocron/astromech";
16
16
  import { loadTasksConfig } from "@theholocron/astromech/config";
17
- import { readGitRemote, updateGitignore } from "@theholocron/git-utils";
17
+ import { readGitRemote, updateGitignore, upsertManagedBlock } from "@theholocron/git-utils";
18
18
  import { bumpCatalogPins, discoverWorkspacePackages, parseCatalogs, readPackageJson, readPackageJsonSync, resolveWorkspaceGlobs } from "@theholocron/pkg-utils";
19
19
  import { createCliLogger, createCliTelemetry } from "@theholocron/kyber/observability";
20
20
  import { resolveAxiomFromEnv } from "@theholocron/observability/logger";
@@ -22,8 +22,8 @@ import { Entry, findCredentials } from "@napi-rs/keyring";
22
22
  import { AuthError, DOTENV_FILE, copyToClipboard, createFeatureResolver, createKeyring, dotenvLine, findCredential, finishCredentialsFile, hasCredentials, isGitIgnored, readDotenvFile, resolveValue, resolveValue as resolveValue$2, setCredentials, writeCredentialsFile } from "@theholocron/kyber/secrets";
23
23
  import { errorMessage } from "@theholocron/misc-utils";
24
24
  import { runCheckAgainstUrl } from "@theholocron/kyber/checks";
25
- import { fileURLToPath, pathToFileURL } from "node:url";
26
25
  import { copyFileSync, existsSync, fstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
26
+ import { fileURLToPath, pathToFileURL } from "node:url";
27
27
  import { DRY_RUN_NOOP_EXIT_CODE, createCommandRegistry, createMenu, numeric } from "@theholocron/kyber/menu";
28
28
  import { promptForPositionals } from "@theholocron/kyber/prompts";
29
29
  import { Separator, checkbox, confirm, input, select } from "@inquirer/prompts";
@@ -748,8 +748,7 @@ function environmentLayers(slug, layer) {
748
748
  if (layer === "test") return [];
749
749
  const candidate = (suffix, optional) => ({
750
750
  name: layerEnvironment(slug, suffix),
751
- optional,
752
- legacy: false
751
+ optional
753
752
  });
754
753
  return layer === "local" ? [candidate(SUFFIX.local, true), candidate(SUFFIX.development, false)] : [candidate(SUFFIX[layer], false)];
755
754
  }
@@ -763,33 +762,21 @@ async function repoSlug(cwd, exec) {
763
762
  if (!remote) throw new ConfigError(`cannot derive the 1Password Environment name: the \`origin\` remote of ${cwd} is missing or not an owner/repo URL. Give the \`credentials\` provider an \`environment\` option to name it.`);
764
763
  return remote.slug;
765
764
  }
766
- // src/credentials-environments/legacy-environments/legacy-environments.ts
767
- const OLD_NAMES = ["Holocron", "Holocron - GitHub Actions variables"];
768
- /** The old Environment names, as candidates that are never reported when absent. */
769
- function legacyEnvironments() {
770
- return OLD_NAMES.map((name) => ({
771
- name,
772
- optional: true,
773
- legacy: true
774
- }));
775
- }
776
765
  // src/credentials-environments/resolve-environments/resolve-environments.ts
777
766
  /**
778
767
  * The Environments one `credentials` entry reads. An explicit name (the entry's `environment` option, else the shared
779
768
  * `credentials.environment`) is the only candidate and wins. Otherwise a deriving provider gets the names of its layer
780
- * (`environmentLayers()`) from the repo's `origin` and `detectEnvironment()`, followed by the migration fallback.
781
- * Nothing is read from a provider here. An empty list means there is nothing to read (the `test` layer).
769
+ * (`environmentLayers()`) from the repo's `origin` and `detectEnvironment()`. Nothing is read from a provider here. An empty list means there is nothing to read (the `test` layer).
782
770
  */
783
771
  async function resolveEnvironments(provider, explicit, input) {
784
772
  if (explicit !== void 0) return [{
785
773
  name: explicit,
786
- optional: false,
787
- legacy: false
774
+ optional: false
788
775
  }];
789
776
  if (!derivesEnvironment(provider)) return [];
790
777
  const layer = detectEnvironment(input.env);
791
778
  if (layer === "test") return [];
792
- return [...environmentLayers(await repoSlug(input.repoRoot, input.gitExec), layer), ...legacyEnvironments()];
779
+ return environmentLayers(await repoSlug(input.repoRoot, input.gitExec), layer);
793
780
  }
794
781
  // src/credentials-environments/try-environments/try-environments.ts
795
782
  /** A provider's "no such Environment": its API error with status 404 (`ProviderApiError`, matched by shape). */
@@ -798,29 +785,19 @@ function isNotFound(err) {
798
785
  }
799
786
  /**
800
787
  * Calls `attempt` for each candidate and sorts the answers into found and missing. A 404 is a miss; any other error
801
- * is thrown. A missing optional Environment is silent. When a required one is missing, the legacy candidates
802
- * (migration only, #2063) are tried too, and if one exists the miss is forgiven.
788
+ * is thrown. A missing optional Environment is silent; a missing required one is reported by name.
803
789
  */
804
790
  async function tryEnvironments(candidates, attempt) {
805
791
  const found = [];
806
792
  const missing = [];
807
- const ask = async (candidate) => {
808
- try {
809
- found.push({
810
- name: candidate.name,
811
- legacy: candidate.legacy,
812
- result: await attempt(candidate.name)
813
- });
814
- } catch (err) {
815
- if (!isNotFound(err)) throw err;
816
- if (!candidate.optional) missing.push(candidate.name);
817
- }
818
- };
819
- for (const candidate of candidates.filter((c) => !c.legacy)) await ask(candidate);
820
- if (missing.length > 0) {
821
- const before = found.length;
822
- for (const candidate of candidates.filter((c) => c.legacy)) await ask(candidate);
823
- if (found.length > before) missing.length = 0;
793
+ for (const candidate of candidates) try {
794
+ found.push({
795
+ name: candidate.name,
796
+ result: await attempt(candidate.name)
797
+ });
798
+ } catch (err) {
799
+ if (!isNotFound(err)) throw err;
800
+ if (!candidate.optional) missing.push(candidate.name);
824
801
  }
825
802
  return {
826
803
  found,
@@ -1423,6 +1400,48 @@ function actionsOf(plugin) {
1423
1400
  ...plugin.doctor ? { doctor: plugin.doctor } : {}
1424
1401
  };
1425
1402
  }
1403
+ // src/private-dir/ignore-advice/ignore-advice.ts
1404
+ /** The line that says how to fix a credentials path the version control ignore rules do not cover. */
1405
+ function ignoreAdvice(isDefault, choose) {
1406
+ return isDefault ? "the private directory's ignore rule is missing: run `holocron repo sync` to add it" : `add it to .gitignore, or ${choose}`;
1407
+ }
1408
+ // src/private-dir/private-dir.ts
1409
+ /** The directory, relative to the repository root, for files that hold secrets and must never be committed. */
1410
+ const PRIVATE_DIR = ".holocron/.private";
1411
+ /** The file `auth export` and `github-app create` write by default, relative to the repository root. */
1412
+ const PRIVATE_CREDENTIALS_FILE = `${PRIVATE_DIR}/.credentials`;
1413
+ /** The tracked file that keeps the otherwise ignored directory in the checkout. */
1414
+ const PRIVATE_KEEP_FILE = `${PRIVATE_DIR}/.gitkeep`;
1415
+ /**
1416
+ * The managed block `repo setup` and `repo sync` keep in `.gitignore`: everything in the private directory is ignored
1417
+ * except the `.gitkeep`. The start marker must not be a substring of the end marker.
1418
+ */
1419
+ const PRIVATE_IGNORE_BLOCK = {
1420
+ start: "# managed by holocron setup — private directory",
1421
+ end: "# end managed by holocron setup — private directory",
1422
+ lines: [`${PRIVATE_DIR}/*`, `!${PRIVATE_KEEP_FILE}`]
1423
+ };
1424
+ // src/private-dir/resolve-credentials-file/resolve-credentials-file.ts
1425
+ /**
1426
+ * The credentials file for a command: `file` (relative to `base`) when given, else `.holocron/.private/.credentials`
1427
+ * under `base`. The default's directory is created when missing (owner-only), because the ignore check can only ask
1428
+ * about a path whose directory exists and the file cannot be written without it.
1429
+ */
1430
+ function resolveCredentialsFile(base, file, makeDir = (dir) => void mkdirSync(dir, {
1431
+ recursive: true,
1432
+ mode: 448
1433
+ })) {
1434
+ if (file) return {
1435
+ path: resolve(base, file),
1436
+ isDefault: false
1437
+ };
1438
+ const path = resolve(base, PRIVATE_CREDENTIALS_FILE);
1439
+ makeDir(dirname(path));
1440
+ return {
1441
+ path,
1442
+ isDefault: true
1443
+ };
1444
+ }
1426
1445
  // src/commands/auth/auth.ts
1427
1446
  /**
1428
1447
  * `holocron auth <subcommand>` — manage bootstrap credentials in the
@@ -1892,8 +1911,6 @@ const doctorTokensCommand = {
1892
1911
  const COMMAND$8 = "auth export";
1893
1912
  /** Plain code-unit order: the same on every machine, whatever its locale. The names it sorts are all different. */
1894
1913
  const compare = (a, b) => a < b ? -1 : 1;
1895
- /** The file the lines go to on a terminal when none is named. */
1896
- const DEFAULT_FILE$1 = ".credentials";
1897
1914
  /** What a variable can be called in a dotenv file and in a shell. */
1898
1915
  const VARIABLE_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
1899
1916
  async function runAuthExport(input) {
@@ -2055,9 +2072,10 @@ async function runAuthExport(input) {
2055
2072
  destination = "clipboard";
2056
2073
  } else if (target === "file") {
2057
2074
  if ((input.platform ?? process.platform) === "win32") return refuse("windows", "cannot make the file private on Windows: its mode bits are not enforced, so other users may read it", "use `holocron auth export --copy`, or pipe the output to a tool");
2058
- file = resolve(dirname(input.loaded.filepath), input.file || DEFAULT_FILE$1);
2075
+ const target = resolveCredentialsFile(dirname(input.loaded.filepath), input.file, input.makeDir);
2076
+ file = target.path;
2059
2077
  const git = (input.isIgnored ?? isGitIgnored)(file);
2060
- if (git === "tracked" || git === "unknown") return refuse("not-ignored", git === "tracked" ? `refusing to write tokens to ${file}: git does not ignore it, so it could be committed` : `refusing to write tokens to ${file}: git could not say whether it ignores it`, "add it to .gitignore, or choose a path outside the repository with --file");
2078
+ if (git === "tracked" || git === "unknown") return refuse("not-ignored", git === "tracked" ? `refusing to write tokens to ${file}: git does not ignore it, so it could be committed` : `refusing to write tokens to ${file}: git could not say whether it ignores it`, ignoreAdvice(target.isDefault, "choose a path outside the repository with --file"));
2061
2079
  try {
2062
2080
  identity = (input.writeFile ?? writeCredentialsFile)(file, text, input.force === true);
2063
2081
  } catch (err) {
@@ -2127,7 +2145,7 @@ const authExportArgs = (yy) => yy.option("from-env", {
2127
2145
  describe: "Also take a token that is set in the environment (HOLOCRON_<X> or the vendor's name), ahead of the keyring"
2128
2146
  }).option("file", {
2129
2147
  type: "string",
2130
- describe: "Write the tokens to this private file (mode 0600; default .credentials, next to holocron.config) instead of stdout; on a terminal this is the default"
2148
+ describe: "Write the tokens to this private file (mode 0600; default .holocron/.private/.credentials) instead of stdout; on a terminal this is the default"
2131
2149
  }).option("only", {
2132
2150
  type: "string",
2133
2151
  array: true,
@@ -5370,7 +5388,7 @@ async function checkCredentials(input, loader) {
5370
5388
  /**
5371
5389
  * One row per expected variable, against the Environments the layer reads. A variable counts as present when any
5372
5390
  * Environment found holds it (the first found wins, as in the credential store). A required Environment that does not
5373
- * exist is a failing row of its own, by name; a missing `- local` is not mentioned; an old name in use is a skipped row.
5391
+ * exist is a failing row of its own, by name; a missing `- local` is not mentioned.
5374
5392
  */
5375
5393
  async function checkProvider(impl, candidates, expected) {
5376
5394
  const provider = impl.providerName;
@@ -5383,7 +5401,6 @@ async function checkProvider(impl, candidates, expected) {
5383
5401
  const rows = missing.map((name) => row$10(provider, "fail", `${provider} has no Environment named "${name}"`));
5384
5402
  const labels = found.map(({ name, result }) => result.environment === name ? `"${name}"` : `"${result.environment}" (the config writes "${name}")`);
5385
5403
  const where = labels.join(", ");
5386
- for (const { name, legacy } of found) if (legacy) rows.push(row$10(provider, "skip", `read from the old Environment name "${name}"; rename it`));
5387
5404
  if (found.length === 0) return rows;
5388
5405
  for (const { name, optional } of expected) {
5389
5406
  const at = found.findIndex((f) => f.result.names.includes(name));
@@ -12102,7 +12119,7 @@ const doctorCommand = {
12102
12119
  // src/commands/github-app-create/github-app-create.ts
12103
12120
  /**
12104
12121
  * `holocron github-app create` — create a GitHub App from a manifest (GitHub's manifest flow), and keep its
12105
- * credentials in the private `.credentials` file `auth export` uses, to import into a credentials environment.
12122
+ * credentials in the private `.holocron/.private/.credentials` file `auth export` uses, to import into a credentials environment.
12106
12123
  *
12107
12124
  * The flow has one click in it that cannot be done for you: a local page posts the manifest to GitHub, you press
12108
12125
  * "Create GitHub App", GitHub redirects back to a one-shot server on the loopback address with a code, and the code is
@@ -12111,7 +12128,6 @@ const doctorCommand = {
12111
12128
  * ever printed.
12112
12129
  */
12113
12130
  const COMMAND$5 = "github-app create";
12114
- const DEFAULT_FILE = ".credentials";
12115
12131
  const DEFAULT_WEBHOOK_SECRET_VAR = "SENTINEL_WEBHOOK_SECRET";
12116
12132
  async function runGithubAppCreate(input) {
12117
12133
  const print = input.print ?? ((line) => console.error(line));
@@ -12141,9 +12157,10 @@ async function runGithubAppCreate(input) {
12141
12157
  } catch (err) {
12142
12158
  return refuse("manifest", errorMessage(err));
12143
12159
  }
12144
- const file = resolve(input.dir, input.file || DEFAULT_FILE);
12160
+ const target = resolveCredentialsFile(input.dir, input.file, input.makeDir);
12161
+ const file = target.path;
12145
12162
  const git = (input.isIgnored ?? isGitIgnored)(file);
12146
- if (git === "tracked" || git === "unknown") return refuse("not-ignored", git === "tracked" ? `refusing to write credentials to ${file}: git does not ignore it, so it could be committed` : `refusing to write credentials to ${file}: git could not say whether it ignores it`, "add it to .gitignore, or choose another path with --file");
12163
+ if (git === "tracked" || git === "unknown") return refuse("not-ignored", git === "tracked" ? `refusing to write credentials to ${file}: git does not ignore it, so it could be committed` : `refusing to write credentials to ${file}: git could not say whether it ignores it`, ignoreAdvice(target.isDefault, "choose another path with --file"));
12147
12164
  if (!input.force && (input.exists ?? existsSync)(file)) return refuse("exists", `${file} is already there and is never overwritten`, "delete it, or pass --force to replace it");
12148
12165
  const state = input.state ?? randomBytes(16).toString("hex");
12149
12166
  const action = input.org ? `https://github.com/organizations/${encodeURIComponent(input.org)}/settings/apps/new?state=${state}` : `https://github.com/settings/apps/new?state=${state}`;
@@ -12233,7 +12250,7 @@ const githubAppCreateArgs = (yy) => yy.option("name", {
12233
12250
  describe: "The variable the webhook secret is written as"
12234
12251
  }).option("file", {
12235
12252
  type: "string",
12236
- describe: "Write the credentials to this private file (mode 0600; default .credentials)"
12253
+ describe: "Write the credentials to this private file (mode 0600; default .holocron/.private/.credentials)"
12237
12254
  }).option("keep", {
12238
12255
  type: "boolean",
12239
12256
  default: false,
@@ -18666,6 +18683,34 @@ async function generateConfigFiles(input) {
18666
18683
  }
18667
18684
  return entries;
18668
18685
  }
18686
+ // src/commands/repo-files/generate-private-dir-files.ts
18687
+ /**
18688
+ * The private directory for files that hold secrets (`.holocron/.private/`): an empty tracked `.gitkeep` that keeps it
18689
+ * in the checkout, and the managed block in `.gitignore` that ignores everything else in it. The block is merged into
18690
+ * the `.gitignore` already on disk, so the rest of the file (and the skills blocks `repo setup` keeps) is untouched.
18691
+ * `repo setup` and `repo sync` both write what this returns, so the bytes are the same from either.
18692
+ */
18693
+ async function generatePrivateDirFiles(input) {
18694
+ const existing = await readFile(join(input.repoRoot, ".gitignore"), "utf8").catch(() => "");
18695
+ return [{
18696
+ kind: "file",
18697
+ path: PRIVATE_KEEP_FILE,
18698
+ content: "",
18699
+ step: `write ${PRIVATE_KEEP_FILE}`,
18700
+ syncStep: `write ${PRIVATE_KEEP_FILE}`,
18701
+ note: "keeps the private directory in the checkout"
18702
+ }, {
18703
+ kind: "file",
18704
+ path: ".gitignore",
18705
+ content: upsertManagedBlock(existing, {
18706
+ ...PRIVATE_IGNORE_BLOCK,
18707
+ lines: PRIVATE_IGNORE_BLOCK.lines
18708
+ }),
18709
+ step: "write .gitignore",
18710
+ syncStep: "write .gitignore",
18711
+ note: "private directory block"
18712
+ }];
18713
+ }
18669
18714
  // src/commands/repo-files/generate-turbo-files.ts
18670
18715
  /**
18671
18716
  * `turbo.json`, and the two edits that go with it: `turbo.json` alone is inert unless the root is a workspace member
@@ -18970,7 +19015,8 @@ function generateWorkflowFiles(input) {
18970
19015
  // src/commands/repo-files/generate-repo-files.ts
18971
19016
  /**
18972
19017
  * Every file `holocron repo setup` writes to disk from the config alone, in the order it writes them: the thin-caller
18973
- * workflows, the config files, then `turbo.json` and its follow-up edits. No provider and no network, so a job without
19018
+ * workflows, the config files, the agent instructions block, the private directory (`.holocron/.private/.gitkeep` and its `.gitignore` block), then
19019
+ * `turbo.json` and its follow-up edits. No provider and no network, so a job without
18974
19020
  * a token can produce them, and `repo sync` takes the files it shares from here too. What setup reads from a provider
18975
19021
  * (CODEOWNERS, which needs the org, the installed skills, the agent prompts) is not here.
18976
19022
  */
@@ -18979,6 +19025,7 @@ async function generateRepoFiles(input) {
18979
19025
  ...generateWorkflowFiles(input),
18980
19026
  ...await generateConfigFiles(input),
18981
19027
  ...await generateAgentFiles(input),
19028
+ ...await generatePrivateDirFiles(input),
18982
19029
  ...await generateTurboFiles(input)
18983
19030
  ];
18984
19031
  }
@@ -23187,6 +23234,7 @@ const SYNC_STEPS = [
23187
23234
  "scripts",
23188
23235
  "turbo",
23189
23236
  "agents",
23237
+ "private",
23190
23238
  "wiki"
23191
23239
  ];
23192
23240
  const LOCAL_STEPS = /* @__PURE__ */ new Set([
@@ -23198,6 +23246,7 @@ const LOCAL_STEPS = /* @__PURE__ */ new Set([
23198
23246
  "scripts",
23199
23247
  "turbo",
23200
23248
  "agents",
23249
+ "private",
23201
23250
  "wiki"
23202
23251
  ]);
23203
23252
  async function runSync(input) {
@@ -23377,6 +23426,7 @@ async function runSync(input) {
23377
23426
  "scripts",
23378
23427
  "turbo",
23379
23428
  "agents",
23429
+ "private",
23380
23430
  "wiki"
23381
23431
  ]) {
23382
23432
  if (requestedSteps !== void 0 && !requestedSteps.includes(stepName)) continue;
@@ -23578,6 +23628,29 @@ async function runSync(input) {
23578
23628
  print(formatSyncStep(steps[steps.length - 1]));
23579
23629
  }
23580
23630
  }
23631
+ if (stepName === "private") {
23632
+ if (resolvedRepoRoot !== gitRoot) {
23633
+ steps.push({
23634
+ capability: "local",
23635
+ step: "sync private directory",
23636
+ status: "skip",
23637
+ message: "--cwd is a monorepo subpackage, not the git root — run from the root"
23638
+ });
23639
+ print(formatSyncStep(steps[steps.length - 1]));
23640
+ continue;
23641
+ }
23642
+ for (const entry of await generatePrivateDirFiles({
23643
+ loaded: input.loaded,
23644
+ repoRoot: input.context.repoRoot,
23645
+ logger
23646
+ })) {
23647
+ steps.push(await runSyncStep("local", entry.syncStep, dryRun, async () => {
23648
+ await mkdir(dirname(join(gitRoot, entry.path)), { recursive: true });
23649
+ await writeFile(join(gitRoot, entry.path), entry.content, "utf8");
23650
+ }));
23651
+ print(formatSyncStep(steps[steps.length - 1]));
23652
+ }
23653
+ }
23581
23654
  if (stepName === "wiki") {
23582
23655
  const result = await runSyncWiki({
23583
23656
  loaded: input.loaded,