@theholocron/astromech 5.0.0-alpha.39 → 5.0.0-alpha.391

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,541 @@
1
+ // src/repo-validation/docs-presence/page-names/page-names.ts
2
+ /**
3
+ * The names a package's docs page can have: its folder name, and that name without the `-client` or
4
+ * `holocron-plugin-` part its page drops (`clients/axiom-client` is the page `clients/axiom.mdx`).
5
+ */
6
+ function pageNames(dir) {
7
+ const name = dir.slice(dir.lastIndexOf("/") + 1);
8
+ return [.../* @__PURE__ */ new Set([
9
+ name,
10
+ name.replace(/-client$/, ""),
11
+ name.replace(/^holocron-plugin-/, "")
12
+ ])];
13
+ }
14
+ // src/repo-validation/docs-presence/has-docs-signal/has-docs-signal.ts
15
+ /**
16
+ * Whether the PR touches a package's documentation: a doc comment added in its source, its `README.md`, or a docs
17
+ * page named after it (see `pageNames`).
18
+ */
19
+ function hasDocsSignal(dir, changedFiles, addedCommentLines) {
20
+ if (addedCommentLines.length > 0) return true;
21
+ const names = pageNames(dir);
22
+ return changedFiles.some((f) => {
23
+ if (f === `${dir}/README.md`) return true;
24
+ if (!f.startsWith("docs/") || !/\.mdx?$/.test(f)) return false;
25
+ return names.includes(f.slice(f.lastIndexOf("/") + 1).replace(/\.mdx?$/, ""));
26
+ });
27
+ }
28
+ // src/repo-validation/docs-presence/evaluate-docs-presence/evaluate-docs-presence.ts
29
+ /**
30
+ * Sorts the packages a feature changed into those that need a warning (no docs signal, and no `[skip docs]` marker
31
+ * with a reason that covers them) and those a marker excused. A marker with no reason excuses nothing.
32
+ */
33
+ function evaluateDocsPresence(input) {
34
+ const { packages, changedFiles, addedCommentLines, skip } = input;
35
+ const result = {
36
+ warn: [],
37
+ skipped: [],
38
+ missingReason: false
39
+ };
40
+ for (const dir of packages) {
41
+ if (hasDocsSignal(dir, changedFiles, addedCommentLines(dir))) continue;
42
+ const covered = skip !== null && (skip.scope === null || skip.scope.some((s) => s === dir || pageNames(dir).includes(s)));
43
+ if (covered && skip.reason) {
44
+ result.skipped.push({
45
+ dir,
46
+ reason: skip.reason
47
+ });
48
+ continue;
49
+ }
50
+ if (covered) result.missingReason = true;
51
+ result.warn.push(dir);
52
+ }
53
+ return result;
54
+ }
55
+ // src/repo-validation/docs-presence/is-added-doc-comment/is-added-doc-comment.ts
56
+ /** Whether a line of a unified diff adds part of a doc comment: its `/**` opener, a ` * text` line or the closer. */
57
+ function isAddedDocComment(line) {
58
+ return /^\+\s*(\/\*\*|\*(\s|\/|$))/.test(line);
59
+ }
60
+ // src/repo-validation/docs-presence/is-feat/is-feat.ts
61
+ /** Whether any subject is a Conventional Commit `feat`: `feat:`, `feat(scope):` or `feat!:`, in any case. */
62
+ function isFeat(subjects) {
63
+ return subjects.some((s) => /^feat(\([^)]*\))?!?:/i.test(s.trim()));
64
+ }
65
+ // src/repo-validation/docs-presence/package-of/package-of.ts
66
+ /**
67
+ * The public package a changed file is source of: the nearest folder above it with a `package.json`, when the file is
68
+ * under that package's `src/` or is its root `index`, and the package is not private. Tests, other package files and
69
+ * files in no package give `undefined`.
70
+ */
71
+ function packageOf(file, readPackage) {
72
+ if (file.includes("node_modules/") || /\.(test|spec)\.[cm]?[jt]sx?$/.test(file)) return void 0;
73
+ const parts = file.split("/");
74
+ for (let i = parts.length - 1; i > 0; i--) {
75
+ const dir = parts.slice(0, i).join("/");
76
+ const pkg = readPackage(dir);
77
+ if (!pkg) continue;
78
+ if (pkg.private) return void 0;
79
+ const inside = parts.slice(i).join("/");
80
+ return inside.startsWith("src/") || /^index\.[cm]?[jt]s$/.test(inside) ? dir : void 0;
81
+ }
82
+ }
83
+ // src/repo-validation/docs-presence/parse-skip-docs/parse-skip-docs.ts
84
+ /**
85
+ * Finds `[skip docs] reason`, or `[skip docs: pkg-a, pkg-b] reason`, on one line of a PR description or commit
86
+ * body. Like semantic-release's `[skip ci]`, except that the reason after it is what makes it count. `null` when the
87
+ * text has no marker.
88
+ */
89
+ function parseSkipDocs(text) {
90
+ const match = /\[skip docs(?::\s*([^\]]*?))?\][ \t]*([^\n]*)/i.exec(text);
91
+ if (!match) return null;
92
+ return {
93
+ scope: match[1] ? match[1].split(",").map((s) => s.trim()).filter(Boolean) : null,
94
+ reason: match[2].trim()
95
+ };
96
+ }
97
+ // src/repo-validation/specs/assign-spec-ids/assign-spec-ids.ts
98
+ /** `SPEC-` and four digits: the id a spec carries in its front matter. */
99
+ const SPEC_ID = /^SPEC-(\d+)$/;
100
+ /**
101
+ * The ids the specs without one should take. They are numbered after the highest id any spec has, one after another,
102
+ * oldest first (by when the file was first committed, then by path), so numbering a whole tree gives the same result
103
+ * every time and a new spec always takes the next number. A spec that already has an id keeps it and is not in the
104
+ * result. Ids are `SPEC-` and at least four digits.
105
+ */
106
+ function assignSpecIds(specs) {
107
+ const taken = specs.flatMap((s) => {
108
+ const match = s.id === void 0 ? null : SPEC_ID.exec(s.id);
109
+ return match ? [Number(match[1])] : [];
110
+ });
111
+ let next = Math.max(0, ...taken) + 1;
112
+ const unnumbered = specs.filter((s) => !s.id).sort((a, b) => (a.time ?? Infinity) - (b.time ?? Infinity) || a.path.localeCompare(b.path));
113
+ return new Map(unnumbered.map((s) => [s.path, `SPEC-${String(next++).padStart(4, "0")}`]));
114
+ }
115
+ // src/repo-validation/specs/spec-locations/spec-locations.ts
116
+ /** Where ADRs live, relative to the repo root. */
117
+ const ADR_DIR = "docs/wiki/decisions";
118
+ /** Where specs live, relative to the repo root: in-progress ones in `.notes`, settled ones under the wiki. */
119
+ const SPEC_DIRS = [".notes", "docs/wiki/specifications"];
120
+ /** The statuses an ADR may have. */
121
+ const ADR_STATUSES = [
122
+ "proposed",
123
+ "accepted",
124
+ "rejected",
125
+ "deprecated",
126
+ "superseded"
127
+ ];
128
+ /** The statuses a spec may have. */
129
+ const SPEC_STATUSES = [
130
+ "draft",
131
+ "proposed",
132
+ "accepted",
133
+ "archived",
134
+ "superseded"
135
+ ];
136
+ /**
137
+ * The statuses that mean a document is finished with: a spec that shipped or was dropped, one that was replaced, an ADR
138
+ * that was turned down or is no longer followed. Its discussion is closed and locked, so it does not start up again;
139
+ * the others (`draft`, `proposed`, `accepted`) stay open, since an accepted document is still asked about.
140
+ */
141
+ const CLOSED_STATUSES = [
142
+ "archived",
143
+ "superseded",
144
+ "rejected",
145
+ "deprecated"
146
+ ];
147
+ /**
148
+ * The tag a discussion post carries while its pull request is closed unmerged. It is a state of the post only: no file
149
+ * may have it as its `status` (`ADR_STATUSES` and `SPEC_STATUSES` leave it out), and `reconcileSpecStatus` never reads it
150
+ * as a gatekeeper's retag. A post with it is closed, like one with a finished status.
151
+ */
152
+ const WITHDRAWN_STATE = "withdrawn";
153
+ /** The files in the ADR folder that are not ADRs. */
154
+ const ADR_EXEMPT = ["template.md", "README.md"];
155
+ // src/repo-validation/specs/classify-spec-path/classify-spec-path.ts
156
+ /**
157
+ * What a repo-relative path is to the ADR and spec check: an `adr` (a `.md` file directly in the ADR folder, other
158
+ * than the template and the README), a `spec` (a `*.spec.md` file directly in `.notes` or the wiki's specifications
159
+ * folder), or `undefined` for anything else, which the check leaves alone. Subfolders are not searched.
160
+ */
161
+ function classifySpecPath(path) {
162
+ const slash = path.lastIndexOf("/");
163
+ const dir = path.slice(0, slash);
164
+ const name = path.slice(slash + 1);
165
+ if (dir === "docs/wiki/decisions") return name.endsWith(".md") && !ADR_EXEMPT.includes(name) ? "adr" : void 0;
166
+ if (SPEC_DIRS.includes(dir)) return name.endsWith(".spec.md") ? "spec" : void 0;
167
+ }
168
+ // src/repo-validation/specs/parse-frontmatter/parse-frontmatter.ts
169
+ /**
170
+ * Reads a leading `---` block of `key: value` lines, with the line each one is on, plus one level of nesting keyed
171
+ * `parent.child` (the ADR template's `discussion:` / ` url:`). Any other line is skipped. Returns `null` when the
172
+ * text does not open with such a block.
173
+ */
174
+ function parseFrontmatter(content) {
175
+ const match = /^---\n([\s\S]*?)\n---/.exec(content);
176
+ if (!match) return null;
177
+ const fields = /* @__PURE__ */ new Map();
178
+ let parent;
179
+ match[1].split("\n").forEach((text, i) => {
180
+ const line = i + 2;
181
+ const kv = /^(\w[\w-]*):\s*(.*)/.exec(text);
182
+ if (kv) {
183
+ fields.set(kv[1], {
184
+ value: kv[2].trim(),
185
+ line
186
+ });
187
+ parent = kv[1];
188
+ return;
189
+ }
190
+ const nested = /^\s+(\w[\w-]*):\s*(.*)/.exec(text);
191
+ if (nested && parent) fields.set(`${parent}.${nested[1]}`, {
192
+ value: nested[2].trim(),
193
+ line
194
+ });
195
+ });
196
+ return fields;
197
+ }
198
+ // src/repo-validation/specs/is-valid-iso-date/is-valid-iso-date.ts
199
+ /** Whether `value` is a `YYYY-MM-DD` date that exists as far as `Date.parse` can tell. */
200
+ function isValidIsoDate(value) {
201
+ return /^\d{4}-\d{2}-\d{2}$/.test(value) && !Number.isNaN(Date.parse(value));
202
+ }
203
+ // src/repo-validation/specs/validate-adr/validate-adr.ts
204
+ /**
205
+ * The findings for one ADR's text. Errors: no frontmatter; a missing `id`, or one that is not `ADR-<the filename's
206
+ * four-digit prefix>`; a missing or empty `title`; a missing or unknown `status`; a missing or malformed `date`. A
207
+ * warning: an `accepted` ADR with no `discussion.url`, the address of its discussion post, which `holocron specs sync`
208
+ * writes. A GitHub Discussion link does not count.
209
+ */
210
+ function validateAdr(file, content) {
211
+ const findings = [];
212
+ const add = (rule, reason, line = 1, severity = "error") => {
213
+ findings.push({
214
+ file,
215
+ line,
216
+ rule,
217
+ reason,
218
+ severity
219
+ });
220
+ };
221
+ const fm = parseFrontmatter(content);
222
+ if (!fm) {
223
+ add("frontmatter", "no frontmatter found");
224
+ return findings;
225
+ }
226
+ const id = fm.get("id");
227
+ const sequence = /^(\d{4})-/.exec(file.slice(file.lastIndexOf("/") + 1))?.[1];
228
+ if (!id?.value) add("id", "missing `id` field", id?.line);
229
+ else if (sequence && id.value !== `ADR-${sequence}`) add("id", `id "${id.value}" does not match filename sequence (expected ADR-${sequence})`, id.line);
230
+ const title = fm.get("title");
231
+ if (!title?.value || title.value === "\"\"" || title.value === "''") add("title", "missing or empty `title` field", title?.line);
232
+ const status = fm.get("status");
233
+ if (!status?.value) add("status", "missing `status` field", status?.line);
234
+ else if (!ADR_STATUSES.includes(status.value)) add("status", `invalid status "${status.value}" — must be one of: ${ADR_STATUSES.join(", ")}`, status.line);
235
+ const date = fm.get("date");
236
+ if (!date?.value) add("date", "missing `date` field", date?.line);
237
+ else if (!isValidIsoDate(date.value)) add("date", `invalid date "${date.value}" — must be YYYY-MM-DD`, date.line);
238
+ if (status?.value === "accepted" && !fm.get("discussion.url")?.value) add("discussion", "status is accepted but `discussion.url` is not set", status.line, "warning");
239
+ return findings;
240
+ }
241
+ // src/repo-validation/specs/validate-spec/validate-spec.ts
242
+ /**
243
+ * The findings for one spec's text. Errors: no frontmatter; a missing or unknown `status`; an `id` that is not
244
+ * `SPEC-` and four digits. Warnings: a missing `id` (`holocron specs sync` numbers it, so a new spec needs none); a missing
245
+ * `issue` (every spec has a companion GitHub issue), except on an `archived` or `superseded` spec, many of which
246
+ * predate the issue-first process.
247
+ */
248
+ function validateSpec(file, content) {
249
+ const fm = parseFrontmatter(content);
250
+ if (!fm) return [{
251
+ file,
252
+ line: 1,
253
+ rule: "frontmatter",
254
+ reason: "no frontmatter found",
255
+ severity: "error"
256
+ }];
257
+ const findings = [];
258
+ const status = fm.get("status");
259
+ if (!status?.value) findings.push({
260
+ file,
261
+ line: status?.line ?? 1,
262
+ rule: "status",
263
+ reason: "missing `status` field",
264
+ severity: "error"
265
+ });
266
+ else if (!SPEC_STATUSES.includes(status.value)) findings.push({
267
+ file,
268
+ line: status.line,
269
+ rule: "status",
270
+ reason: `invalid status "${status.value}" — must be one of: ${SPEC_STATUSES.join(", ")}`,
271
+ severity: "error"
272
+ });
273
+ const id = fm.get("id");
274
+ if (!id?.value) findings.push({
275
+ file,
276
+ line: 1,
277
+ rule: "id",
278
+ reason: "missing `id` — `holocron specs sync` numbers a spec once it is on the default branch",
279
+ severity: "warning"
280
+ });
281
+ else if (!/^SPEC-\d{4,}$/.test(id.value)) findings.push({
282
+ file,
283
+ line: id.line,
284
+ rule: "id",
285
+ reason: `invalid id "${id.value}" — must be SPEC- and four digits, such as SPEC-0007`,
286
+ severity: "error"
287
+ });
288
+ if (!fm.get("issue")?.value && status?.value !== "archived" && status?.value !== "superseded") findings.push({
289
+ file,
290
+ line: 1,
291
+ rule: "issue",
292
+ reason: "missing `issue` field — every spec must have a companion GitHub issue",
293
+ severity: "warning"
294
+ });
295
+ return findings;
296
+ }
297
+ // src/repo-validation/specs/check-specs/check-specs.ts
298
+ /**
299
+ * The ADR and spec check over the files it is given: each one that is an ADR or a spec (see `classifySpecPath`) goes to
300
+ * its rules, and every other file is skipped. Whoever calls it decides which files to read (the whole tree, a PR's
301
+ * changed files) and supplies their text; nothing here touches the filesystem or the network.
302
+ *
303
+ * Beyond each file's own rules, two specs may not share an `id`: the later one, in the order given, is an error.
304
+ */
305
+ function checkSpecs(files) {
306
+ const result = {
307
+ fileCount: 0,
308
+ findings: []
309
+ };
310
+ const specIds = /* @__PURE__ */ new Map();
311
+ for (const { path, text } of files) {
312
+ const kind = classifySpecPath(path);
313
+ if (!kind) continue;
314
+ result.fileCount++;
315
+ result.findings.push(...kind === "adr" ? validateAdr(path, text) : validateSpec(path, text));
316
+ const id = kind === "spec" ? parseFrontmatter(text)?.get("id") : void 0;
317
+ if (!id?.value) continue;
318
+ const first = specIds.get(id.value);
319
+ if (first === void 0) specIds.set(id.value, path);
320
+ else result.findings.push({
321
+ file: path,
322
+ line: id.line,
323
+ rule: "id",
324
+ reason: `id "${id.value}" is also the id of ${first}`,
325
+ severity: "error"
326
+ });
327
+ }
328
+ return result;
329
+ }
330
+ // src/repo-validation/specs/discussion-id-line/discussion-id-line.ts
331
+ /**
332
+ * The line of a discussion post's first message that names the document: its id (`SPEC-0007`), and, once the file is on
333
+ * the default branch, the id as a link to the file at its path there: `[SPEC-0007](<address>)`. The address is
334
+ * `https://github.com/<repo>/blob/<branch>/<path>`, kept in angle brackets so the chat service does not expand it into a
335
+ * preview card. Plain text when `file` is not given: while a pull request is open its `PR:` line is the link, and a blob
336
+ * address on a branch where the file does not yet exist leads nowhere. {@link discussionBody} writes it, a file that moved
337
+ * is given its new address with it, and a repair of existing posts compares against it.
338
+ */
339
+ function discussionIdLine(id, file) {
340
+ if (!file) return id;
341
+ const escape = (path) => path.split("/").map(encodeURIComponent).join("/");
342
+ return `[${id}](<https://github.com/${file.repo}/blob/${escape(file.branch)}/${escape(file.path)}>)`;
343
+ }
344
+ // src/repo-validation/specs/discussion-pr-line/discussion-pr-line.ts
345
+ /**
346
+ * The line of a discussion post's first message that names the pull request that added the document:
347
+ * `PR: [#1538](<address>)`. The address is kept in angle brackets so the chat service does not expand it into a preview
348
+ * card. Empty when the pull request is not known, so a post names none. {@link discussionBody} writes it, and a repair of
349
+ * existing posts compares against it.
350
+ */
351
+ function discussionPrLine(pr) {
352
+ return pr ? `PR: [#${pr.number}](<${pr.url}>)` : "";
353
+ }
354
+ // src/repo-validation/specs/discussion-body/discussion-body.ts
355
+ /**
356
+ * The first message of a document's discussion post: its id (a link to the file once it is on the default branch, see
357
+ * {@link discussionIdLine}), a short description, and the pull request that added it,
358
+ * each in a paragraph of its own. The pull request's address is kept in angle brackets so the chat service does not
359
+ * expand it into a preview card. A part that is not known (a document with no summary, one whose pull request cannot
360
+ * be found) is left out, with its blank line.
361
+ */
362
+ function discussionBody({ id, summary, pr, file }) {
363
+ const pull = discussionPrLine(pr);
364
+ return [
365
+ discussionIdLine(id, file),
366
+ summary,
367
+ pull
368
+ ].filter(Boolean).join("\n\n");
369
+ }
370
+ // src/repo-validation/specs/discussion-title/discussion-title.ts
371
+ /** Discord, and most chat services, cap a thread title near this. */
372
+ const MAX_TITLE$1 = 100;
373
+ /**
374
+ * The title of a spec's or ADR's discussion post: the document's own title, in plain text (a title cannot be formatted),
375
+ * cut with an ellipsis so it is at most 100 characters. The title is the document's own (see `specTitle`), already free
376
+ * of markup. Nothing is put in front of it: the status tag says where the document stands and the id is in the first message.
377
+ */
378
+ function discussionTitle(title) {
379
+ return title.length > MAX_TITLE$1 ? `${title.slice(0, 99)}…` : title;
380
+ }
381
+ // src/repo-validation/specs/reconcile-spec-status/reconcile-spec-status.ts
382
+ /**
383
+ * What to do about a spec's status when the file, the tag on its discussion post and the status last synced may all
384
+ * differ. Two values cannot tell "someone retagged" from "the file changed and the tag has not caught up"; the third,
385
+ * the status the post was last in step with, can.
386
+ *
387
+ * - in step (tag is the file's status): nothing, or just record it when the post's last-synced line is stale
388
+ * - the tag is missing (none, or more than one status tag): put the file's status on it
389
+ * - only the file moved since the last sync (a merged edit): set the tag to the file's status
390
+ * - only the tag moved (a gatekeeper retagged): ask for the file to change, through a pull request
391
+ * - both moved, or there is no last-synced status to tell by: report a conflict and change nothing
392
+ *
393
+ * - the tag is `withdrawn` (the post's pull request closed unmerged, #1653): never a retag, since no file has that status.
394
+ * The file's status goes back on the tag, which is what reopening the pull request, or the same file coming back in a
395
+ * new one, needs.
396
+ *
397
+ * A file with no `status` cannot be synced, so that is a conflict too.
398
+ */
399
+ function reconcileSpecStatus({ file, tag, synced }) {
400
+ if (file === void 0) return {
401
+ action: "conflict",
402
+ reason: "the file has no status to sync"
403
+ };
404
+ if (tag === file) return synced === file ? { action: "none" } : {
405
+ action: "record",
406
+ status: file
407
+ };
408
+ if (tag === void 0 || tag === "withdrawn") return {
409
+ action: "set-tag",
410
+ status: file
411
+ };
412
+ if (synced === void 0) return {
413
+ action: "conflict",
414
+ reason: `the file says ${file} and the tag says ${tag}, and nothing says which moved`
415
+ };
416
+ if (synced === file) return {
417
+ action: "request",
418
+ status: tag
419
+ };
420
+ if (synced === tag) return {
421
+ action: "set-tag",
422
+ status: file
423
+ };
424
+ return {
425
+ action: "conflict",
426
+ reason: `the file moved to ${file} and the tag to ${tag} since they last agreed on ${synced}`
427
+ };
428
+ }
429
+ // src/repo-validation/specs/spec-summary/spec-summary.ts
430
+ /** The longest summary a post carries; a chat message caps near 2000 and the post adds a link and a footer. */
431
+ const MAX_SUMMARY = 1e3;
432
+ /** The headings whose first paragraph says what the document is for, in the order they are looked for. */
433
+ const SUMMARY_HEADINGS = /^#{2,3}[ \t]+(problem|why|context|summary|overview)[ \t]*#*[ \t]*$/i;
434
+ /**
435
+ * The first paragraph of a block of lines starting at `from`: skips blank lines, then reads lines up to the next blank
436
+ * one. A heading, a table row or a code fence is not a paragraph, so the search goes on past it.
437
+ */
438
+ function paragraphFrom(lines, from) {
439
+ let i = from;
440
+ while (i < lines.length) {
441
+ const line = lines[i];
442
+ if (line.startsWith("```")) {
443
+ i++;
444
+ while (i < lines.length && !lines[i].startsWith("```")) i++;
445
+ i++;
446
+ continue;
447
+ }
448
+ if (line.trim() === "" || /^(#|\|)/.test(line)) {
449
+ i++;
450
+ continue;
451
+ }
452
+ const block = [];
453
+ while (i < lines.length && lines[i].trim() !== "") block.push(lines[i++].trimEnd());
454
+ return block.join("\n");
455
+ }
456
+ }
457
+ /**
458
+ * A short summary of a spec or ADR for a discussion post: the first paragraph under a `Problem`, `Why`, `Context`,
459
+ * `Summary` or `Overview` heading, else the first paragraph after the title, cut with an ellipsis at 1000 characters.
460
+ * Empty when the document has no paragraph at all. The post links to the file for the rest; the text is not mirrored.
461
+ */
462
+ function specSummary(text) {
463
+ const lines = text.replace(/^---\n[\s\S]*?\n---\n?/, "").split("\n");
464
+ const at = lines.findIndex((line) => SUMMARY_HEADINGS.test(line));
465
+ const found = (at === -1 ? void 0 : paragraphFrom(lines, at + 1)) ?? paragraphFrom(lines, 0) ?? "";
466
+ return found.length > MAX_SUMMARY ? `${found.slice(0, 999)}…` : found;
467
+ }
468
+ // src/repo-validation/specs/spec-title/spec-title.ts
469
+ /** The longest title a discussion post carries. */
470
+ const MAX_TITLE = 100;
471
+ /** Text with the characters that format or link in a chat message removed, runs of whitespace collapsed, and a cap on its length. */
472
+ function plain(text) {
473
+ const cleaned = text.replace(/[[\]()<>`*_~|\\]/g, "").replace(/\s+/g, " ").trim();
474
+ return cleaned.length > MAX_TITLE ? `${cleaned.slice(0, 99)}…` : cleaned;
475
+ }
476
+ /**
477
+ * A spec's title for a chat post: its first `# ` heading after the frontmatter, else its file name without `.spec.md`.
478
+ * What the file says is written by whoever opened the pull request, so the result carries no markdown, brackets or
479
+ * line breaks that could turn it into a link or a layout of its own.
480
+ */
481
+ function specTitle(path, text) {
482
+ const body = text.replace(/^---\n[\s\S]*?\n---\n?/, "");
483
+ const heading = /^#[ \t]+(.+?)[ \t]*#*[ \t]*$/m.exec(body)?.[1];
484
+ const name = path.slice(path.lastIndexOf("/") + 1).replace(/\.spec\.md$/, "");
485
+ return (heading === void 0 ? "" : plain(heading)) || plain(name);
486
+ }
487
+ // src/repo-validation/specs/update-frontmatter/update-frontmatter.ts
488
+ /** The lines of the front matter block, between the two `---` lines. */
489
+ const BLOCK = /^---\n([\s\S]*?)\n---/;
490
+ /**
491
+ * Sets `key: value` on its own line, replacing the line that has the key or adding one: at the end of the block, or at the
492
+ * start with `first`.
493
+ */
494
+ function setField(lines, key, value, first = false) {
495
+ const at = lines.findIndex((line) => new RegExp(`^${key}:`).test(line));
496
+ if (at === -1) return first ? [`${key}: ${value}`, ...lines] : [...lines, `${key}: ${value}`];
497
+ return lines.map((line, i) => i === at ? `${key}: ${value}` : line);
498
+ }
499
+ /**
500
+ * Sets `discussion.url`. The block under `discussion:` is kept: a `url:` line there is replaced, else one is added right
501
+ * under the key, so any other line there stays. A `discussion:` that holds a plain value (an old GitHub Discussion link)
502
+ * becomes a block with the address instead, and a document with no `discussion:` gets one at the end of the front matter.
503
+ */
504
+ function setDiscussionUrl(lines, url) {
505
+ const at = lines.findIndex((line) => /^discussion:/.test(line));
506
+ if (at === -1) return [
507
+ ...lines,
508
+ "discussion:",
509
+ ` url: ${url}`
510
+ ];
511
+ if (lines[at].slice(11).trim() !== "") return [
512
+ ...lines.slice(0, at),
513
+ "discussion:",
514
+ ` url: ${url}`,
515
+ ...lines.slice(at + 1)
516
+ ];
517
+ let end = at + 1;
518
+ while (end < lines.length && /^\s+\S/.test(lines[end])) end++;
519
+ const existing = lines.slice(at + 1, end).findIndex((line) => /^\s+url:/.test(line));
520
+ if (existing !== -1) return lines.map((line, i) => i === at + 1 + existing ? ` url: ${url}` : line);
521
+ return [
522
+ ...lines.slice(0, at + 1),
523
+ ` url: ${url}`,
524
+ ...lines.slice(at + 1)
525
+ ];
526
+ }
527
+ /**
528
+ * A document's text with its front matter changed: `id` and `status` set, and `discussion.url` set to the address of its discussion
529
+ * post. Nothing else in the file moves: the other fields, their order and the body are left as they were. A document
530
+ * with no front matter is returned unchanged.
531
+ */
532
+ function updateFrontmatter(text, changes) {
533
+ const match = BLOCK.exec(text);
534
+ if (!match) return text;
535
+ let lines = match[1].split("\n");
536
+ if (changes.id !== void 0) lines = setField(lines, "id", changes.id, true);
537
+ if (changes.status !== void 0) lines = setField(lines, "status", changes.status);
538
+ if (changes.discussionUrl !== void 0) lines = setDiscussionUrl(lines, changes.discussionUrl);
539
+ return `---\n${lines.join("\n")}\n---${text.slice(match[0].length)}`;
540
+ }
541
+ export { ADR_DIR, ADR_EXEMPT, ADR_STATUSES, CLOSED_STATUSES, SPEC_DIRS, SPEC_STATUSES, WITHDRAWN_STATE, assignSpecIds, checkSpecs, classifySpecPath, discussionBody, discussionIdLine, discussionPrLine, discussionTitle, evaluateDocsPresence, hasDocsSignal, isAddedDocComment, isFeat, isValidIsoDate, packageOf, pageNames, parseFrontmatter, parseSkipDocs, reconcileSpecStatus, specSummary, specTitle, updateFrontmatter, validateAdr, validateSpec };
@@ -1,18 +1,13 @@
1
- //#region src/config/schema.d.ts
2
1
  /**
3
- * The `tasks` config shape — the single manifest of what a repo runs.
4
- * Read from a dedicated `astromech.config.*` file or the `tasks` key of
5
- * `holocron.config.*` (see {@link loadTasksConfig}).
6
- *
7
- * Runtime validation is the loader's job, not this type's — the type only
8
- * describes what an author writes.
2
+ * One entry of the task manifest: a registry task by name, with the options that change how it is generated and
3
+ * run.
9
4
  */
10
5
  interface TaskEntry {
11
6
  /** Registry task name — `verification.unitTests`, `sourceQuality.staticAnalysis`, `delivery.build`, … */
12
7
  name: string;
13
8
  /**
14
9
  * Emit a `.github/workflows/<name>.yml` thin caller and include the task
15
- * in `holocron ci`. Default `true`.
10
+ * in `holocron run ci`. Default `true`.
16
11
  */
17
12
  ci?: boolean;
18
13
  /**
@@ -24,7 +19,7 @@ interface TaskEntry {
24
19
  /**
25
20
  * The task's CI check context (from `WORKFLOW_CHECK_CONTEXTS`) is a
26
21
  * required status check in branch protection (`astromech.requiredChecks()`)
27
- * and part of `holocron ci`'s default run.
22
+ * and part of `holocron run ci`'s default run.
28
23
  */
29
24
  required?: boolean;
30
25
  /** Per-repo overrides on the same channel the reusable workflow reads. */
@@ -40,10 +35,28 @@ interface TaskEntry {
40
35
  turbo?: {
41
36
  /** Extra env vars turbo hashes into this task's cache key, appended to the registry default (empty when the task has none). */
42
37
  passThroughEnv?: string[];
38
+ /**
39
+ * Extra input globs appended to the registry default's `inputs`
40
+ * (holocron#845) — for a package whose layout the registry's
41
+ * `"src/**"` default doesn't cover (e.g. a flat-layout package with
42
+ * no `src/` directory at all). Appended, not replaced: the
43
+ * registry's other inputs (`package.json`, `tsdown.config.ts`, …)
44
+ * stay tracked without needing to be repeated here.
45
+ */
46
+ inputs?: string[];
47
+ /**
48
+ * Extra tasks this one waits for, appended to the registry default's
49
+ * `dependsOn` — for a build the package does not list as a dependency
50
+ * but its task loads anyway (e.g. `staticAnalysis` loading the root
51
+ * ESLint config, which imports a package of the workspace). Turbo
52
+ * syntax: `"<package>#<task>"`, `"^<task>"`.
53
+ */
54
+ dependsOn?: string[];
43
55
  };
44
56
  }
45
57
  /** A task is either its bare name (all defaults) or an entry object. */
46
58
  type TaskConfigItem = string | TaskEntry;
59
+ /** The part of `holocron.config` that holds the task manifest and the switches around it. */
47
60
  interface TasksConfig {
48
61
  /** The manifest. */
49
62
  tasks?: TaskConfigItem[];
@@ -52,18 +65,18 @@ interface TasksConfig {
52
65
  /**
53
66
  * The command the synced `"holocron"` `package.json` script runs. Default
54
67
  * `"holocron"` (the installed bin). The source repo overrides it to run
55
- * its own build, e.g. `"node packages/cli/dist/cli.mjs"`.
68
+ * its own build, e.g. `"node cli/cli/dist/cli.mjs"`.
56
69
  */
57
70
  holocronScript?: string;
58
71
  /**
59
72
  * Required status-check contexts not backed by a task — codecov gates,
60
73
  * a bundle-build check, … Appended to `astromech.requiredChecks()` after the
61
- * `required`-task contexts. (`DCO` is prepended by `holocron setup` itself.)
74
+ * `required`-task contexts. (`DCO` is prepended by `holocron repo setup` itself.)
62
75
  */
63
76
  extraRequiredChecks?: string[];
64
77
  /**
65
- * Git hooks `holocron setup` installs. `true` / `{ prePush: true }` writes
66
- * `.husky/pre-push` (runs `holocron ci`); `false` / `{ prePush: false }`
78
+ * Git hooks `holocron repo setup` installs. `true` / `{ prePush: true }` writes
79
+ * `.husky/pre-push` (runs `holocron run ci`); `false` / `{ prePush: false }`
67
80
  * opts out. Omitted → on for `protection: "strict"` repos, off otherwise.
68
81
  * When enabled, `packageScripts()` also emits `prepare: "husky"`.
69
82
  */
@@ -71,7 +84,4 @@ interface TasksConfig {
71
84
  prePush?: boolean;
72
85
  };
73
86
  }
74
- /** Normalise a `TaskConfigItem` to a full {@link TaskEntry} with defaults applied. */
75
- declare function normalizeTaskEntry(item: TaskConfigItem): Required<Pick<TaskEntry, "name" | "ci" | "local">> & TaskEntry;
76
- //#endregion
77
- export { normalizeTaskEntry as i, TaskEntry as n, TasksConfig as r, TaskConfigItem as t };
87
+ export { TaskEntry as n, TasksConfig as r, TaskConfigItem as t };