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

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.
Files changed (3) hide show
  1. package/dist/cli.mjs +619 -517
  2. package/dist/cli.mjs.map +1 -1
  3. package/package.json +12 -12
package/dist/cli.mjs CHANGED
@@ -10791,6 +10791,456 @@ function docsCoverageProbes(repoRoot, typedoc = runTypedoc(repoRoot), diff = rea
10791
10791
  }
10792
10792
  };
10793
10793
  }
10794
+ // src/commands/probe/generated/constants.ts
10795
+ /**
10796
+ * Workflow files that no task generates and that are not marked `# HAND-MAINTAINED`, so the check would take them for
10797
+ * stale generated files. Each is intentional.
10798
+ */
10799
+ const UNMANAGED_WORKFLOWS = { "platform.syncTemplates.yml": "its task is not in the config yet, on purpose (see astromech.config.ts)" };
10800
+ // src/commands/probe/generated/check-generated.ts
10801
+ const WORKFLOWS_DIR = ".github/workflows/";
10802
+ /** Where two texts first differ: the line number and both lines, cut to fit a terminal. */
10803
+ function firstDifference(committed, generated) {
10804
+ const a = committed.split("\n");
10805
+ const b = generated.split("\n");
10806
+ const line = a.findIndex((text, i) => text !== b[i]);
10807
+ const at = line === -1 ? Math.min(a.length, b.length) : line;
10808
+ const cut = (text) => text === void 0 ? "(end of file)" : JSON.stringify(text.slice(0, 80));
10809
+ return `first difference at line ${at + 1}: committed ${cut(a[at])}, generated ${cut(b[at])}`;
10810
+ }
10811
+ /** The package whose config generated a workflow, from its `# Source package:` marker (`.` is the root). */
10812
+ function sourcePackage(text) {
10813
+ return /^# Source package: (.+)$/m.exec(text)?.[1] ?? null;
10814
+ }
10815
+ /**
10816
+ * Problems with the generated files, as human-readable lines: a file that differs from the committed copy or is
10817
+ * missing, a file whose second generation differs from the first, and a workflow that nothing generates and that is not
10818
+ * marked as someone else's (hand-maintained, from another package's config, or on the unmanaged list).
10819
+ */
10820
+ function checkGenerated({ files, again, read, workflows }) {
10821
+ const problems = [];
10822
+ const second = new Map(again.map((f) => [f.path, f.content]));
10823
+ for (const file of files) {
10824
+ const committed = read(file.path);
10825
+ if (committed === null) problems.push(`${file.path}: missing; run \`holocron repo setup\` or \`holocron repo sync\` and commit it`);
10826
+ else if (committed !== file.content) problems.push(`${file.path}: differs from what holocron generates (${firstDifference(committed, file.content)}); run \`holocron repo setup\` or \`holocron repo sync\` and commit the result`);
10827
+ if (second.get(file.path) !== file.content) problems.push(`${file.path}: generating it twice gives different content`);
10828
+ }
10829
+ const generated = new Set(files.map((f) => f.path));
10830
+ for (const [name, text] of workflows) {
10831
+ const path = `${WORKFLOWS_DIR}${name}`;
10832
+ if (generated.has(path) || name in UNMANAGED_WORKFLOWS || text.startsWith("# HAND-MAINTAINED")) continue;
10833
+ const source = sourcePackage(text);
10834
+ if (text.startsWith("# AUTO-GENERATED") && source !== null && source !== ".") continue;
10835
+ problems.push(`${path}: no task generates it and it is not marked "# HAND-MAINTAINED"; remove it, or mark it hand-maintained`);
10836
+ }
10837
+ return problems;
10838
+ }
10839
+ // src/templates/dco.yml
10840
+ var dco_default = "allowRemediationCommits:\n individual: true\n";
10841
+ // src/commands/setup/own-catalog-packages/own-catalog-packages.ts
10842
+ /**
10843
+ * The packages of this workspace that a pnpm catalog also lists: the minimum versions a plugin accepts
10844
+ * as a peer, say. Dependabot reads every catalog entry as an ordinary dependency and would raise it to the
10845
+ * latest release, but such an entry is a compatibility floor that is raised by hand, and the package itself
10846
+ * is linked with `workspace:`. A package from outside the workspace in a catalog is left out, so it keeps
10847
+ * getting updates. Sorted; `[]` when there is no `pnpm-workspace.yaml`.
10848
+ */
10849
+ function ownCatalogPackages(repoRoot) {
10850
+ let yaml;
10851
+ try {
10852
+ yaml = readFileSync(join(repoRoot, "pnpm-workspace.yaml"), "utf8");
10853
+ } catch {
10854
+ return [];
10855
+ }
10856
+ const listed = new Set(Object.values(parseCatalogs(yaml)).flatMap((catalog) => Object.keys(catalog)));
10857
+ const own = discoverWorkspacePackages(repoRoot).flatMap(({ name }) => name && listed.has(name) ? [name] : []);
10858
+ return [...new Set(own)].sort();
10859
+ }
10860
+ // src/commands/repo-files/hooks-enabled.ts
10861
+ /** Whether git hooks are installed: `--hooks` / `--no-hooks` wins, then `config.hooks`, then on for `protection: "strict"`. */
10862
+ function hooksEnabled(input) {
10863
+ const config = input.loaded.resolved;
10864
+ if (input.hooks !== void 0) return input.hooks;
10865
+ if (typeof config.hooks === "boolean") return config.hooks;
10866
+ if (typeof config.hooks === "object") return config.hooks.prePush !== false;
10867
+ return config.repo?.protection === "strict";
10868
+ }
10869
+ // src/commands/repo-files/generate-config-files.ts
10870
+ const { workflowHeader: workflowHeader$1 } = createHeader({
10871
+ source: "cli/cli/src/commands/repo-files/generate-config-files.ts",
10872
+ tool: "holocron repo setup"
10873
+ });
10874
+ function file(path, content, note) {
10875
+ const step = `write ${path}`;
10876
+ return {
10877
+ kind: "file",
10878
+ path,
10879
+ content,
10880
+ step,
10881
+ syncStep: step,
10882
+ ...note === void 0 ? {} : { note }
10883
+ };
10884
+ }
10885
+ /**
10886
+ * The config files that are not workflows: the labeler, Dependabot and DCO configs, the lint and editor configs, the
10887
+ * git hooks and `codecov.yml`, in the order `repo setup` writes them. `codecov.yml` is merged into the copy already on
10888
+ * disk, so the file is read here.
10889
+ */
10890
+ async function generateConfigFiles(input) {
10891
+ const config = input.loaded.resolved;
10892
+ const taskNames = (config.tasks ?? []).map((e) => typeof e === "string" ? e : e.name);
10893
+ const entries = [];
10894
+ if (taskNames.includes("bookkeeping")) entries.push(file(".github/labeler.yml", createLabeler()));
10895
+ if (config.repo?.protection !== "none") entries.push(file(".github/dependabot.yml", createDependabot({ ignore: ownCatalogPackages(input.repoRoot) })), file(".github/dco.yml", `${workflowHeader$1()}${dco_default}`));
10896
+ entries.push(file(".alexrc.json", createAlexrc()), file(".alexignore", createAlexignore()), file(".yamllint.yml", createYamllint()), file(".yamlignore", createYamlignore()), file(".editorconfig", createEditorconfig()), file(".editorconfig-checker.json", createEditorconfigChecker()), file("devmoji.config.cjs", createDevmoji()), file(".husky/prepare-commit-msg", createPrepareCommitMsg()), file(".husky/commit-msg", createCommitMsg(config.holocronScript)));
10897
+ if (hooksEnabled(input)) entries.push(file(".husky/pre-push", createPrePush(config.holocronScript), "runs `holocron run ci` before push — bypass with `git push --no-verify`"), file(".husky/pre-commit", createPreCommit(), "runs GitLeaks (staged-only) + lint-staged before commit"));
10898
+ else for (const hook of [".husky/pre-push", ".husky/pre-commit"]) entries.push({
10899
+ kind: "skip",
10900
+ step: `write ${hook}`,
10901
+ syncStep: `write ${hook}`,
10902
+ message: "git hooks disabled"
10903
+ });
10904
+ const existing = await readFile(join(input.repoRoot, "codecov.yml"), "utf8").catch(() => null);
10905
+ if (!taskNames.includes("verification.unitTests") && existing == null) entries.push({
10906
+ kind: "skip",
10907
+ step: "write codecov.yml",
10908
+ syncStep: "write codecov.yml",
10909
+ message: "no test workflow configured"
10910
+ });
10911
+ else try {
10912
+ const content = createAstromech({
10913
+ cwd: input.repoRoot,
10914
+ logger: input.logger ?? getLogger()
10915
+ }).codecovConfig(existing);
10916
+ const packageCount = readWorkspacePackages(input.repoRoot).length;
10917
+ entries.push(file("codecov.yml", content, packageCount > 0 ? `${packageCount} components` : "no components"));
10918
+ } catch (error) {
10919
+ entries.push({
10920
+ kind: "error",
10921
+ step: "write codecov.yml",
10922
+ syncStep: "write codecov.yml",
10923
+ message: errorMessage(error)
10924
+ });
10925
+ }
10926
+ return entries;
10927
+ }
10928
+ // src/commands/repo-files/generate-turbo-files.ts
10929
+ /**
10930
+ * `turbo.json`, and the two edits that go with it: `turbo.json` alone is inert unless the root is a workspace member
10931
+ * (#692) and turbo is a dependency, so `pnpm-workspace.yaml` and the root `package.json` are fixed in the same step that
10932
+ * introduces the risk. An edit is an entry only when it changes the file.
10933
+ */
10934
+ async function generateTurboFiles(input) {
10935
+ const astromech = createAstromech({
10936
+ cwd: input.repoRoot,
10937
+ config: { tasks: input.loaded.resolved.tasks },
10938
+ logger: input.logger ?? getLogger()
10939
+ });
10940
+ const content = astromech.turboConfig();
10941
+ if (content === null) return [{
10942
+ kind: "skip",
10943
+ step: "write turbo.json",
10944
+ syncStep: "sync turbo.json",
10945
+ message: "no fan-out-eligible tasks configured"
10946
+ }];
10947
+ const entries = [{
10948
+ kind: "file",
10949
+ path: "turbo.json",
10950
+ content,
10951
+ step: "write turbo.json",
10952
+ syncStep: "sync turbo.json"
10953
+ }];
10954
+ const rootPkgRaw = await readFile(join(input.repoRoot, "package.json"), "utf8").catch(() => null);
10955
+ const rootPkg = rootPkgRaw ? JSON.parse(rootPkgRaw) : null;
10956
+ const workspaceYaml = await readFile(join(input.repoRoot, "pnpm-workspace.yaml"), "utf8").catch(() => "");
10957
+ const workspaceFix = astromech.ensureRootWorkspaceMember(workspaceYaml, rootPkg?.scripts ?? {});
10958
+ if (workspaceFix.changed) {
10959
+ const step = "fix pnpm-workspace.yaml (root workspace member, #692)";
10960
+ entries.push({
10961
+ kind: "file",
10962
+ path: "pnpm-workspace.yaml",
10963
+ content: workspaceFix.content,
10964
+ step,
10965
+ syncStep: step
10966
+ });
10967
+ }
10968
+ if (rootPkgRaw) {
10969
+ const depFix = astromech.ensureTurboDependency(rootPkgRaw, workspaceFix.content);
10970
+ if (depFix.changed) entries.push({
10971
+ kind: "file",
10972
+ path: "package.json",
10973
+ content: depFix.content,
10974
+ step: "add turbo devDependency",
10975
+ syncStep: "add turbo devDependency"
10976
+ });
10977
+ }
10978
+ return entries;
10979
+ }
10980
+ // src/commands/preview-deploy-paths/preview-deploy-paths.ts
10981
+ /** `realpathSync`, falling back to the unresolved input on a path that doesn't exist (e.g. a test fixture). */
10982
+ function tryRealpath(path) {
10983
+ try {
10984
+ return realpathSync(path);
10985
+ } catch {
10986
+ return path;
10987
+ }
10988
+ }
10989
+ /**
10990
+ * `delivery.previewDeploy`'s package directory plus its `workspace:*`
10991
+ * dependencies' directories (holocron#1023) — the reusable workflow's
10992
+ * `paths` input, so a PR touching only an unrelated package in the
10993
+ * monorepo skips the actual deploy work instead of spinning up a Vercel
10994
+ * preview for every PR regardless of relevance. `undefined` for a
10995
+ * root-level consumer (`cwd: "."` or omitted) -- every PR already IS a PR
10996
+ * to that package, no filter needed -- or when `cwd` doesn't resolve to
10997
+ * any known workspace package (soft-skip; the caller leaves `paths`
10998
+ * unset rather than guessing).
10999
+ */
11000
+ function resolvePreviewDeployPaths(gitRoot, cwdValue) {
11001
+ if (!cwdValue || cwdValue === ".") return void 0;
11002
+ const all = workspacePackages(gitRoot, {
11003
+ readJson: defaultReadJson,
11004
+ listDirs: defaultListDirs
11005
+ });
11006
+ const target = tryRealpath(resolve(gitRoot, cwdValue));
11007
+ const pkg = all.find((candidate) => tryRealpath(candidate.dir) === target);
11008
+ if (!pkg) return void 0;
11009
+ return defaultPaths(gitRoot, pkg, all);
11010
+ }
11011
+ /**
11012
+ * Returns `tasks` unchanged unless it has a `delivery.previewDeploy` entry
11013
+ * with a non-root `with.cwd` and no `with.paths` of its own -- in which
11014
+ * case that one entry gets an auto-computed `paths` (see
11015
+ * {@link resolvePreviewDeployPaths}), added without mutating the input.
11016
+ * An explicit `with.paths` from the repo's own config always wins; this
11017
+ * only fills in what the repo didn't already specify.
11018
+ */
11019
+ function withAutoPreviewDeployPaths(tasks, gitRoot) {
11020
+ return tasks.map((entry) => {
11021
+ if (typeof entry === "string" || entry.name !== "delivery.previewDeploy") return entry;
11022
+ const cwdValue = entry.with?.["cwd"];
11023
+ if (typeof cwdValue !== "string" || entry.with?.["paths"] !== void 0) return entry;
11024
+ const paths = resolvePreviewDeployPaths(gitRoot, cwdValue);
11025
+ if (!paths) return entry;
11026
+ return {
11027
+ ...entry,
11028
+ with: {
11029
+ ...entry.with,
11030
+ paths
11031
+ }
11032
+ };
11033
+ });
11034
+ }
11035
+ // src/commands/thin-caller-file/thin-caller-file.ts
11036
+ const { workflowHeader } = createHeader({
11037
+ source: "cli/astromech/src/thin-callers.ts",
11038
+ tool: "holocron repo sync"
11039
+ });
11040
+ /**
11041
+ * The text of a generated thin-caller workflow: the AUTO-GENERATED header, the `# Source package:` marker (see
11042
+ * `resolvePkgRelPath`) and the workflow itself. Both `repo setup` and `repo sync` write their workflows through
11043
+ * this, so the file is the same whichever command wrote it.
11044
+ */
11045
+ function thinCallerFile(pkgRelPath, content) {
11046
+ return `${workflowHeader()}# Source package: ${pkgRelPath}\n\n${content}`;
11047
+ }
11048
+ // src/commands/workflow-source-marker/workflow-source-marker.ts
11049
+ /** `# Source package: <path>` line at the head of a generated thin-caller workflow — see {@link resolvePkgRelPath}. */
11050
+ const SOURCE_PACKAGE_MARKER = /^# Source package: (.+)$/m;
11051
+ /** Strip control characters (including ANSI escapes) before a value reaches a printed error message. */
11052
+ function sanitizeForDisplay(value) {
11053
+ return value.replace(/[\x00-\x1f\x7f]/g, "");
11054
+ }
11055
+ /**
11056
+ * Repo-root-relative path of the PACKAGE a workflow-writing command run is
11057
+ * scoped to — the directory holding the discovered `holocron.config.*`
11058
+ * (`configFilepath`), not necessarily `--cwd` itself. `loadConfig()` walks
11059
+ * up to find the config from any subdirectory ("every command is usable
11060
+ * from any subdirectory of a repo, not only its exact root"), so a `--cwd`
11061
+ * one level too deep would otherwise stamp a different marker than a later
11062
+ * run from the package's own root and misfire the collision check this
11063
+ * feeds (holocron#1026).
11064
+ *
11065
+ * "." for a root invocation, "apps/sentinel" for a subpackage. Normalized
11066
+ * to forward slashes so the same package produces the same marker on
11067
+ * Windows and POSIX. Throws if the result contains a line break — a path
11068
+ * containing one could otherwise break out of the `# Source package: `
11069
+ * comment line and inject arbitrary workflow YAML when the generated
11070
+ * content is later written. Not reachable through this CLI's own flows
11071
+ * (no code path writes a config file whose directory name contains a line
11072
+ * break), but cheap to reject outright rather than trust the filesystem.
11073
+ */
11074
+ function resolvePkgRelPath(gitRoot, configFilepath) {
11075
+ let root;
11076
+ try {
11077
+ root = realpathSync(gitRoot);
11078
+ } catch {
11079
+ root = gitRoot;
11080
+ }
11081
+ let configDir;
11082
+ try {
11083
+ configDir = realpathSync(dirname(configFilepath));
11084
+ } catch {
11085
+ configDir = dirname(configFilepath);
11086
+ }
11087
+ const pkgRelPath = (relative(root, configDir) || ".").split(sep).join("/");
11088
+ if (/[\r\n]/.test(pkgRelPath)) throw new Error(`refusing to use a package path containing a line break: ${JSON.stringify(pkgRelPath)}`);
11089
+ return pkgRelPath;
11090
+ }
11091
+ /**
11092
+ * Two different monorepo packages opting into the same generic task name
11093
+ * (e.g. both `apps/sentinel` and some future `apps/other` configuring
11094
+ * `delivery.previewDeploy`) would otherwise overwrite each other's
11095
+ * `.github/workflows/<task>.yml` on whichever package's write ran last —
11096
+ * only one package's behavior would ever actually run in CI, with no
11097
+ * signal that the other's was silently dropped (holocron#1026).
11098
+ *
11099
+ * Shared by both `holocron repo sync` (reads the file straight off local
11100
+ * disk) and `holocron repo setup` (reads it through the loaded `Source`
11101
+ * capability, which happens to be local disk too for the github plugin
11102
+ * today, but the interface doesn't promise that for every provider —
11103
+ * holocron#1068). The marker-parsing and error message are identical
11104
+ * either way; `readExisting` is how the two callers differ.
11105
+ *
11106
+ * A file with no marker at all predates this check (or was written before
11107
+ * #1026) and is never flagged — only a marker that's present AND disagrees
11108
+ * with the current run's own package is a real collision. `readExisting`
11109
+ * returning `null` means "nothing there," not "unreadable" — a caller
11110
+ * whose underlying read can fail for reasons other than "doesn't exist"
11111
+ * (e.g. local fs EISDIR) is expected to let that error propagate out of
11112
+ * `readExisting` itself rather than mapping it to `null`.
11113
+ */
11114
+ async function assertNoPackageCollision(taskName, pkgRelPath, filename, readExisting) {
11115
+ const existing = await readExisting();
11116
+ if (existing === null) return;
11117
+ const previousPkg = SOURCE_PACKAGE_MARKER.exec(existing)?.[1];
11118
+ if (previousPkg !== void 0 && previousPkg !== pkgRelPath) throw new Error(`task "${taskName}" would overwrite .github/workflows/${filename}, already generated for package "${sanitizeForDisplay(previousPkg)}" — the same task name can't be used by two different packages (holocron#1026). If "${sanitizeForDisplay(previousPkg)}" moved or was renamed to this path, delete .github/workflows/${filename} first and re-run this command; otherwise rename one or give it a different thin-caller filename.`);
11119
+ }
11120
+ // src/commands/repo-files/generate-workflow-files.ts
11121
+ /**
11122
+ * The thin-caller workflow for each task in the manifest, in the manifest's order. A task with no template is a
11123
+ * skipped entry, and a task with `ci: false` has no file. Nothing here is remote: astromech renders every file from the
11124
+ * manifest (the linter set, deploy paths, deploy and preview), and a bad manifest throws.
11125
+ */
11126
+ function generateWorkflowFiles(input) {
11127
+ const config = input.loaded.resolved;
11128
+ if (!config.tasks || config.tasks.length === 0) return [];
11129
+ const gitRoot = findRootSync(input.repoRoot, ".git", {
11130
+ fallback: "start",
11131
+ realpath: true
11132
+ });
11133
+ const pkgRelPath = resolvePkgRelPath(gitRoot, input.loaded.filepath);
11134
+ const tasks = withAutoPreviewDeployPaths(config.tasks, gitRoot);
11135
+ const files = createAstromech({
11136
+ cwd: input.repoRoot,
11137
+ config: { tasks },
11138
+ orgContext: {
11139
+ org: config.org,
11140
+ domain: config.domain
11141
+ },
11142
+ logger: input.logger ?? getLogger()
11143
+ }).thinCallers();
11144
+ const entries = [];
11145
+ for (const entry of tasks) {
11146
+ const name = typeof entry === "string" ? entry : entry.name;
11147
+ const isCombinedContentOnly = name === "knowledge.docs" || name === "knowledge.components";
11148
+ if (!KNOWN_WORKFLOWS.has(name) && !isCombinedContentOnly) {
11149
+ entries.push({
11150
+ kind: "skip",
11151
+ step: `write workflow ${name}`,
11152
+ syncStep: `sync workflow ${name}`,
11153
+ message: `unknown workflow "${name}" — no template available`
11154
+ });
11155
+ continue;
11156
+ }
11157
+ const filename = `${name}.yml`;
11158
+ const content = files.get(filename);
11159
+ if (content === void 0) continue;
11160
+ const preview = content.includes("workflows/preview.yml@main") ? " (with preview)" : "";
11161
+ entries.push({
11162
+ kind: "file",
11163
+ path: `.github/workflows/${filename}`,
11164
+ content: thinCallerFile(pkgRelPath, content),
11165
+ step: `write workflow ${name}${preview}`,
11166
+ syncStep: `sync workflow ${name}${preview}`,
11167
+ workflow: {
11168
+ task: name,
11169
+ filename
11170
+ }
11171
+ });
11172
+ }
11173
+ return entries;
11174
+ }
11175
+ // src/commands/repo-files/generate-repo-files.ts
11176
+ /**
11177
+ * Every file `holocron repo setup` writes to disk from the config alone, in the order it writes them: the thin-caller
11178
+ * workflows, the config files, then `turbo.json` and its follow-up edits. No provider and no network, so a job without
11179
+ * a token can produce them, and `repo sync` takes the files it shares from here too. What setup reads from a provider
11180
+ * (CODEOWNERS, which needs the org, the installed skills, the agent prompts) is not here.
11181
+ */
11182
+ async function generateRepoFiles(input) {
11183
+ return [
11184
+ ...generateWorkflowFiles(input),
11185
+ ...await generateConfigFiles(input),
11186
+ ...await generateTurboFiles(input)
11187
+ ];
11188
+ }
11189
+ // src/commands/probe/generated/generated-probes.ts
11190
+ /** The group of probes that check the files `repo setup` and `repo sync` generate. */
11191
+ const GENERATED_PROVIDER = "generated";
11192
+ function readText(path) {
11193
+ try {
11194
+ return readFileSync(path, "utf8");
11195
+ } catch {
11196
+ return null;
11197
+ }
11198
+ }
11199
+ async function generate(input) {
11200
+ const entries = await generateRepoFiles(input);
11201
+ return {
11202
+ files: entries.filter((e) => e.kind === "file"),
11203
+ errors: entries.flatMap((e) => e.kind === "error" ? [`${e.step}: ${e.message}`] : [])
11204
+ };
11205
+ }
11206
+ /**
11207
+ * `generated check` generates every file `repo setup` writes from the config alone (no provider, no token), twice, and
11208
+ * fails for each one that differs from the committed copy, differs the second time, or is a workflow nothing
11209
+ * generates. CI runs it, so a change to a generator or to the config that was not followed by a run of `repo setup`
11210
+ * or `repo sync` cannot merge.
11211
+ */
11212
+ function generatedProbes(loaded, repoRoot) {
11213
+ return { check: {
11214
+ summary: "Fail for each generated file that differs from the committed copy (CI runs this).",
11215
+ writes: false,
11216
+ async run(ctx) {
11217
+ const input = {
11218
+ loaded,
11219
+ repoRoot
11220
+ };
11221
+ const first = await generate(input);
11222
+ const second = await generate(input);
11223
+ const workflowsDir = join(repoRoot, ".github", "workflows");
11224
+ const workflows = /* @__PURE__ */ new Map();
11225
+ for (const name of readdirSync(workflowsDir).filter((n) => n.endsWith(".yml")).sort()) workflows.set(name, readFileSync(join(workflowsDir, name), "utf8"));
11226
+ const problems = [...first.errors, ...checkGenerated({
11227
+ files: first.files,
11228
+ again: second.files,
11229
+ read: (path) => readText(join(repoRoot, path)),
11230
+ workflows
11231
+ })];
11232
+ for (const line of problems) ctx.say({
11233
+ status: "fail",
11234
+ label: line
11235
+ });
11236
+ if (problems.length === 0) ctx.say({
11237
+ status: "ok",
11238
+ label: `${first.files.length} files`,
11239
+ detail: "all match what holocron generates"
11240
+ });
11241
+ }
11242
+ } };
11243
+ }
10794
11244
  // src/commands/probe/list-probes.ts
