@plexus-ms/cli 0.120.0 → 0.121.0

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 (2) hide show
  1. package/dist/plx.js +568 -10
  2. package/package.json +2 -2
package/dist/plx.js CHANGED
@@ -7533,6 +7533,266 @@ var require_lib = __commonJS({
7533
7533
  }
7534
7534
  });
7535
7535
 
7536
+ // ../lib/dist/lints.js
7537
+ var keyOf = (v) => `${v.lint} ${v.file}: ${v.excerpt}`;
7538
+ var renderViolation = (v) => `\u2717 ${v.file}: line ${v.line}: ${v.message}`;
7539
+ var lineAt = (text, index) => {
7540
+ let line = 1;
7541
+ for (let i = 0; i < index; i++)
7542
+ if (text.charCodeAt(i) === 10)
7543
+ line++;
7544
+ return line;
7545
+ };
7546
+ function* matches(text, pattern) {
7547
+ for (const match of text.matchAll(pattern))
7548
+ yield { match, line: lineAt(text, match.index) };
7549
+ }
7550
+ var MONTH = "Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t(?:ember)?)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?";
7551
+ var YEAR = "(?:19|20)\\d{2}";
7552
+ var DATE_OR_VERSION = new RegExp([
7553
+ // 2026-11-04, 2026-07, 2026-11-04T10:00Z
7554
+ `(?<![\\w-])${YEAR}-(?:0[1-9]|1[0-2])(?:-(?:0[1-9]|[12]\\d|3[01])(?:T\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?(?:Z|[+-]\\d{2}:?\\d{2})?)?)?(?![\\w-])`,
7555
+ // November 2026, Nov. 4, 2026
7556
+ `\\b(?:${MONTH})\\.?\\s+(?:\\d{1,2}(?:st|nd|rd|th)?,?\\s+)?${YEAR}\\b`,
7557
+ // in 2026, since 2025, Q3 2026
7558
+ `\\b(?:[Ii]n|[Ss]ince|[Uu]ntil|[Tt]ill|[Aa]s of|[Bb]efore|[Aa]fter|[Dd]uring|[Ee]arly|[Mm]id|[Ll]ate|Q[1-4])\\s+${YEAR}\\b(?![.,]?\\d)`,
7559
+ // 0.111.0, 1.2.3-rc.1; not the dotted parts of an IP address, not a section number
7560
+ "(?<![\\w.\xA7]|\xA7\\s*)(?!1\\.0\\.0(?![\\w-]|\\.\\d))\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.]+)?(?!\\.?\\d)",
7561
+ // v24, v1.48
7562
+ "(?<![\\w./-])v\\d+(?:\\.\\d+)*\\b",
7563
+ // pnpm@12, hk@1.48 (three parts are caught above)
7564
+ "(?<=@)\\d+(?:\\.\\d+)?\\b(?!\\.\\d)"
7565
+ ].join("|"), "g");
7566
+ function proseOf(text) {
7567
+ const lines = text.split("\n");
7568
+ let i = 0;
7569
+ if (lines[0] === "---") {
7570
+ const end = lines.findIndex((l, n) => n > 0 && l === "---");
7571
+ if (end !== -1)
7572
+ for (; i <= end; i++)
7573
+ lines[i] = "";
7574
+ }
7575
+ let fence;
7576
+ for (; i < lines.length; i++) {
7577
+ const line = lines[i] ?? "";
7578
+ const opener = /^\s*(`{3,}|~{3,})/.exec(line)?.[1];
7579
+ if (fence === void 0 && opener) {
7580
+ fence = opener;
7581
+ lines[i] = "";
7582
+ } else if (fence !== void 0) {
7583
+ if (opener?.startsWith(fence[0] ?? "") && opener.length >= fence.length && line.trim() === opener)
7584
+ fence = void 0;
7585
+ lines[i] = "";
7586
+ } else
7587
+ lines[i] = line.replace(/(`+)[^\n]*?\1/g, (span) => " ".repeat(span.length));
7588
+ }
7589
+ return lines.join("\n");
7590
+ }
7591
+ function lintDateOrVersion(text, file) {
7592
+ return [...matches(proseOf(text), DATE_OR_VERSION)].map(({ match, line }) => ({
7593
+ lint: "date-or-version",
7594
+ file,
7595
+ line,
7596
+ excerpt: match[0],
7597
+ message: `a date or version number in prose goes stale; say it once where it is maintained: ${match[0]}`
7598
+ }));
7599
+ }
7600
+ var CODE = "PLX(?:-[A-Z][A-Za-z]+)?(?![A-Za-z])";
7601
+ var NUMBER = "\\d+(?:\\.\\d+)*";
7602
+ var NUMBERS = `${NUMBER}(?:[ \\t\\u00a0]*(?:,|and|or|&|\u2013|-|to)[ \\t\\u00a0]*${NUMBER})*`;
7603
+ var GAP = "(?:[ \\t\\u00a0]+|[ \\t]*\\r?\\n[ \\t]*(?:#+|//+|\\*|>)?[ \\t]*)";
7604
+ var SIGN = `(?<!\xA7)\xA7\xA7?[ \\t\\u00a0]*`;
7605
+ var REQUIREMENT_NAME = "PLX-[A-Z][A-Za-z]+(?:/[A-Z][A-Za-z0-9]*){1,2}";
7606
+ var NAME_LIKE = "PLX-[A-Z][A-Za-z]+(?:/[\\w-]+)+";
7607
+ var FORWARD = new RegExp(`${SIGN}(${NUMBERS})${GAP}(${CODE})`, "g");
7608
+ var REVERSE = new RegExp(`(?<![\\w-])(${CODE})[ \\t\\u00a0]*,?[ \\t\\u00a0]*${SIGN}(${NUMBERS})`, "g");
7609
+ var BARE = new RegExp(`${SIGN}(${NUMBERS})`, "g");
7610
+ var NAME_CITATION = new RegExp(`(?<![\\w/-])${NAME_LIKE}(?![\\w/])`, "g");
7611
+ var sectionKey = (n, code) => `\xA7 ${n} ${code}`;
7612
+ var numbersOf = (list2) => list2.match(new RegExp(NUMBER, "g")) ?? [];
7613
+ function lintCitations(text, file, citable, own) {
7614
+ const codes2 = new Set([...citable].filter((c) => c.startsWith("\xA7 ")).map((c) => c.replace(/^§ \S+ /, "")));
7615
+ const out = [];
7616
+ const sections = (list2, code, line) => {
7617
+ for (const n of numbersOf(list2)) {
7618
+ const excerpt = sectionKey(n, code);
7619
+ if (citable.has(excerpt))
7620
+ continue;
7621
+ const message = codes2.has(code) ? `${excerpt} cites a section that does not exist` : `${excerpt} cites ${code}, which is no module`;
7622
+ out.push({ lint: "citations", file, line, excerpt, message });
7623
+ }
7624
+ };
7625
+ const taken = /* @__PURE__ */ new Set();
7626
+ const signAt = (m) => m.index + m[0].indexOf("\xA7");
7627
+ for (const { match, line } of matches(text, FORWARD)) {
7628
+ taken.add(signAt(match));
7629
+ sections(match[1] ?? "", match[2] ?? "", line);
7630
+ }
7631
+ for (const { match, line } of matches(text, REVERSE)) {
7632
+ if (taken.has(signAt(match)))
7633
+ continue;
7634
+ taken.add(signAt(match));
7635
+ sections(match[2] ?? "", match[1] ?? "", line);
7636
+ }
7637
+ if (own)
7638
+ for (const { match, line } of matches(text, BARE)) {
7639
+ const at = signAt(match);
7640
+ const lineStart = text.lastIndexOf("\n", at) + 1;
7641
+ if (taken.has(at) || /^#+[ \t]*$/.test(text.slice(lineStart, at)))
7642
+ continue;
7643
+ sections(match[1] ?? "", own, line);
7644
+ }
7645
+ const wellFormed = new RegExp(`^${REQUIREMENT_NAME}$`);
7646
+ for (const { match, line } of matches(text, NAME_CITATION)) {
7647
+ const name = match[0];
7648
+ if (!wellFormed.test(name))
7649
+ out.push({
7650
+ lint: "citations",
7651
+ file,
7652
+ line,
7653
+ excerpt: name,
7654
+ message: `${name} is no requirement name: PLX-<Module>[/<Profile>]/<Name>, each segment capitalised`
7655
+ });
7656
+ else if (!citable.has(name))
7657
+ out.push({ lint: "citations", file, line, excerpt: name, message: `${name} names no requirement line` });
7658
+ }
7659
+ return out.sort((a, b) => a.line - b.line);
7660
+ }
7661
+ var MAX_HEADER_LINES = 2;
7662
+ function commentSyntax(file) {
7663
+ const jinja = file.endsWith(".jinja") ? [["{#", "#}"]] : [];
7664
+ const name = file.replace(/\.jinja$/, "");
7665
+ if (/\.(md|mdx|html)$/.test(name))
7666
+ return { blocks: [["<!--", "-->"], ...jinja] };
7667
+ if (/\.(ts|tsx|js|jsx|mjs|cjs|css|json|jsonc|pkl)$/.test(name))
7668
+ return { line: /^\/\//, blocks: [["/*", "*/"], ...jinja] };
7669
+ return { line: /^#(?!!)/, blocks: jinja };
7670
+ }
7671
+ var JINJA_TAG = /\{%-?[\s\S]*?-?%\}/g;
7672
+ var isPreamble = (line) => /^#!/.test(line) || /^#\s*(syntax|escape|check)\s*=/.test(line) || line === "---";
7673
+ function headerLines(text, file) {
7674
+ const syntax = commentSyntax(file);
7675
+ const raw = text.split("\n").map((l) => l.trim());
7676
+ const lines = raw.map((l) => l.replace(JINJA_TAG, "").trim());
7677
+ const jinjaOnly = (n) => (lines[n] ?? "") === "" && (raw[n] ?? "") !== "";
7678
+ const blockEnd = (i2) => {
7679
+ let j = i2;
7680
+ for (; ; ) {
7681
+ const line = lines[j] ?? "";
7682
+ const block = line === "" ? void 0 : syntax.blocks.find(([open]) => line.startsWith(open));
7683
+ if (block) {
7684
+ const [open, close] = block;
7685
+ let k = j;
7686
+ while (k < lines.length - 1 && !(lines[k] ?? "").includes(close, k === j ? open.length : 0))
7687
+ k++;
7688
+ j = k + 1;
7689
+ } else if (line !== "" && syntax.line?.test(line))
7690
+ j++;
7691
+ else
7692
+ return j;
7693
+ }
7694
+ };
7695
+ let i = 0;
7696
+ let content = 0;
7697
+ for (; i < lines.length; i++) {
7698
+ const line = lines[i] ?? "";
7699
+ if (line === "" || isPreamble(line))
7700
+ continue;
7701
+ if (blockEnd(i) > i)
7702
+ break;
7703
+ if (++content > 1)
7704
+ return 0;
7705
+ }
7706
+ if (i >= lines.length)
7707
+ return 0;
7708
+ let end = blockEnd(i);
7709
+ let count = end - i;
7710
+ for (i = end; i < lines.length; ) {
7711
+ if ((lines[i] ?? "") === "" && !jinjaOnly(i)) {
7712
+ i++;
7713
+ continue;
7714
+ }
7715
+ end = blockEnd(i);
7716
+ if (end === i || (lines[end] ?? "") !== "" || jinjaOnly(end))
7717
+ break;
7718
+ count += end - i;
7719
+ i = end;
7720
+ }
7721
+ return count;
7722
+ }
7723
+ function lintTemplateHeader(text, file) {
7724
+ const n = headerLines(text, file);
7725
+ if (n <= MAX_HEADER_LINES)
7726
+ return [];
7727
+ return [
7728
+ {
7729
+ lint: "template-header",
7730
+ file,
7731
+ line: 1,
7732
+ excerpt: `${n} header comment lines`,
7733
+ message: `${n} header comment lines; a template file opens with at most ${MAX_HEADER_LINES}, and the rest lives in the compendium`
7734
+ }
7735
+ ];
7736
+ }
7737
+ var ISSUE_ID = /(?<![\w])([A-Z]{3})-\d+(?![\w])/g;
7738
+ var STANDARD_PREFIXES = /* @__PURE__ */ new Set([
7739
+ "SHA",
7740
+ // hash functions: SHA-256
7741
+ "UTF",
7742
+ // character encodings: UTF-8
7743
+ "GPL",
7744
+ // licence identifiers: GPL-3.0-or-later
7745
+ "PDF",
7746
+ // format versions: PDF-1.4
7747
+ "ADR"
7748
+ // architecture decision records: ADR-0009
7749
+ ]);
7750
+ function lintIssueIds(text, file) {
7751
+ return [...matches(text, ISSUE_ID)].filter(({ match }) => !STANDARD_PREFIXES.has(match[1] ?? "")).map(({ match, line }) => ({
7752
+ lint: "issue-id",
7753
+ file,
7754
+ line,
7755
+ excerpt: match[0],
7756
+ message: `${match[0]} reads as an issue identifier; say what it means instead`
7757
+ }));
7758
+ }
7759
+ var AUTO_COMMENT_CHARS = "#;@!$%^&|:";
7760
+ function lintCommitMessage(text, comment = "#") {
7761
+ const chars = comment === "auto" ? [...AUTO_COMMENT_CHARS] : [comment];
7762
+ const ends = chars.flatMap((c) => {
7763
+ const q2 = c.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
7764
+ return [new RegExp(`^${q2} -+ >8 -+$`, "m"), new RegExp(`^${q2} Please enter the commit message`, "m")];
7765
+ }).map((p) => text.search(p)).filter((n) => n !== -1);
7766
+ return lintIssueIds(ends.length > 0 ? text.slice(0, Math.min(...ends)) : text, "commit message");
7767
+ }
7768
+
7769
+ // ../lib/dist/baseline.js
7770
+ var BASELINE_FILE = "plx-baseline.txt";
7771
+ var HEADER = [
7772
+ "# Known violations of `plx requirements`: burn them down, never add to them.",
7773
+ "# One per line, as often as each occurs; `plx requirements --write-baseline` rewrites the file."
7774
+ ];
7775
+ var parseBaseline = (text) => text.split("\n").map((l) => l.trimEnd()).filter((l) => l !== "" && !l.startsWith("#"));
7776
+ var renderBaseline = (violations) => `${[...HEADER, ...violations.map(keyOf).sort()].join("\n")}
7777
+ `;
7778
+ function compareBaseline(violations, baseline) {
7779
+ const left = /* @__PURE__ */ new Map();
7780
+ for (const key of baseline)
7781
+ left.set(key, (left.get(key) ?? 0) + 1);
7782
+ const fresh = [];
7783
+ let known = 0;
7784
+ for (const v of violations) {
7785
+ const n = left.get(keyOf(v)) ?? 0;
7786
+ if (n > 0) {
7787
+ left.set(keyOf(v), n - 1);
7788
+ known++;
7789
+ } else
7790
+ fresh.push(v);
7791
+ }
7792
+ const stale = [...left].flatMap(([key, n]) => Array(n).fill(key));
7793
+ return { fresh, stale: stale.sort(), known };
7794
+ }
7795
+
7536
7796
  // ../lib/dist/frontmatter.js
7537
7797
  function frontmatterLines(lines) {
7538
7798
  if (lines[0] !== "---")
@@ -9098,11 +9358,179 @@ async function propagate(ctx, options) {
9098
9358
 
9099
9359
  // ../lib/dist/requirements.js
9100
9360
  import { join as join8 } from "node:path";
9361
+
9362
+ // ../lib/dist/standard-index.json
9363
+ var standard_index_default = {
9364
+ version: "0.121.0",
9365
+ citable: [
9366
+ "\xA7 1 PLX",
9367
+ "\xA7 1.1 PLX",
9368
+ "\xA7 1.2 PLX",
9369
+ "\xA7 1.3 PLX",
9370
+ "\xA7 1.4 PLX",
9371
+ "\xA7 1.5 PLX",
9372
+ "\xA7 1.6 PLX",
9373
+ "\xA7 1.7 PLX",
9374
+ "\xA7 1.8 PLX",
9375
+ "\xA7 2 PLX",
9376
+ "\xA7 2.1 PLX",
9377
+ "\xA7 2.2 PLX",
9378
+ "\xA7 2.3 PLX",
9379
+ "\xA7 2.4 PLX",
9380
+ "\xA7 2.5 PLX",
9381
+ "\xA7 2.6 PLX",
9382
+ "\xA7 2.7 PLX",
9383
+ "\xA7 3 PLX",
9384
+ "\xA7 3.1 PLX",
9385
+ "\xA7 3.2 PLX",
9386
+ "\xA7 3.3 PLX",
9387
+ "\xA7 3.4 PLX",
9388
+ "\xA7 4 PLX",
9389
+ "\xA7 4.1 PLX",
9390
+ "\xA7 4.2 PLX",
9391
+ "\xA7 4.3 PLX",
9392
+ "\xA7 4.4 PLX",
9393
+ "\xA7 4.5 PLX",
9394
+ "\xA7 4.6 PLX",
9395
+ "\xA7 4.7 PLX",
9396
+ "\xA7 5 PLX",
9397
+ "\xA7 5.1 PLX",
9398
+ "\xA7 5.2 PLX",
9399
+ "\xA7 5.3 PLX",
9400
+ "\xA7 6 PLX",
9401
+ "\xA7 6.1 PLX",
9402
+ "\xA7 6.2 PLX",
9403
+ "\xA7 6.3 PLX",
9404
+ "\xA7 6.4 PLX",
9405
+ "\xA7 6.5 PLX",
9406
+ "\xA7 6.6 PLX",
9407
+ "\xA7 6.7 PLX",
9408
+ "\xA7 6.8 PLX",
9409
+ "\xA7 6.9 PLX",
9410
+ "\xA7 7 PLX",
9411
+ "\xA7 7.1 PLX",
9412
+ "\xA7 7.2 PLX",
9413
+ "\xA7 7.3 PLX",
9414
+ "\xA7 7.4 PLX",
9415
+ "\xA7 7.5 PLX",
9416
+ "\xA7 7.6 PLX",
9417
+ "\xA7 7.7 PLX",
9418
+ "\xA7 8 PLX",
9419
+ "\xA7 8.1 PLX",
9420
+ "\xA7 8.2 PLX",
9421
+ "\xA7 8.3 PLX",
9422
+ "\xA7 8.4 PLX",
9423
+ "\xA7 8.5 PLX",
9424
+ "\xA7 8.6 PLX",
9425
+ "\xA7 8.7 PLX",
9426
+ "\xA7 9 PLX",
9427
+ "\xA7 10 PLX",
9428
+ "\xA7 10.1 PLX",
9429
+ "\xA7 10.2 PLX",
9430
+ "\xA7 10.3 PLX",
9431
+ "\xA7 10.4 PLX",
9432
+ "\xA7 10.5 PLX",
9433
+ "\xA7 11 PLX",
9434
+ "\xA7 11.1 PLX",
9435
+ "\xA7 11.2 PLX",
9436
+ "\xA7 11.3 PLX",
9437
+ "\xA7 11.4 PLX",
9438
+ "\xA7 11.5 PLX",
9439
+ "\xA7 11.6 PLX",
9440
+ "\xA7 12 PLX",
9441
+ "\xA7 12.1 PLX",
9442
+ "\xA7 12.2 PLX",
9443
+ "\xA7 12.3 PLX",
9444
+ "\xA7 12.4 PLX",
9445
+ "\xA7 12.5 PLX",
9446
+ "\xA7 12.6 PLX",
9447
+ "\xA7 13 PLX",
9448
+ "\xA7 13.1 PLX",
9449
+ "\xA7 13.2 PLX",
9450
+ "\xA7 13.3 PLX",
9451
+ "\xA7 13.4 PLX",
9452
+ "\xA7 13.5 PLX",
9453
+ "\xA7 1 PLX-AppStateful",
9454
+ "\xA7 2 PLX-AppStateful",
9455
+ "\xA7 3 PLX-AppStateful",
9456
+ "\xA7 1 PLX-AppStateless",
9457
+ "\xA7 1 PLX-App",
9458
+ "\xA7 2 PLX-App",
9459
+ "\xA7 3 PLX-App",
9460
+ "\xA7 4 PLX-App",
9461
+ "\xA7 5 PLX-App",
9462
+ "\xA7 6 PLX-App",
9463
+ "\xA7 7 PLX-App",
9464
+ "\xA7 1 PLX-Environment",
9465
+ "\xA7 2 PLX-Environment",
9466
+ "\xA7 1 PLX-Host",
9467
+ "\xA7 2 PLX-Host",
9468
+ "\xA7 1 PLX-Repo",
9469
+ "\xA7 2 PLX-Repo",
9470
+ "\xA7 3 PLX-Repo",
9471
+ "\xA7 1 PLX-Tenancy",
9472
+ "\xA7 2 PLX-Tenancy",
9473
+ "\xA7 3 PLX-Tenancy",
9474
+ "\xA7 4 PLX-Tenancy",
9475
+ "\xA7 1 PLX-CLI",
9476
+ "\xA7 2 PLX-CLI",
9477
+ "\xA7 3 PLX-CLI",
9478
+ "\xA7 4 PLX-CLI",
9479
+ "\xA7 5 PLX-CLI",
9480
+ "\xA7 6 PLX-CLI",
9481
+ "\xA7 1 PLX-Delivery",
9482
+ "\xA7 2 PLX-Delivery",
9483
+ "\xA7 3 PLX-Delivery",
9484
+ "\xA7 4 PLX-Delivery",
9485
+ "\xA7 5 PLX-Delivery",
9486
+ "\xA7 6 PLX-Delivery",
9487
+ "\xA7 7 PLX-Delivery",
9488
+ "\xA7 8 PLX-Delivery",
9489
+ "\xA7 1 PLX-Infrastructure",
9490
+ "\xA7 2 PLX-Infrastructure",
9491
+ "\xA7 3 PLX-Infrastructure",
9492
+ "\xA7 1 PLX-Ingress",
9493
+ "\xA7 2 PLX-Ingress",
9494
+ "\xA7 1 PLX-JS",
9495
+ "\xA7 1 PLX-Platform",
9496
+ "\xA7 2 PLX-Platform",
9497
+ "\xA7 3 PLX-Platform",
9498
+ "\xA7 1 PLX-Secrets",
9499
+ "\xA7 2 PLX-Secrets",
9500
+ "\xA7 3 PLX-Secrets",
9501
+ "\xA7 1 PLX-Updates",
9502
+ "\xA7 2 PLX-Updates",
9503
+ "\xA7 3 PLX-Updates"
9504
+ ]
9505
+ };
9506
+
9507
+ // ../lib/dist/standardIndex.js
9508
+ var STANDARD_INDEX_FILE = "packages/lib/src/standard-index.json";
9509
+ var bundledIndex = () => checked(standard_index_default);
9510
+ function checked(value) {
9511
+ const { version: version2, citable } = value ?? {};
9512
+ if (typeof version2 !== "string" || !Array.isArray(citable) || !citable.every((c) => typeof c === "string"))
9513
+ throw new Error(`${STANDARD_INDEX_FILE} is not a citable index`);
9514
+ return { version: version2, citable };
9515
+ }
9516
+
9517
+ // ../lib/dist/requirements.js
9101
9518
  var KEYWORD = /MUST|SHOULD|MAY/;
9102
9519
  var hasKeyword = (line) => KEYWORD.test(line.replace(/MUSTs|SHOULDs|MAYs/g, ""));
9520
+ function requirementName(bullet) {
9521
+ const span = /^`(PLX-[^`\s]*\/[^`\s]*)`(:\s)?/.exec(bullet);
9522
+ if (!span)
9523
+ return void 0;
9524
+ const name = span[1] ?? "";
9525
+ if (!new RegExp(`^${REQUIREMENT_NAME}$`).test(name))
9526
+ return { name, malformed: "the format is PLX-<Module>[/<Profile>]/<Name>, each segment capitalised" };
9527
+ if (!span[2])
9528
+ return { name, malformed: "a name is followed by a colon and a blank" };
9529
+ return { name };
9530
+ }
9103
9531
  var list = (value) => value.replace(/^\s*\[/, "").replace(/\].*$/, "").split(",").map((s) => s.trim()).filter(Boolean);
9104
9532
  function scanPage(text, name, mode) {
9105
- const scan = { defects: [], requirements: [], depends: [], consumes: [] };
9533
+ const scan = { defects: [], requirements: [], sections: [], names: [], depends: [], consumes: [] };
9106
9534
  const lines = text.split("\n");
9107
9535
  const defect = (n, msg) => scan.defects.push(`\u2717 ${name}: line ${n + 1}: ${msg}`);
9108
9536
  let i = 0;
@@ -9148,6 +9576,7 @@ function scanPage(text, name, mode) {
9148
9576
  if (maintaining)
9149
9577
  defect(i, "numbered section after Maintaining");
9150
9578
  section = heading[1] ?? "";
9579
+ scan.sections.push(section);
9151
9580
  started = true;
9152
9581
  continue;
9153
9582
  }
@@ -9160,8 +9589,16 @@ function scanPage(text, name, mode) {
9160
9589
  defect(i, `requirement under Maintaining: ${line}`);
9161
9590
  else if (!started)
9162
9591
  defect(i, "requirement before the first \xA7 heading");
9163
- else
9592
+ else {
9164
9593
  scan.requirements.push(`\xA7 ${section} ${line.slice(4)}`);
9594
+ const named = requirementName(line.slice(4));
9595
+ if (named?.malformed)
9596
+ defect(i, `malformed requirement name ${named.name}: ${named.malformed}`);
9597
+ else if (named && named.name.split("/")[0] !== scan.code)
9598
+ defect(i, `requirement name ${named.name} does not start with the page's code, ${scan.code}`);
9599
+ else if (named)
9600
+ scan.names.push(named.name);
9601
+ }
9165
9602
  continue;
9166
9603
  }
9167
9604
  if (line.startsWith(">")) {
@@ -9213,17 +9650,28 @@ async function checkCompendium(ctx, compendium) {
9213
9650
  for (const [code, where] of byCode)
9214
9651
  if (where.length > 1)
9215
9652
  defects.push(`\u2717 duplicate module code: ${code}`);
9653
+ const named = /* @__PURE__ */ new Set();
9654
+ for (const s of scans.values())
9655
+ for (const name of s.names) {
9656
+ if (named.has(name))
9657
+ defects.push(`\u2717 duplicate requirement name: ${name}`);
9658
+ named.add(name);
9659
+ const module = name.split("/")[0] ?? "";
9660
+ const base = [...byCode.keys()].find((c) => c !== module && new RegExp(`^${c}[A-Z][a-z]+$`).test(module));
9661
+ if (base)
9662
+ defects.push(`\u2717 requirement name ${name} spells a profile of ${base} as a module; a profile's lines are named ${base}/<Profile>/<Name> on the page of ${base}`);
9663
+ }
9216
9664
  for (const s of scans.values())
9217
9665
  for (const dep of s.depends)
9218
9666
  if (!byCode.has(dep))
9219
9667
  defects.push(`\u2717 unknown module in depends: ${dep}`);
9220
- const kindOf2 = (page) => page.startsWith("contracts/") ? "contract" : "approach";
9668
+ const kindOf3 = (page) => page.startsWith("contracts/") ? "contract" : "approach";
9221
9669
  const side = (binds2) => binds2 === "repo" || binds2 === "app" ? "dev" : "ops";
9222
- const kinds = new Map([...byCode].map(([code, [page = ""]]) => [code, kindOf2(page)]));
9670
+ const kinds = new Map([...byCode].map(([code, [page = ""]]) => [code, kindOf3(page)]));
9223
9671
  const binds = new Map([...byCode].map(([code, [page = ""]]) => [code, scans.get(page)?.binds ?? ""]));
9224
9672
  for (const [page, s] of scans) {
9225
9673
  const m = s.code ?? page.replace(/.*\//, "");
9226
- const kind = kindOf2(page);
9674
+ const kind = kindOf3(page);
9227
9675
  for (const c of s.consumes) {
9228
9676
  if (kind === "contract")
9229
9677
  defects.push(`\u2717 ${m} is a contract and consumes ${c}; a contract has no other side to consume`);
@@ -9247,6 +9695,101 @@ async function checkCompendium(ctx, compendium) {
9247
9695
  approaches: pages.filter((p) => p.startsWith("approaches/")).length
9248
9696
  };
9249
9697
  }
9698
+ async function readCitable(ctx, compendium) {
9699
+ return (await readPages(ctx, compendium)).citable;
9700
+ }
9701
+ async function readPages(ctx, compendium) {
9702
+ const own = /* @__PURE__ */ new Map([[MAP_PAGE, "PLX"]]);
9703
+ const citable = scanPage(await ctx.readFile(join8(compendium, MAP_PAGE)), MAP_PAGE, "map").sections.map((n) => `\xA7 ${n} PLX`);
9704
+ for (const page of await modulePages(ctx, compendium)) {
9705
+ const scan = scanPage(await ctx.readFile(join8(compendium, page)), page, "module");
9706
+ if (!scan.code)
9707
+ continue;
9708
+ own.set(page, scan.code);
9709
+ citable.push(...scan.sections.map((n) => `\xA7 ${n} ${scan.code}`), ...scan.names);
9710
+ }
9711
+ return { citable, own };
9712
+ }
9713
+ var COPIER_FILES = ["copier.yml", "copier.yaml"];
9714
+ async function kindOf2(ctx, dir) {
9715
+ if (await ctx.readFile(join8(dir, MAP_PAGE)).then(() => true, () => false))
9716
+ return { kind: "compendium" };
9717
+ for (const file of COPIER_FILES) {
9718
+ const text = await ctx.readFile(join8(dir, file)).catch(() => void 0);
9719
+ const sub = text === void 0 ? void 0 : /^_subdirectory:\s*["']?([^"'\s#]+)/m.exec(text)?.[1];
9720
+ if (sub)
9721
+ return { kind: "template", templateDir: sub.replace(/\/+$/, "") };
9722
+ }
9723
+ return { kind: "repo" };
9724
+ }
9725
+ async function trackedFiles(ctx, dir) {
9726
+ const out = await ctx.read("git", ["ls-files", "-z"], { cwd: dir }).catch(() => {
9727
+ throw new Error(`${dir} is not a git checkout; the lints read its tracked files`);
9728
+ });
9729
+ return out.split("\0").filter(Boolean).sort();
9730
+ }
9731
+ async function lintRepo(ctx, dir, options = {}) {
9732
+ const { kind, templateDir } = await kindOf2(ctx, dir);
9733
+ const result = { kind, against: "", defects: [], violations: [] };
9734
+ let index;
9735
+ let own = /* @__PURE__ */ new Map();
9736
+ if (kind === "compendium") {
9737
+ const check = await checkCompendium(ctx, dir);
9738
+ Object.assign(result, { defects: check.defects, contracts: check.contracts, approaches: check.approaches });
9739
+ const pages = await readPages(ctx, dir);
9740
+ index = { version: "this checkout", citable: pages.citable };
9741
+ own = pages.own;
9742
+ result.against = "this compendium";
9743
+ } else if (options.compendium) {
9744
+ index = { version: options.compendium, citable: await readCitable(ctx, options.compendium) };
9745
+ result.against = `the compendium at ${options.compendium}`;
9746
+ } else {
9747
+ index = bundledIndex();
9748
+ result.against = `Plexus ${index.version}, the index this plx carries`;
9749
+ }
9750
+ const citable = new Set(index.citable);
9751
+ for (const file of await trackedFiles(ctx, dir)) {
9752
+ if (file === BASELINE_FILE)
9753
+ continue;
9754
+ const text = await ctx.readFile(join8(dir, file)).catch(() => void 0);
9755
+ if (text === void 0 || text.includes("\0"))
9756
+ continue;
9757
+ if (kind === "compendium" && /\.mdx?$/.test(file))
9758
+ result.violations.push(...lintDateOrVersion(text, file));
9759
+ result.violations.push(...lintCitations(text, file, citable, own.get(file)));
9760
+ if (templateDir && file.startsWith(`${templateDir}/`))
9761
+ result.violations.push(...lintTemplateHeader(text, file));
9762
+ result.violations.push(...lintIssueIds(text, file));
9763
+ }
9764
+ return result;
9765
+ }
9766
+ async function checkRepo(ctx, dir, options = {}) {
9767
+ const lint = await lintRepo(ctx, dir, options);
9768
+ const baseline = parseBaseline(await ctx.readFile(join8(dir, BASELINE_FILE)).catch(() => ""));
9769
+ const { fresh, stale, known } = compareBaseline(lint.violations, baseline);
9770
+ return {
9771
+ kind: lint.kind,
9772
+ against: lint.against,
9773
+ defects: [
9774
+ ...lint.defects,
9775
+ ...fresh.map(renderViolation),
9776
+ ...stale.map((key) => `\u2717 ${BASELINE_FILE}: no longer occurs, remove it: ${key}`)
9777
+ ],
9778
+ known,
9779
+ contracts: lint.contracts,
9780
+ approaches: lint.approaches
9781
+ };
9782
+ }
9783
+ async function planBaseline(ctx, dir, options = {}) {
9784
+ const lint = await lintRepo(ctx, dir, options);
9785
+ ctx.say(`\u2022 ${lint.violations.length} known violations \u2192 ${BASELINE_FILE}`);
9786
+ return [write(join8(dir, BASELINE_FILE), renderBaseline(lint.violations))];
9787
+ }
9788
+ async function checkCommitMessage(ctx, file, dir) {
9789
+ const config = async (key) => (await ctx.read("git", ["config", "--get", key], { cwd: dir }).catch(() => "")).trim();
9790
+ const comment = await config("core.commentString") || await config("core.commentChar") || "#";
9791
+ return lintCommitMessage(await ctx.readFile(file), comment);
9792
+ }
9250
9793
 
9251
9794
  // ../lib/dist/summary.js
9252
9795
  function mergeLine(urls) {
@@ -14342,21 +14885,36 @@ function register6(program2) {
14342
14885
  // src/commands/requirements.ts
14343
14886
  import { join as join10, resolve as resolve7 } from "node:path";
14344
14887
  function register7(program2) {
14345
- program2.command("requirements").description("lint the standard's map and module pages, or extract one module's requirement lines").argument("[dir]", "a checkout of the compendium", ".").option("--extract <page>", "print a module page's requirement lines instead of linting (path relative to dir)").action(async (dir, opts, command) => {
14888
+ program2.command("requirements").description(
14889
+ "lint a repo: the standard's pages in the compendium, citations, dates, template headers and issue identifiers everywhere"
14890
+ ).argument("[dir]", "a repo checkout: the compendium, a template or any other repo", ".").option("--extract <page>", "print a module page's requirement lines instead of linting (path relative to dir)").option("--write-baseline", `record every current violation in ${BASELINE_FILE} as known, instead of checking`).option("--commit-msg <file>", "check a commit message for issue identifiers instead (the commit-msg hook)").option("--compendium <dir>", "resolve citations against this compendium checkout, not this plx's own index").action(async (dir, opts, command) => {
14346
14891
  const ctx = contextOf2(command);
14347
- const compendium = resolve7(dir);
14892
+ const repo = resolve7(dir);
14893
+ const options = { compendium: opts.compendium ? resolve7(opts.compendium) : void 0 };
14348
14894
  if (opts.extract) {
14349
- ctx.result(extractRequirements(await ctx.readFile(join10(compendium, opts.extract))));
14895
+ ctx.result(extractRequirements(await ctx.readFile(join10(repo, opts.extract))));
14896
+ return;
14897
+ }
14898
+ if (opts.commitMsg) {
14899
+ const violations = await checkCommitMessage(ctx, resolve7(opts.commitMsg), repo);
14900
+ ctx.result(violations, (vs) => vs.map(renderViolation).join("\n"));
14901
+ if (violations.length > 0) process.exitCode = 1;
14902
+ return;
14903
+ }
14904
+ if (opts.writeBaseline) {
14905
+ await ctx.apply(await planBaseline(ctx, repo, options));
14350
14906
  return;
14351
14907
  }
14352
- const check = await checkCompendium(ctx, compendium);
14908
+ const check = await checkRepo(ctx, repo, options);
14353
14909
  ctx.result(check, renderCheck);
14354
14910
  if (check.defects.length > 0) process.exitCode = 1;
14355
14911
  });
14356
14912
  }
14357
14913
  function renderCheck(c) {
14358
14914
  if (c.defects.length > 0) return c.defects.join("\n");
14359
- return `\u2713 the map, ${c.contracts} contracts and ${c.approaches} approaches are well-formed`;
14915
+ const what = c.kind === "compendium" ? `the map, ${c.contracts} contracts and ${c.approaches} approaches are well-formed; ` : "";
14916
+ const known = c.known > 0 ? `, ${c.known} known violations in ${BASELINE_FILE}` : "";
14917
+ return `\u2713 ${what}citations resolve against ${c.against}${known}`;
14360
14918
  }
14361
14919
 
14362
14920
  // src/commands/update.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plexus-ms/cli",
3
- "version": "0.120.0",
3
+ "version": "0.121.0",
4
4
  "description": "plx, the Plexus command-line tool: a single-script adapter over @plexus-ms/lib",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@inquirer/prompts": "^8.7.5",
27
- "@plexus-ms/lib": "0.120.0",
27
+ "@plexus-ms/lib": "0.121.0",
28
28
  "commander": "^15.0.0"
29
29
  },
30
30
  "devDependencies": {