@theholocron/astromech 5.0.0-alpha.56 → 5.0.0-alpha.561

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.
@@ -0,0 +1,549 @@
1
+ import { loadLayered } from "@theholocron/datapad";
2
+ // src/config/schema/schema.ts
3
+ /**
4
+ * The `tasks` config shape — the single manifest of what a repo runs.
5
+ * Read from a dedicated `astromech.config.*` file or the `tasks` key of
6
+ * `holocron.config.*` (see {@link loadTasksConfig}).
7
+ *
8
+ * Runtime validation is the loader's job, not this type's — the type only
9
+ * describes what an author writes.
10
+ */
11
+ /** Normalise a `TaskConfigItem` to a full {@link TaskEntry} with defaults applied. */
12
+ function normalizeTaskEntry(item) {
13
+ return {
14
+ ci: true,
15
+ local: true,
16
+ ...typeof item === "string" ? { name: item } : item
17
+ };
18
+ }
19
+ // src/registry/registry.ts
20
+ /**
21
+ * The task registry — how each task runs *locally*, without GitHub
22
+ * Actions. `holocron run <task>` and `holocron run ci` resolve against this;
23
+ * adding a task here gives every repo that task.
24
+ *
25
+ * Keyed by the flat, verb-first id (`test:unit`, `lint:code`, `build`,
26
+ * `deploy-preview`), the one spelling of a task in the CLI (spec
27
+ * `ci-flat-task-vocabulary`, SPEC-0064, epic #1612). A colon means "member of
28
+ * the suite named before it": `test`, `lint`, `scan`,
29
+ * `validate` and `measure` are suites, declared here by the `suite` field of their leaves
30
+ * and never ids of their own. A hyphen is part of a verb phrase and implies no
31
+ * suite. The old dotted names (`verification.unitTests`, …) are accepted for a
32
+ * window through {@link LEGACY_NAMES} and still name the generated workflow
33
+ * files, turbo tasks and `package.json` scripts until the later phases move
34
+ * those (see {@link legacyName}).
35
+ *
36
+ * Every other artifact (`KNOWN_TASKS`, `CI_ORDER`, the suites) derives from
37
+ * these keys rather than hand-duplicating them — including the GitHub App
38
+ * (#679), which imports this same table for config-schema validation.
39
+ *
40
+ * Declared order is run order: a suite runs its members in the order they
41
+ * appear here.
42
+ *
43
+ * Task names are an intent-facing vocabulary, not tool names —
44
+ * `eslint`/`vitest`/`tsdown`/… stay internal to this file and the `configs/`
45
+ * folder.
46
+ *
47
+ * Spec: `.notes/ci-flat-task-vocabulary.spec.md`, and
48
+ * `docs/wiki/specifications/tech-astromech-task-runner.spec.md` (epic #581).
49
+ */
50
+ const TASKS = {
51
+ "test:unit": {
52
+ group: "Verification",
53
+ scope: "package",
54
+ suite: "test",
55
+ local: {
56
+ tool: "vitest",
57
+ args: ["run", "--coverage"]
58
+ },
59
+ turbo: {
60
+ inputs: [
61
+ "src/**",
62
+ "test/**",
63
+ "vitest.config.ts",
64
+ "vitest.config.js",
65
+ "vitest.config.mjs",
66
+ "$TURBO_ROOT$/vitest.config.ts",
67
+ "$TURBO_ROOT$/vitest.config.js",
68
+ "$TURBO_ROOT$/vitest.config.mjs",
69
+ "package.json"
70
+ ],
71
+ outputs: ["test-report.junit.xml", "coverage/**"],
72
+ dependsOn: ["build", "^build"]
73
+ }
74
+ },
75
+ "test:visual": {
76
+ group: "Verification",
77
+ scope: "repo",
78
+ suite: "test",
79
+ local: null
80
+ },
81
+ "test:perf": {
82
+ group: "Verification",
83
+ scope: "repo",
84
+ suite: "test",
85
+ local: { detect: [{
86
+ when: /^lighthouse\.config\.(cjs|js|mjs|ts)$/,
87
+ tool: "lhci",
88
+ args: ["autorun"]
89
+ }, {
90
+ when: /^lighthouserc\.(cjs|js|mjs|json|yml|yaml)$/,
91
+ tool: "lhci",
92
+ args: ["autorun"]
93
+ }] }
94
+ },
95
+ typecheck: {
96
+ group: "Verification",
97
+ scope: "package",
98
+ local: {
99
+ tool: "tsc",
100
+ args: ["--noEmit"]
101
+ },
102
+ turbo: {
103
+ inputs: [
104
+ "src/**",
105
+ "test/**",
106
+ "tsconfig.json"
107
+ ],
108
+ outputs: [],
109
+ dependsOn: ["^build"]
110
+ }
111
+ },
112
+ "lint:code": {
113
+ group: "Source Quality",
114
+ scope: "package",
115
+ suite: "lint",
116
+ local: null,
117
+ linterGroup: [
118
+ "eslint",
119
+ "actionlint",
120
+ "git-merge-conflict-markers"
121
+ ],
122
+ turbo: {
123
+ inputs: [
124
+ "src/**",
125
+ "eslint.config.ts",
126
+ "eslint.config.js",
127
+ "eslint.config.mjs",
128
+ "eslint.config.cjs",
129
+ "$TURBO_ROOT$/eslint.config.ts",
130
+ "$TURBO_ROOT$/eslint.config.js",
131
+ "$TURBO_ROOT$/eslint.config.mjs",
132
+ "$TURBO_ROOT$/eslint.config.cjs"
133
+ ],
134
+ outputs: [],
135
+ dependsOn: ["^build"]
136
+ }
137
+ },
138
+ "lint:editorconfig": {
139
+ group: "Source Quality",
140
+ scope: "repo",
141
+ suite: "lint",
142
+ local: null,
143
+ linterGroup: ["editorconfig"]
144
+ },
145
+ "lint:markdown": {
146
+ group: "Source Quality",
147
+ scope: "repo",
148
+ suite: "lint",
149
+ local: null,
150
+ linterGroup: ["markdownlint"]
151
+ },
152
+ "lint:data": {
153
+ group: "Source Quality",
154
+ scope: "repo",
155
+ suite: "lint",
156
+ local: null,
157
+ linterGroup: ["yamllint"]
158
+ },
159
+ "lint:unused": {
160
+ group: "Source Quality",
161
+ scope: "repo",
162
+ suite: "lint",
163
+ local: { tool: "knip" }
164
+ },
165
+ "lint:commits": {
166
+ group: "Source Quality",
167
+ scope: "repo",
168
+ suite: "lint",
169
+ local: null,
170
+ linterGroup: ["commitlint"]
171
+ },
172
+ format: {
173
+ group: "Source Quality",
174
+ scope: "repo",
175
+ workflow: false,
176
+ host: "lint:code",
177
+ local: {
178
+ tool: "prettier",
179
+ args: ["--write", "."]
180
+ },
181
+ checkArgs: ["--check", "."]
182
+ },
183
+ "scan:secrets": {
184
+ group: "Security",
185
+ scope: "repo",
186
+ suite: "scan",
187
+ local: null,
188
+ linterGroup: ["gitleaks"]
189
+ },
190
+ "scan:code": {
191
+ group: "Security",
192
+ scope: "repo",
193
+ suite: "scan",
194
+ local: null
195
+ },
196
+ "check-tokens": {
197
+ group: "Security",
198
+ scope: "repo",
199
+ local: { command: "doctor secrets --verify" }
200
+ },
201
+ "doctor-tokens": {
202
+ group: "Security",
203
+ scope: "repo",
204
+ local: { command: "doctor tokens" }
205
+ },
206
+ build: {
207
+ group: "Delivery",
208
+ scope: "package",
209
+ local: { detect: [
210
+ {
211
+ when: /^tsdown\.config\.(ts|js|mjs|cjs)$/,
212
+ tool: "tsdown"
213
+ },
214
+ {
215
+ when: /^vite\.config\.(ts|js|mjs|cjs)$/,
216
+ tool: "vite",
217
+ args: ["build"]
218
+ },
219
+ {
220
+ when: /^rollup\.config\.(ts|js|mjs|cjs)$/,
221
+ tool: "rollup",
222
+ args: ["-c"]
223
+ },
224
+ {
225
+ when: /^tsconfig\.json$/,
226
+ tool: "tsc",
227
+ args: ["-b"]
228
+ }
229
+ ] },
230
+ turbo: {
231
+ inputs: [
232
+ "src/**",
233
+ "package.json",
234
+ "tsdown.config.ts",
235
+ "$TURBO_ROOT$/tsdown.config.ts",
236
+ "vite.config.ts",
237
+ "rollup.config.ts",
238
+ "tsconfig.json"
239
+ ],
240
+ outputs: ["dist/**"],
241
+ dependsOn: ["^build"]
242
+ }
243
+ },
244
+ release: {
245
+ group: "Delivery",
246
+ scope: "repo",
247
+ local: null,
248
+ preview: true
249
+ },
250
+ deploy: {
251
+ group: "Delivery",
252
+ scope: "package",
253
+ local: null,
254
+ preview: true
255
+ },
256
+ "measure:bundle": {
257
+ group: "Delivery",
258
+ scope: "repo",
259
+ suite: "measure",
260
+ local: null
261
+ },
262
+ "check-preview": {
263
+ group: "Delivery",
264
+ scope: "repo",
265
+ local: null
266
+ },
267
+ "deploy-preview": {
268
+ group: "Delivery",
269
+ scope: "package",
270
+ local: null
271
+ },
272
+ "deploy-sentinel": {
273
+ group: "Delivery",
274
+ scope: "repo",
275
+ local: null
276
+ },
277
+ "validate:specs": {
278
+ group: "Platform",
279
+ scope: "repo",
280
+ suite: "validate",
281
+ local: { command: "probe specs check" }
282
+ },
283
+ "validate:docs": {
284
+ group: "Platform",
285
+ scope: "repo",
286
+ suite: "validate",
287
+ local: { command: "probe docs validate" }
288
+ },
289
+ "validate:deps": {
290
+ group: "Platform",
291
+ scope: "repo",
292
+ suite: "validate",
293
+ local: { command: "probe deps check" }
294
+ },
295
+ "validate:generated": {
296
+ group: "Platform",
297
+ scope: "repo",
298
+ suite: "validate",
299
+ local: { command: "probe generated check" }
300
+ },
301
+ "validate:plugin": {
302
+ group: "Platform",
303
+ scope: "package",
304
+ suite: "validate",
305
+ workflow: false,
306
+ local: null
307
+ },
308
+ "measure:docs": {
309
+ group: "Platform",
310
+ scope: "repo",
311
+ suite: "measure",
312
+ local: { command: "probe docs coverage" }
313
+ },
314
+ "remind-doctor": {
315
+ group: "Platform",
316
+ scope: "repo",
317
+ local: null
318
+ },
319
+ "sync-repo": {
320
+ group: "Platform",
321
+ scope: "repo",
322
+ local: { command: "sync" }
323
+ },
324
+ "check-notify": {
325
+ group: "Platform",
326
+ scope: "repo",
327
+ local: null
328
+ },
329
+ "sync-secrets": {
330
+ group: "Platform",
331
+ scope: "repo",
332
+ local: null
333
+ },
334
+ "sync-templates": {
335
+ group: "Platform",
336
+ scope: "repo",
337
+ local: { command: "sync github" }
338
+ },
339
+ "reconcile-projects": {
340
+ group: "Platform",
341
+ scope: "repo",
342
+ local: { command: "reconcile project" }
343
+ },
344
+ "reconcile-ci": {
345
+ group: "Platform",
346
+ scope: "repo",
347
+ local: { command: "reconcile ci" }
348
+ },
349
+ "sync-issues": {
350
+ group: "Platform",
351
+ scope: "repo",
352
+ local: null
353
+ },
354
+ "sync-incidents": {
355
+ group: "Platform",
356
+ scope: "repo",
357
+ local: { command: "sync incidents --yes" }
358
+ },
359
+ "open-incident": {
360
+ group: "Platform",
361
+ scope: "repo",
362
+ local: null
363
+ },
364
+ "sync-specs": {
365
+ group: "Knowledge",
366
+ scope: "repo",
367
+ local: { command: "sync specs" }
368
+ },
369
+ "preview-specs": {
370
+ group: "Knowledge",
371
+ scope: "repo",
372
+ local: null
373
+ },
374
+ "publish-wiki": {
375
+ group: "Knowledge",
376
+ scope: "repo",
377
+ local: { command: "sync-wiki" },
378
+ preview: true
379
+ },
380
+ "deploy-docs": {
381
+ group: "Knowledge",
382
+ scope: "repo",
383
+ local: null,
384
+ preview: true
385
+ },
386
+ "deploy-components": {
387
+ group: "Knowledge",
388
+ scope: "repo",
389
+ local: null,
390
+ preview: true
391
+ }
392
+ };
393
+ /**
394
+ * The order `holocron run ci` runs tasks in — cheapest / fastest signal first, so
395
+ * an agent or a `pre-push` hook fails early. Tasks not listed here run last, in
396
+ * manifest order. (The generated thin callers carry no `needs:` — cross-workflow
397
+ * ordering lives in `theholocron/.github` — so `holocron run ci` declares its own.)
398
+ */
399
+ const CI_ORDER = [
400
+ "typecheck",
401
+ "lint:code",
402
+ "lint:editorconfig",
403
+ "lint:markdown",
404
+ "format",
405
+ "lint:data",
406
+ "scan:secrets",
407
+ "lint:commits",
408
+ "validate:specs",
409
+ "validate:docs",
410
+ "validate:deps",
411
+ "validate:generated",
412
+ "test:unit",
413
+ "build",
414
+ "lint:unused",
415
+ "measure:bundle",
416
+ "test:perf",
417
+ "scan:code",
418
+ "deploy"
419
+ ];
420
+ // src/vocabulary/legacy-names/legacy-names.ts
421
+ /**
422
+ * The old dotted task names (and the workflow-only keys) and the flat ids they became — the complete map of spec
423
+ * `ci-flat-task-vocabulary`, "Old to new". `holocron run <old>` and `tasks:` in `holocron.config` still accept them
424
+ * for a window (the frozen reusables in `theholocron/.github` run `holocron run <old>` until #1216 deletes them), and
425
+ * a name that stood for one workflow carrying several checks maps to all of its successors, in run order.
426
+ *
427
+ * Each key is also the name of the generated workflow file, the turbo task and the `package.json` script until the
428
+ * later phases move those, so {@link legacyName} reads this table backwards. Removed together with the aliases in the
429
+ * last phase.
430
+ */
431
+ const LEGACY_NAMES = {
432
+ "verification.unitTests": [{ id: "test:unit" }],
433
+ "verification.visualRegression": [{ id: "test:visual" }],
434
+ "verification.performance": [{ id: "test:perf" }],
435
+ "verification.typeSafety": [{ id: "typecheck" }],
436
+ "sourceQuality.staticAnalysis": [{ id: "lint:code" }],
437
+ "sourceQuality.formatting": [
438
+ { id: "lint:editorconfig" },
439
+ { id: "lint:markdown" },
440
+ {
441
+ id: "format",
442
+ passthrough: ["--check"]
443
+ }
444
+ ],
445
+ "sourceQuality.structuredDataValidation": [{ id: "lint:data" }],
446
+ "sourceQuality.deadCodeAnalysis": [{ id: "lint:unused" }],
447
+ "platform.commitStandards": [{ id: "lint:commits" }],
448
+ "security.secretDetection": [{ id: "scan:secrets" }],
449
+ "security.codeScanning": [{ id: "scan:code" }],
450
+ "security.tokenExpiry": [{ id: "check-tokens" }],
451
+ "delivery.build": [{ id: "build" }],
452
+ "measure-docs": [{ id: "measure:docs" }],
453
+ "measure-bundle": [{ id: "measure:bundle" }],
454
+ "delivery.bundleSize": [{ id: "measure:bundle" }],
455
+ "delivery.publish": [{ id: "release" }],
456
+ "delivery.deploy": [{ id: "deploy" }],
457
+ "delivery.previewDeploy": [{ id: "deploy-preview" }],
458
+ "delivery.previewCheck": [{ id: "check-preview" }],
459
+ validate: [{ id: "validate:specs" }, { id: "validate:docs" }],
460
+ "platform.repoValidation": [{ id: "validate:specs" }, { id: "validate:docs" }],
461
+ "platform.repoSync": [{ id: "sync-repo" }],
462
+ "platform.syncTemplates": [{ id: "sync-templates" }],
463
+ "platform.notifyCheck": [{ id: "check-notify" }],
464
+ "knowledge.wiki": [{ id: "publish-wiki" }],
465
+ "knowledge.docs": [{ id: "deploy-docs" }],
466
+ "knowledge.components": [{ id: "deploy-components" }],
467
+ bookkeeping: [{ id: "label" }],
468
+ greetings: [{ id: "greet" }],
469
+ stale: [{ id: "mark-stale" }],
470
+ dependencies: [{ id: "update-deps" }],
471
+ review: [{ id: "annotate" }]
472
+ };
473
+ // src/vocabulary/legacy-name/legacy-name.ts
474
+ /** Each flat id and the old name that listed it (no id is listed under two). */
475
+ const BY_ID = new Map(Object.entries(LEGACY_NAMES).flatMap(([legacy, targets]) => targets.map(({ id }) => [id, legacy])));
476
+ /**
477
+ * The old name a flat id replaced — `test:unit` is `verification.unitTests`. It is what the generated workflow files,
478
+ * `turbo.json` tasks and `package.json` scripts are still called until the later phases rename them, so generators
479
+ * translate through it and the files do not change. `undefined` for an id that never had an old name (`preview`).
480
+ * `format` and the other formatting successors share the formatting workflow's name.
481
+ */
482
+ function legacyName(id) {
483
+ return BY_ID.get(id);
484
+ }
485
+ /**
486
+ * The old name a flat id replaced, only when that name stood for this id alone. `format` and `lint:markdown` are halves
487
+ * of `sourceQuality.formatting`, so a turbo task or script of that name is not theirs to run.
488
+ */
489
+ function ownLegacyName(id) {
490
+ const legacy = BY_ID.get(id);
491
+ return legacy !== void 0 && LEGACY_NAMES[legacy].length === 1 ? legacy : void 0;
492
+ }
493
+ // src/vocabulary/resolve-task-name/resolve-task-name.ts
494
+ /** A flat id: a registry task, or a workflow-only key (`label`) that only the old-name table lists. */
495
+ function isFlatId(name) {
496
+ return TASKS[name] !== void 0 || legacyName(name) !== void 0;
497
+ }
498
+ /**
499
+ * The flat ids a name written in a manifest, a script or on the command line stands for, in run order: a flat id (or
500
+ * its hyphen compound in the script spelling, `deploy:preview`) stands for itself, an old dotted name for its
501
+ * successors (`sourceQuality.formatting` for three), anything else for none. A suite name is not a task and resolves to
502
+ * none.
503
+ */
504
+ function resolveTaskName(name) {
505
+ if (isFlatId(name)) return [{ id: name }];
506
+ const legacy = LEGACY_NAMES[name];
507
+ if (legacy) return legacy;
508
+ const hyphenated = name.replace(":", "-");
509
+ return isFlatId(hyphenated) ? [{ id: hyphenated }] : [];
510
+ }
511
+ // src/vocabulary/is-task/is-task.ts
512
+ /** `true` when a manifest name (a flat id or an old dotted name) stands for the given flat id. */
513
+ function isTask(name, id) {
514
+ return resolveTaskName(name).some((target) => target.id === id);
515
+ }
516
+ // src/config/coerce-tasks/coerce-tasks.ts
517
+ /** A bare item array is shorthand for `{ tasks: [...] }`. */
518
+ function coerceTasks(value) {
519
+ if (value == null) return void 0;
520
+ return Array.isArray(value) ? { tasks: value } : value;
521
+ }
522
+ // src/config/load/load.ts
523
+ /**
524
+ * Resolve the task manifest for a repo: the `tasks` key of
525
+ * `holocron.config.*`, then a dedicated `astromech.config.*` merged on
526
+ * top (dedicated wins; item arrays concatenate). Returns `{}` when
527
+ * neither source is present.
528
+ *
529
+ * `walkUp: true` — `holocron run`/`ci` are usable from any subdirectory of
530
+ * a repo, not only its exact root (datapad walks up to the nearest `.git`
531
+ * boundary; see `@theholocron/datapad`'s own doc comment).
532
+ *
533
+ * A caller that has already loaded `holocron.config.*` passes it as
534
+ * `options.holocron` so it is not found and loaded again.
535
+ */
536
+ async function loadTasksConfig(cwd, options = {}) {
537
+ return (await loadLayered({
538
+ cwd,
539
+ name: "astromech",
540
+ walkUp: true,
541
+ fallback: {
542
+ file: "holocron",
543
+ key: "tasks",
544
+ preloaded: options.holocron
545
+ },
546
+ coerce: (raw) => coerceTasks(raw)
547
+ }))?.config ?? {};
548
+ }
549
+ export { legacyName as a, CI_ORDER as c, resolveTaskName as i, TASKS as l, coerceTasks as n, ownLegacyName as o, isTask as r, LEGACY_NAMES as s, loadTasksConfig as t, normalizeTaskEntry as u };