10795
11245
  /** The listing `holocron probe` prints: each provider, and under it each probe with its summary; writers are marked. */
10796
11246
  function listProbes(groups) {
@@ -10977,6 +11427,7 @@ async function runProbeCommand(input) {
10977
11427
  groups.set(COMLINK_PROVIDER, comlink);
10978
11428
  groups.set(DOCS_PROVIDER, docsCoverageProbes(input.context.repoRoot, input.typedoc));
10979
11429
  groups.set(DEPS_PROVIDER, depsProbes(input.context.repoRoot, print));
11430
+ groups.set(GENERATED_PROVIDER, generatedProbes(input.loaded, input.context.repoRoot));
10980
11431
  if (!input.provider) {
10981
11432
  if (input.pick) await input.pick(groups);
10982
11433
  else for (const line of listProbes(groups)) print(line);
@@ -11118,261 +11569,119 @@ function deriveCapabilities(providers) {
11118
11569
  * a Phase B (GitHub App) refinement once it can post *why* on a check run.
11119
11570
  */
11120
11571
  const REQUIRED_BASELINE = ["source", "ci"];
11121
- function deriveCompliance(capabilities) {
11122
- return REQUIRED_BASELINE.every((key) => capabilities.includes(key)) ? "compliant" : "non-compliant";
11123
- }
11124
- /**
11125
- * Reads each workspace package's actual `package.json` content (not just
11126
- * `readWorkspacePackages()`'s `{ slug, name, dir }` — `deriveProfile()`'s
11127
- * `platform` detection needs `bin`, which that helper doesn't carry).
11128
- * Missing/invalid files are skipped, matching `readWorkspacePackages()`'s
11129
- * own soft-fail behavior.
11130
- */
11131
- async function readWorkspacePackageJsons(repoRoot, workspacePackages) {
11132
- const results = [];
11133
- for (const { slug, dir = "packages", path } of workspacePackages) {
11134
- const pkg = await readPackageJson(join(repoRoot, path ?? join(dir, slug)));
11135
- if (pkg) results.push(pkg);
11136
- }
11137
- return results;
11138
- }
11139
- // src/commands/setup/labels.ts
11140
- const CANONICAL_LABELS = [
11141
- {
11142
- name: "bug",
11143
- color: "d73a4a",
11144
- description: "Something isn't working"
11145
- },
11146
- {
11147
- name: "chore",
11148
- color: "ededed",
11149
- description: "Maintenance, no user-facing change"
11150
- },
11151
- {
11152
- name: "ci",
11153
- color: "0075ca",
11154
- description: "CI/CD pipeline changes"
11155
- },
11156
- {
11157
- name: "dependencies",
11158
- color: "0366d6",
11159
- description: "Dependency update"
11160
- },
11161
- {
11162
- name: "documentation",
11163
- color: "0075ca",
11164
- description: "Documentation only"
11165
- },
11166
- {
11167
- name: "duplicate",
11168
- color: "cfd3d7",
11169
- description: "Already reported"
11170
- },
11171
- {
11172
- name: "enhancement",
11173
- color: "a2eeef",
11174
- description: "New feature or request"
11175
- },
11176
- {
11177
- name: "good first issue",
11178
- color: "7057ff",
11179
- description: "Good for newcomers"
11180
- },
11181
- {
11182
- name: "help wanted",
11183
- color: "008672",
11184
- description: "Extra attention needed"
11185
- },
11186
- {
11187
- name: "invalid",
11188
- color: "e4e669",
11189
- description: "Doesn't seem right"
11190
- },
11191
- {
11192
- name: "performance",
11193
- color: "fbca04",
11194
- description: "Performance improvement"
11195
- },
11196
- {
11197
- name: "question",
11198
- color: "d876e3",
11199
- description: "Further information requested"
11200
- },
11201
- {
11202
- name: "refactor",
11203
- color: "cfd3d7",
11204
- description: "Code restructuring"
11205
- },
11206
- {
11207
- name: "released",
11208
- color: "ededed",
11209
- description: "Included in a release"
11210
- },
11211
- {
11212
- name: "test",
11213
- color: "bfd4f2",
11214
- description: "Test-related changes"
11215
- },
11216
- {
11217
- name: "triage",
11218
- color: "e4e669",
11219
- description: "Needs investigation"
11220
- },
11221
- {
11222
- name: "wontfix",
11223
- color: "ffffff",
11224
- description: "Won't be addressed"
11225
- }
11226
- ];
11227
- const STALE_LABELS = [
11228
- "github_actions",
11229
- "javascript",
11230
- "autorelease: pending",
11231
- "autorelease: tagged",
11232
- "released on @alpha"
11233
- ];
11234
- // src/templates/dco.yml
11235
- var dco_default = "allowRemediationCommits:\n individual: true\n";
11236
- // src/commands/preview-deploy-paths/preview-deploy-paths.ts
11237
- /** `realpathSync`, falling back to the unresolved input on a path that doesn't exist (e.g. a test fixture). */
11238
- function tryRealpath(path) {
11239
- try {
11240
- return realpathSync(path);
11241
- } catch {
11242
- return path;
11243
- }
11244
- }
11245
- /**
11246
- * `delivery.previewDeploy`'s package directory plus its `workspace:*`
11247
- * dependencies' directories (holocron#1023) — the reusable workflow's
11248
- * `paths` input, so a PR touching only an unrelated package in the
11249
- * monorepo skips the actual deploy work instead of spinning up a Vercel
11250
- * preview for every PR regardless of relevance. `undefined` for a
11251
- * root-level consumer (`cwd: "."` or omitted) -- every PR already IS a PR
11252
- * to that package, no filter needed -- or when `cwd` doesn't resolve to
11253
- * any known workspace package (soft-skip; the caller leaves `paths`
11254
- * unset rather than guessing).
11255
- */
11256
- function resolvePreviewDeployPaths(gitRoot, cwdValue) {
11257
- if (!cwdValue || cwdValue === ".") return void 0;
11258
- const all = workspacePackages(gitRoot, {
11259
- readJson: defaultReadJson,
11260
- listDirs: defaultListDirs
11261
- });
11262
- const target = tryRealpath(resolve(gitRoot, cwdValue));
11263
- const pkg = all.find((candidate) => tryRealpath(candidate.dir) === target);
11264
- if (!pkg) return void 0;
11265
- return defaultPaths(gitRoot, pkg, all);
11266
- }
11267
- /**
11268
- * Returns `tasks` unchanged unless it has a `delivery.previewDeploy` entry
11269
- * with a non-root `with.cwd` and no `with.paths` of its own -- in which
11270
- * case that one entry gets an auto-computed `paths` (see
11271
- * {@link resolvePreviewDeployPaths}), added without mutating the input.
11272
- * An explicit `with.paths` from the repo's own config always wins; this
11273
- * only fills in what the repo didn't already specify.
11274
- */
11275
- function withAutoPreviewDeployPaths(tasks, gitRoot) {
11276
- return tasks.map((entry) => {
11277
- if (typeof entry === "string" || entry.name !== "delivery.previewDeploy") return entry;
11278
- const cwdValue = entry.with?.["cwd"];
11279
- if (typeof cwdValue !== "string" || entry.with?.["paths"] !== void 0) return entry;
11280
- const paths = resolvePreviewDeployPaths(gitRoot, cwdValue);
11281
- if (!paths) return entry;
11282
- return {
11283
- ...entry,
11284
- with: {
11285
- ...entry.with,
11286
- paths
11287
- }
11288
- };
11289
- });
11290
- }
11291
- // src/commands/thin-caller-file/thin-caller-file.ts
11292
- const { workflowHeader: workflowHeader$1 } = createHeader({
11293
- source: "cli/astromech/src/thin-callers.ts",
11294
- tool: "holocron repo sync"
11295
- });
11296
- /**
11297
- * The text of a generated thin-caller workflow: the AUTO-GENERATED header, the `# Source package:` marker (see
11298
- * `resolvePkgRelPath`) and the workflow itself. Both `repo setup` and `repo sync` write their workflows through
11299
- * this, so the file is the same whichever command wrote it.
11300
- */
11301
- function thinCallerFile(pkgRelPath, content) {
11302
- return `${workflowHeader$1()}# Source package: ${pkgRelPath}\n\n${content}`;
11303
- }
11304
- // src/commands/workflow-source-marker/workflow-source-marker.ts
11305
- /** `# Source package: <path>` line at the head of a generated thin-caller workflow — see {@link resolvePkgRelPath}. */
11306
- const SOURCE_PACKAGE_MARKER = /^# Source package: (.+)$/m;
11307
- /** Strip control characters (including ANSI escapes) before a value reaches a printed error message. */
11308
- function sanitizeForDisplay(value) {
11309
- return value.replace(/[\x00-\x1f\x7f]/g, "");
11310
- }
11311
- /**
11312
- * Repo-root-relative path of the PACKAGE a workflow-writing command run is
11313
- * scoped to — the directory holding the discovered `holocron.config.*`
11314
- * (`configFilepath`), not necessarily `--cwd` itself. `loadConfig()` walks
11315
- * up to find the config from any subdirectory ("every command is usable
11316
- * from any subdirectory of a repo, not only its exact root"), so a `--cwd`
11317
- * one level too deep would otherwise stamp a different marker than a later
11318
- * run from the package's own root and misfire the collision check this
11319
- * feeds (holocron#1026).
11320
- *
11321
- * "." for a root invocation, "apps/sentinel" for a subpackage. Normalized
11322
- * to forward slashes so the same package produces the same marker on
11323
- * Windows and POSIX. Throws if the result contains a line break — a path
11324
- * containing one could otherwise break out of the `# Source package: `
11325
- * comment line and inject arbitrary workflow YAML when the generated
11326
- * content is later written. Not reachable through this CLI's own flows
11327
- * (no code path writes a config file whose directory name contains a line
11328
- * break), but cheap to reject outright rather than trust the filesystem.
11329
- */
11330
- function resolvePkgRelPath(gitRoot, configFilepath) {
11331
- let root;
11332
- try {
11333
- root = realpathSync(gitRoot);
11334
- } catch {
11335
- root = gitRoot;
11336
- }
11337
- let configDir;
11338
- try {
11339
- configDir = realpathSync(dirname(configFilepath));
11340
- } catch {
11341
- configDir = dirname(configFilepath);
11342
- }
11343
- const pkgRelPath = (relative(root, configDir) || ".").split(sep).join("/");
11344
- if (/[\r\n]/.test(pkgRelPath)) throw new Error(`refusing to use a package path containing a line break: ${JSON.stringify(pkgRelPath)}`);
11345
- return pkgRelPath;
11346
- }
11347
- /**
11348
- * Two different monorepo packages opting into the same generic task name
11349
- * (e.g. both `apps/sentinel` and some future `apps/other` configuring
11350
- * `delivery.previewDeploy`) would otherwise overwrite each other's
11351
- * `.github/workflows/<task>.yml` on whichever package's write ran last —
11352
- * only one package's behavior would ever actually run in CI, with no
11353
- * signal that the other's was silently dropped (holocron#1026).
11354
- *
11355
- * Shared by both `holocron repo sync` (reads the file straight off local
11356
- * disk) and `holocron repo setup` (reads it through the loaded `Source`
11357
- * capability, which happens to be local disk too for the github plugin
11358
- * today, but the interface doesn't promise that for every provider —
11359
- * holocron#1068). The marker-parsing and error message are identical
11360
- * either way; `readExisting` is how the two callers differ.
11361
- *
11362
- * A file with no marker at all predates this check (or was written before
11363
- * #1026) and is never flagged — only a marker that's present AND disagrees
11364
- * with the current run's own package is a real collision. `readExisting`
11365
- * returning `null` means "nothing there," not "unreadable" — a caller
11366
- * whose underlying read can fail for reasons other than "doesn't exist"
11367
- * (e.g. local fs EISDIR) is expected to let that error propagate out of
11368
- * `readExisting` itself rather than mapping it to `null`.
11572
+ function deriveCompliance(capabilities) {
11573
+ return REQUIRED_BASELINE.every((key) => capabilities.includes(key)) ? "compliant" : "non-compliant";
11574
+ }
11575
+ /**
11576
+ * Reads each workspace package's actual `package.json` content (not just
11577
+ * `readWorkspacePackages()`'s `{ slug, name, dir }` — `deriveProfile()`'s
11578
+ * `platform` detection needs `bin`, which that helper doesn't carry).
11579
+ * Missing/invalid files are skipped, matching `readWorkspacePackages()`'s
11580
+ * own soft-fail behavior.
11369
11581
  */
11370
- async function assertNoPackageCollision(taskName, pkgRelPath, filename, readExisting) {
11371
- const existing = await readExisting();
11372
- if (existing === null) return;
11373
- const previousPkg = SOURCE_PACKAGE_MARKER.exec(existing)?.[1];
11374
- if (previousPkg !== void 0 && previousPkg !== pkgRelPath) throw new Error(`task "${taskName}" would overwrite .github/workflows/${filename}, already generated for package "${sanitizeForDisplay(previousPkg)}" — the same task name can't be used by two different packages (holocron#1026). If "${sanitizeForDisplay(previousPkg)}" moved or was renamed to this path, delete .github/workflows/${filename} first and re-run this command; otherwise rename one or give it a different thin-caller filename.`);
11582
+ async function readWorkspacePackageJsons(repoRoot, workspacePackages) {
11583
+ const results = [];
11584
+ for (const { slug, dir = "packages", path } of workspacePackages) {
11585
+ const pkg = await readPackageJson(join(repoRoot, path ?? join(dir, slug)));
11586
+ if (pkg) results.push(pkg);
11587
+ }
11588
+ return results;
11375
11589
  }
11590
+ // src/commands/setup/labels.ts
11591
+ const CANONICAL_LABELS = [
11592
+ {
11593
+ name: "bug",
11594
+ color: "d73a4a",
11595
+ description: "Something isn't working"
11596
+ },
11597
+ {
11598
+ name: "chore",
11599
+ color: "ededed",
11600
+ description: "Maintenance, no user-facing change"
11601
+ },
11602
+ {
11603
+ name: "ci",
11604
+ color: "0075ca",
11605
+ description: "CI/CD pipeline changes"
11606
+ },
11607
+ {
11608
+ name: "dependencies",
11609
+ color: "0366d6",
11610
+ description: "Dependency update"
11611
+ },
11612
+ {
11613
+ name: "documentation",
11614
+ color: "0075ca",
11615
+ description: "Documentation only"
11616
+ },
11617
+ {
11618
+ name: "duplicate",
11619
+ color: "cfd3d7",
11620
+ description: "Already reported"
11621
+ },
11622
+ {
11623
+ name: "enhancement",
11624
+ color: "a2eeef",
11625
+ description: "New feature or request"
11626
+ },
11627
+ {
11628
+ name: "good first issue",
11629
+ color: "7057ff",
11630
+ description: "Good for newcomers"
11631
+ },
11632
+ {
11633
+ name: "help wanted",
11634
+ color: "008672",
11635
+ description: "Extra attention needed"
11636
+ },
11637
+ {
11638
+ name: "invalid",
11639
+ color: "e4e669",
11640
+ description: "Doesn't seem right"
11641
+ },
11642
+ {
11643
+ name: "performance",
11644
+ color: "fbca04",
11645
+ description: "Performance improvement"
11646
+ },
11647
+ {
11648
+ name: "question",
11649
+ color: "d876e3",
11650
+ description: "Further information requested"
11651
+ },
11652
+ {
11653
+ name: "refactor",
11654
+ color: "cfd3d7",
11655
+ description: "Code restructuring"
11656
+ },
11657
+ {
11658
+ name: "released",
11659
+ color: "ededed",
11660
+ description: "Included in a release"
11661
+ },
11662
+ {
11663
+ name: "test",
11664
+ color: "bfd4f2",
11665
+ description: "Test-related changes"
11666
+ },
11667
+ {
11668
+ name: "triage",
11669
+ color: "e4e669",
11670
+ description: "Needs investigation"
11671
+ },
11672
+ {
11673
+ name: "wontfix",
11674
+ color: "ffffff",
11675
+ description: "Won't be addressed"
11676
+ }
11677
+ ];
11678
+ const STALE_LABELS = [
11679
+ "github_actions",
11680
+ "javascript",
11681
+ "autorelease: pending",
11682
+ "autorelease: tagged",
11683
+ "released on @alpha"
11684
+ ];
11376
11685
  // src/commands/setup/agent-prompts-data.ts
11377
11686
  /**
11378
11687
  * Canonical AI engineering workflow role prompts.
@@ -11917,25 +12226,6 @@ async function installEngineeringStructure({ repoRoot }) {
11917
12226
  for (const [path, content] of writes) if (await writeIfAbsent(path, content)) results.push(path.replace(repoRoot + "/", ""));
11918
12227
  return results.length > 0 ? `created: ${results.join(", ")}` : "all files already exist — nothing to write";
11919
12228
  }
11920
- // src/commands/setup/own-catalog-packages/own-catalog-packages.ts
11921
- /**
11922
- * The packages of this workspace that a pnpm catalog also lists: the minimum versions a plugin accepts
11923
- * as a peer, say. Dependabot reads every catalog entry as an ordinary dependency and would raise it to the
11924
- * latest release, but such an entry is a compatibility floor that is raised by hand, and the package itself
11925
- * is linked with `workspace:`. A package from outside the workspace in a catalog is left out, so it keeps
11926
- * getting updates. Sorted; `[]` when there is no `pnpm-workspace.yaml`.
11927
- */
11928
- function ownCatalogPackages(repoRoot) {
11929
- let yaml;
11930
- try {
11931
- yaml = readFileSync(join(repoRoot, "pnpm-workspace.yaml"), "utf8");
11932
- } catch {
11933
- return [];
11934
- }
11935
- const listed = new Set(Object.values(parseCatalogs(yaml)).flatMap((catalog) => Object.keys(catalog)));
11936
- const own = discoverWorkspacePackages(repoRoot).flatMap(({ name }) => name && listed.has(name) ? [name] : []);
11937
- return [...new Set(own)].sort();
11938
- }
11939
12229
  // src/commands/setup/repo-settings.ts
11940
12230
  const BALANCED_REPO_SETTINGS = {
11941
12231
  allow_squash_merge: true,
@@ -12213,10 +12503,6 @@ async function updateSkillsGitignore(gitignorePath, skills, symlinkFn) {
12213
12503
  * extensible but pushes the same knowledge into N plugins instead of
12214
12504
  * one central place.
12215
12505
  */
12216
- const { workflowHeader } = createHeader({
12217
- source: "cli/cli/src/commands/setup/run-setup.ts",
12218
- tool: "holocron repo setup"
12219
- });
12220
12506
  async function runSetup(input) {
12221
12507
  const print = input.print ?? ((line) => console.log(line));
12222
12508
  const logger = getLogger();
@@ -12228,12 +12514,10 @@ async function runSetup(input) {
12228
12514
  const steps = [];
12229
12515
  const repo = config.repo;
12230
12516
  const effectivePreset = repo?.protection;
12231
- const setupGitRoot = findRootSync(input.context.repoRoot, ".git", {
12517
+ const setupPkgRelPath = resolvePkgRelPath(findRootSync(input.context.repoRoot, ".git", {
12232
12518
  fallback: "start",
12233
12519
  realpath: true
12234
- });
12235
- const setupPkgRelPath = resolvePkgRelPath(setupGitRoot, input.loaded.filepath);
12236
- const hooksEnabled = input.hooks ?? (typeof config.hooks === "boolean" ? config.hooks : typeof config.hooks === "object" ? config.hooks.prePush !== false : effectivePreset === "strict");
12520
+ }), input.loaded.filepath);
12237
12521
  print(style.header(`Holocron setup — ${config.name}${dryRun ? " (dry-run)" : ""}`));
12238
12522
  print(style.dim(` config: ${input.loaded.filepath}`));
12239
12523
  print("");
@@ -12281,187 +12565,43 @@ async function runSetup(input) {
12281
12565
  print(formatStep(steps[steps.length - 1]));
12282
12566
  }
12283
12567
  }
12284
- const tasks = config.tasks && config.tasks.length > 0 ? withAutoPreviewDeployPaths(config.tasks, setupGitRoot) : config.tasks;
12285
- if (loader.has("source") && tasks && tasks.length > 0) {
12286
- const source = loader.get("source");
12287
- print(style.step("workflows"));
12288
- const files = createAstromech({
12289
- cwd: input.context.repoRoot,
12290
- config: { tasks },
12291
- orgContext: {
12292
- org: config.org,
12293
- domain: config.domain
12294
- },
12295
- logger
12296
- }).thinCallers();
12297
- for (const entry of tasks) {
12298
- const name = typeof entry === "string" ? entry : entry.name;
12299
- const isCombinedContentOnly = name === "knowledge.docs" || name === "knowledge.components";
12300
- if (!KNOWN_WORKFLOWS.has(name) && !isCombinedContentOnly) {
12301
- steps.push({
12302
- capability: "source",
12303
- step: `write workflow ${name}`,
12304
- status: "skip",
12305
- message: `unknown workflow "${name}" — no template available`
12306
- });
12307
- print(formatStep(steps[steps.length - 1]));
12308
- continue;
12309
- }
12310
- const filename = `${name}.yml`;
12311
- const content = files.get(filename);
12312
- if (content === void 0) continue;
12313
- const step = content.includes("workflows/preview.yml@main") ? `write workflow ${name} (with preview)` : `write workflow ${name}`;
12314
- steps.push(await runStep("source", step, dryRun, async () => {
12315
- await assertNoPackageCollision(name, setupPkgRelPath, filename, () => source.readWorkflowFile(filename));
12316
- await source.writeWorkflowFile(filename, thinCallerFile(setupPkgRelPath, content));
12317
- }));
12318
- print(formatStep(steps[steps.length - 1]));
12319
- }
12320
- }
12321
- if (loader.has("source") && (config.tasks ?? []).map((e) => typeof e === "string" ? e : e.name).includes("bookkeeping")) {
12322
- const source = loader.get("source");
12323
- steps.push(await runStep("source", "write .github/labeler.yml", dryRun, async () => {
12324
- await source.writeRepoFile(".github/labeler.yml", createLabeler());
12325
- }));
12326
- print(formatStep(steps[steps.length - 1]));
12327
- }
12328
- if (loader.has("source") && effectivePreset !== "none") {
12329
- const source = loader.get("source");
12330
- steps.push(await runStep("source", "write .github/dependabot.yml", dryRun, async () => {
12331
- await source.writeRepoFile(".github/dependabot.yml", createDependabot({ ignore: ownCatalogPackages(input.context.repoRoot) }));
12332
- }));
12333
- print(formatStep(steps[steps.length - 1]));
12334
- steps.push(await runStep("source", "write .github/dco.yml", dryRun, async () => {
12335
- await source.writeRepoFile(".github/dco.yml", `${workflowHeader()}${dco_default}`);
12336
- }));
12337
- print(formatStep(steps[steps.length - 1]));
12338
- }
12339
12568
  if (loader.has("source")) {
12340
12569
  const source = loader.get("source");
12341
- steps.push(await runStep("source", "write .alexrc.json", dryRun, async () => {
12342
- await source.writeRepoFile(".alexrc.json", createAlexrc());
12343
- }));
12344
- print(formatStep(steps[steps.length - 1]));
12345
- steps.push(await runStep("source", "write .alexignore", dryRun, async () => {
12346
- await source.writeRepoFile(".alexignore", createAlexignore());
12347
- }));
12348
- print(formatStep(steps[steps.length - 1]));
12349
- steps.push(await runStep("source", "write .yamllint.yml", dryRun, async () => {
12350
- await source.writeRepoFile(".yamllint.yml", createYamllint());
12351
- }));
12352
- print(formatStep(steps[steps.length - 1]));
12353
- steps.push(await runStep("source", "write .yamlignore", dryRun, async () => {
12354
- await source.writeRepoFile(".yamlignore", createYamlignore());
12355
- }));
12356
- print(formatStep(steps[steps.length - 1]));
12357
- steps.push(await runStep("source", "write .editorconfig", dryRun, async () => {
12358
- await source.writeRepoFile(".editorconfig", createEditorconfig());
12359
- }));
12360
- print(formatStep(steps[steps.length - 1]));
12361
- steps.push(await runStep("source", "write .editorconfig-checker.json", dryRun, async () => {
12362
- await source.writeRepoFile(".editorconfig-checker.json", createEditorconfigChecker());
12363
- }));
12364
- print(formatStep(steps[steps.length - 1]));
12365
- steps.push(await runStep("source", "write devmoji.config.cjs", dryRun, async () => {
12366
- await source.writeRepoFile("devmoji.config.cjs", createDevmoji());
12367
- }));
12368
- print(formatStep(steps[steps.length - 1]));
12369
- steps.push(await runStep("source", "write .husky/prepare-commit-msg", dryRun, async () => {
12370
- await source.writeRepoFile(".husky/prepare-commit-msg", createPrepareCommitMsg());
12371
- }));
12372
- print(formatStep(steps[steps.length - 1]));
12373
- steps.push(await runStep("source", "write .husky/commit-msg", dryRun, async () => {
12374
- await source.writeRepoFile(".husky/commit-msg", createCommitMsg(config.holocronScript));
12375
- }));
12376
- print(formatStep(steps[steps.length - 1]));
12377
- if (hooksEnabled) {
12378
- steps.push(await runStep("source", "write .husky/pre-push", dryRun, async () => {
12379
- await source.writeRepoFile(".husky/pre-push", createPrePush(config.holocronScript));
12380
- return "runs `holocron run ci` before push — bypass with `git push --no-verify`";
12570
+ if (config.tasks && config.tasks.length > 0) print(style.step("workflows"));
12571
+ for (const entry of await generateRepoFiles({
12572
+ loaded: input.loaded,
12573
+ repoRoot: input.context.repoRoot,
12574
+ hooks: input.hooks,
12575
+ logger
12576
+ })) {
12577
+ if (entry.kind === "skip") steps.push({
12578
+ capability: "source",
12579
+ step: entry.step,
12580
+ status: "skip",
12581
+ message: entry.message
12582
+ });
12583
+ else if (entry.kind === "error") steps.push(await runStep("source", entry.step, dryRun, async () => {
12584
+ throw new Error(entry.message);
12381
12585
  }));
12382
- print(formatStep(steps[steps.length - 1]));
12383
- steps.push(await runStep("source", "write .husky/pre-commit", dryRun, async () => {
12384
- await source.writeRepoFile(".husky/pre-commit", createPreCommit());
12385
- return "runs GitLeaks (staged-only) + lint-staged before commit";
12586
+ else steps.push(await runStep("source", entry.step, dryRun, async () => {
12587
+ if (entry.workflow) {
12588
+ const { task, filename } = entry.workflow;
12589
+ await assertNoPackageCollision(task, setupPkgRelPath, filename, () => source.readWorkflowFile(filename));
12590
+ await source.writeWorkflowFile(filename, entry.content);
12591
+ } else await source.writeRepoFile(entry.path, entry.content);
12592
+ return entry.note;
12386
12593
  }));
12387
12594
  print(formatStep(steps[steps.length - 1]));
12388
- if (config.syncScripts !== false) {
12595
+ if (entry.kind === "file" && entry.path === ".husky/pre-commit" && config.syncScripts !== false) {
12389
12596
  steps.push(await runStep("source", "set package.json prepare script", dryRun, async () => {
12390
12597
  return await ensurePrepareScript(input.context.repoRoot) ? "prepare now runs husky" : "already runs husky";
12391
12598
  }));
12392
12599
  print(formatStep(steps[steps.length - 1]));
12393
12600
  }
12394
- } else {
12395
- steps.push({
12396
- capability: "source",
12397
- step: "write .husky/pre-push",
12398
- status: "skip",
12399
- message: "git hooks disabled"
12400
- });
12401
- print(formatStep(steps[steps.length - 1]));
12402
- steps.push({
12403
- capability: "source",
12404
- step: "write .husky/pre-commit",
12405
- status: "skip",
12406
- message: "git hooks disabled"
12407
- });
12408
- print(formatStep(steps[steps.length - 1]));
12409
- }
12410
- {
12411
- const hasTestWorkflow = (config.tasks ?? []).map((e) => typeof e === "string" ? e : e.name).includes("verification.unitTests");
12412
- const existing = await readFile(join(input.context.repoRoot, "codecov.yml"), "utf8").catch(() => null);
12413
- if (!hasTestWorkflow && existing == null) steps.push({
12414
- capability: "source",
12415
- step: "write codecov.yml",
12416
- status: "skip",
12417
- message: "no test workflow configured"
12418
- });
12419
- else steps.push(await runStep("source", "write codecov.yml", dryRun, async () => {
12420
- const content = createAstromech({
12421
- cwd: input.context.repoRoot,
12422
- logger
12423
- }).codecovConfig(existing);
12424
- await source.writeRepoFile("codecov.yml", content);
12425
- const packageCount = readWorkspacePackages(input.context.repoRoot).length;
12426
- return packageCount > 0 ? `${packageCount} components` : "no components";
12427
- }));
12428
- print(formatStep(steps[steps.length - 1]));
12429
- }
12430
- {
12431
- const astromechTurbo = createAstromech({
12432
- cwd: input.context.repoRoot,
12433
- config: { tasks: config.tasks },
12434
- logger
12435
- });
12436
- const content = astromechTurbo.turboConfig();
12437
- const firstStep = steps.length;
12438
- if (content === null) steps.push({
12439
- capability: "source",
12440
- step: "write turbo.json",
12441
- status: "skip",
12442
- message: "no fan-out-eligible tasks configured"
12443
- });
12444
- else {
12445
- steps.push(await runStep("source", "write turbo.json", dryRun, async () => {
12446
- await source.writeRepoFile("turbo.json", content);
12447
- }));
12448
- const rootPkgRaw = await readFile(join(input.context.repoRoot, "package.json"), "utf8").catch(() => null);
12449
- const rootPkg = rootPkgRaw ? JSON.parse(rootPkgRaw) : null;
12450
- const workspaceYaml = await readFile(join(input.context.repoRoot, "pnpm-workspace.yaml"), "utf8").catch(() => "");
12451
- const rootScripts = rootPkg?.scripts ?? {};
12452
- const workspaceFix = astromechTurbo.ensureRootWorkspaceMember(workspaceYaml, rootScripts);
12453
- if (workspaceFix.changed) steps.push(await runStep("source", "fix pnpm-workspace.yaml (root workspace member, #692)", dryRun, async () => {
12454
- await source.writeRepoFile("pnpm-workspace.yaml", workspaceFix.content);
12455
- }));
12456
- if (rootPkgRaw) {
12457
- const depFix = astromechTurbo.ensureTurboDependency(rootPkgRaw, workspaceFix.content);
12458
- if (depFix.changed) steps.push(await runStep("source", "add turbo devDependency", dryRun, async () => {
12459
- await source.writeRepoFile("package.json", depFix.content);
12460
- }));
12461
- }
12462
- }
12463
- for (const step of steps.slice(firstStep)) print(formatStep(step));
12464
12601
  }
12602
+ }
12603
+ if (loader.has("source")) {
12604
+ const source = loader.get("source");
12465
12605
  if (source.syncLabels) {
12466
12606
  steps.push(await runStep("source", "sync labels", dryRun, async () => {
12467
12607
  return source.syncLabels(CANONICAL_LABELS, STALE_LABELS);
@@ -13700,9 +13840,12 @@ async function runSync(input) {
13700
13840
  print(formatSyncStep(steps[steps.length - 1]));
13701
13841
  }
13702
13842
  if (stepName === "workflows") {
13703
- const rawTaskEntries = config.tasks ?? [];
13704
- const taskEntries = rawTaskEntries.length === 0 ? rawTaskEntries : withAutoPreviewDeployPaths(rawTaskEntries, gitRoot);
13705
- if (taskEntries.length === 0) {
13843
+ const entries = generateWorkflowFiles({
13844
+ loaded: input.loaded,
13845
+ repoRoot: input.context.repoRoot,
13846
+ logger
13847
+ });
13848
+ if ((config.tasks ?? []).length === 0) {
13706
13849
  steps.push({
13707
13850
  capability: "local",
13708
13851
  step: "sync workflows",
@@ -13710,39 +13853,22 @@ async function runSync(input) {
13710
13853
  message: "no tasks configured"
13711
13854
  });
13712
13855
  print(formatSyncStep(steps[steps.length - 1]));
13713
- } else {
13714
- const files = createAstromech({
13715
- cwd: input.context.repoRoot,
13716
- config: { tasks: taskEntries },
13717
- orgContext: {
13718
- org: config.org,
13719
- domain: config.domain
13720
- },
13721
- logger
13722
- }).thinCallers();
13723
- for (const entry of taskEntries) {
13724
- const name = typeof entry === "string" ? entry : entry.name;
13725
- const isCombinedContentOnly = name === "knowledge.docs" || name === "knowledge.components";
13726
- if (!KNOWN_WORKFLOWS.has(name) && !isCombinedContentOnly) {
13727
- steps.push({
13728
- capability: "local",
13729
- step: `sync workflow ${name}`,
13730
- status: "skip",
13731
- message: `unknown workflow "${name}" — no template available`
13732
- });
13733
- print(formatSyncStep(steps[steps.length - 1]));
13734
- continue;
13735
- }
13736
- const filename = `${name}.yml`;
13737
- const content = files.get(filename);
13738
- if (content === void 0) continue;
13739
- const step = `sync workflow ${name}${content.includes("workflows/preview.yml@main") ? " (with preview)" : ""}`;
13740
- steps.push(await runSyncStep("local", step, dryRun, async () => {
13741
- await assertNoPackageCollision(name, pkgRelPath, filename, () => readExistingWorkflowFile(gitRoot, filename));
13742
- await writeWorkflowFile(gitRoot, filename, thinCallerFile(pkgRelPath, content));
13856
+ }
13857
+ for (const entry of entries) {
13858
+ if (entry.kind === "skip") steps.push({
13859
+ capability: "local",
13860
+ step: entry.syncStep,
13861
+ status: "skip",
13862
+ message: entry.message
13863
+ });
13864
+ else {
13865
+ const { task, filename } = entry.workflow;
13866
+ steps.push(await runSyncStep("local", entry.syncStep, dryRun, async () => {
13867
+ await assertNoPackageCollision(task, pkgRelPath, filename, () => readExistingWorkflowFile(gitRoot, filename));
13868
+ await writeWorkflowFile(gitRoot, filename, entry.content);
13743
13869
  }));
13744
- print(formatSyncStep(steps[steps.length - 1]));
13745
13870
  }
13871
+ print(formatSyncStep(steps[steps.length - 1]));
13746
13872
  }
13747
13873
  }
13748
13874
  if (stepName === "scripts") {
@@ -13785,45 +13911,21 @@ async function runSync(input) {
13785
13911
  print(formatSyncStep(steps[steps.length - 1]));
13786
13912
  continue;
13787
13913
  }
13788
- const astromechTurbo = createAstromech({
13789
- cwd: input.context.repoRoot,
13790
- config: { tasks: config.tasks },
13914
+ for (const entry of await generateTurboFiles({
13915
+ loaded: input.loaded,
13916
+ repoRoot: input.context.repoRoot,
13791
13917
  logger
13792
- });
13793
- const content = astromechTurbo.turboConfig();
13794
- if (content === null) {
13795
- steps.push({
13918
+ })) {
13919
+ if (entry.kind === "skip") steps.push({
13796
13920
  capability: "local",
13797
- step: "sync turbo.json",
13921
+ step: entry.syncStep,
13798
13922
  status: "skip",
13799
- message: "no fan-out-eligible tasks configured"
13923
+ message: entry.message
13800
13924
  });
13801
- print(formatSyncStep(steps[steps.length - 1]));
13802
- } else {
13803
- steps.push(await runSyncStep("local", "sync turbo.json", dryRun, async () => {
13804
- await writeFile(join(gitRoot, "turbo.json"), content, "utf8");
13925
+ else steps.push(await runSyncStep("local", entry.syncStep, dryRun, async () => {
13926
+ await writeFile(join(gitRoot, entry.path), entry.content, "utf8");
13805
13927
  }));
13806
13928
  print(formatSyncStep(steps[steps.length - 1]));
13807
- const rootPkgRaw = await readFile(join(gitRoot, "package.json"), "utf8").catch(() => null);
13808
- const rootPkg = rootPkgRaw ? JSON.parse(rootPkgRaw) : null;
13809
- const workspaceYaml = await readFile(join(gitRoot, "pnpm-workspace.yaml"), "utf8").catch(() => "");
13810
- const rootScripts = rootPkg?.scripts ?? {};
13811
- const workspaceFix = astromechTurbo.ensureRootWorkspaceMember(workspaceYaml, rootScripts);
13812
- if (workspaceFix.changed) {
13813
- steps.push(await runSyncStep("local", "fix pnpm-workspace.yaml (root workspace member, #692)", dryRun, async () => {
13814
- await writeFile(join(gitRoot, "pnpm-workspace.yaml"), workspaceFix.content, "utf8");
13815
- }));
13816
- print(formatSyncStep(steps[steps.length - 1]));
13817
- }
13818
- if (rootPkgRaw) {
13819
- const depFix = astromechTurbo.ensureTurboDependency(rootPkgRaw, workspaceFix.content);
13820
- if (depFix.changed) {
13821
- steps.push(await runSyncStep("local", "add turbo devDependency", dryRun, async () => {
13822
- await writeFile(join(gitRoot, "package.json"), depFix.content, "utf8");
13823
- }));
13824
- print(formatSyncStep(steps[steps.length - 1]));
13825
- }
13826
- }
13827
13929
  }
13828
13930
  }
13829
13931
  if (stepName === "wiki") {