@futurelastic/colab-handbook 1.16.0-rc.1 → 1.16.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/audit/audit.mjs CHANGED
@@ -91,6 +91,8 @@ const stamp = require("../tools/lib/stamp.js");
91
91
  const { missingConventionLabels, staleConventionDescriptions, MINIMAL_LABEL_NAMES } = require("../tools/lib/labels.js");
92
92
  // #393: "adopted locally, not committed" — one classifier, shared with `colab adopt --local`.
93
93
  const { localAdoptionState } = require("../tools/lib/local-adopt.js");
94
+ // #158 heading slugs, shared with the rule-inventory check (#632).
95
+ const { collectHeadingSlugs } = require("../tools/lib/md-anchors.js");
94
96
  // #144's authority-flip precedence ladder — shared with `tools/colab` for the same reason
95
97
  // every other cross-tool reading in this file is: two implementations of "which key governs"
96
98
  // is exactly the two-places-drift disease this handbook exists to kill.
@@ -2505,59 +2507,9 @@ function splitDerivedSpans(text) {
2505
2507
  return { authoredLines, malformed };
2506
2508
  }
2507
2509
 
2508
- // Minimal GitHub-compatible heading→anchor slugifier (#158). GitHub's real algorithm is
2509
- // unpublished; this is deliberately the common-case subset, calibrated against the 47
2510
- // anchor links already live in this repo (CLAUDE.md, CONVENTIONS.md, README*.md,
2511
- // project.schema.md, skills/handbook-sync/SKILL.md, tools/README.md) — every one of
2512
- // them resolves under it. Not a general markdown-heading parser: it does not need to be,
2513
- // because the only headings it is ever asked to slugify are the ones already governing
2514
- // the links this check exists to validate.
2515
- function slugifyHeading(text) {
2516
- return text
2517
- .replace(/`([^`]*)`/g, "$1") // code spans contribute their literal text, not backticks
2518
- .replace(/\[([^\]]*)\]\([^)]*\)/g, "$1") // [text](url) contributes only the text
2519
- .trim()
2520
- .replace(/#+$/, "") // a trailing "##" some repos use to mark a self-anchor
2521
- .toLowerCase()
2522
- // strip punctuation, keep Unicode letters/digits, underscore, hyphens/spaces -- NOT
2523
- // collapsed. `\w` is ASCII-only ([A-Za-z0-9_]); GitHub's real slugifier keeps Unicode
2524
- // letters (Vietnamese, Japanese, accented Latin, ...), so `\w` alone silently deleted
2525
- // them and produced a slug GitHub never renders (#280). `\p{L}`/`\p{N}` (with the `/u`
2526
- // flag) widen letter/digit matching to Unicode while `_` stays its own explicit member
2527
- // of the class -- it must NOT be folded into `\p{L}`/`\p{N}`, because the very next
2528
- // step below (`.replace(/[ _]/g, "-")`) turns underscores into hyphens and needs them
2529
- // to survive this line to do it; the issue's own one-line suggestion dropped `_` from
2530
- // the class and would have silently broken every underscored heading slug.
2531
- .replace(/[^\p{L}\p{N}_\- ]+/gu, "")
2532
- .trim()
2533
- // Each space/underscore becomes its OWN hyphen -- never collapsed. GitHub does not
2534
- // merge runs: a heading like "tier -- required" strips the em-dash but keeps both
2535
- // spaces around where it was, producing "tier--required" (double hyphen), and every
2536
- // link already written against a real heading in this repo is punctuated that way.
2537
- // Collapsing here silently breaks every one of them.
2538
- .replace(/[ _]/g, "-");
2539
- }
2540
-
2541
- // Every heading in `text`, in document order, mapped to its resolved slug — including
2542
- // GitHub's duplicate-slug suffixing (`-1`, `-2`, … in heading order, not alphabetical).
2543
- // Fenced code blocks are skipped so a `#` inside a code sample is never read as a heading.
2544
- function collectHeadingSlugs(text) {
2545
- const slugs = new Set();
2546
- const seen = new Map(); // base slug -> next suffix to try
2547
- let inFence = false;
2548
- for (const line of text.split("\n")) {
2549
- if (/^\s*(```|~~~)/.test(line)) { inFence = !inFence; continue; }
2550
- if (inFence) continue;
2551
- const m = /^#{1,6}\s+(.+?)\s*$/.exec(line);
2552
- if (!m) continue;
2553
- const base = slugifyHeading(m[1]);
2554
- if (!base) continue;
2555
- const n = seen.get(base) ?? 0;
2556
- seen.set(base, n + 1);
2557
- slugs.add(n === 0 ? base : `${base}-${n}`);
2558
- }
2559
- return slugs;
2560
- }
2510
+ // slugifyHeading + collectHeadingSlugs live in tools/lib/md-anchors.js (#632) — one slugifier,
2511
+ // shared with scripts/check-rule-inventory.mjs, so an inventory `dest#anchor` and a doc link
2512
+ // cannot disagree about what a heading's anchor is.
2561
2513
 
2562
2514
  // Every `](target#fragment)` markdown link, repo-relative to the file that carries it.
2563
2515
  // `target` is `""` for a same-file link (`[…](#slug)`); anything already resolved by the
package/package.json CHANGED
@@ -33,5 +33,5 @@
33
33
  "engines": {
34
34
  "node": ">=18"
35
35
  },
36
- "version": "1.16.0-rc.1"
36
+ "version": "1.16.0-rc.2"
37
37
  }
@@ -0,0 +1,60 @@
1
+ 'use strict';
2
+ // md-anchors — the heading-to-anchor slugs a markdown link or an inventory `dest#anchor` resolves
3
+ // against. Moved out of audit/audit.mjs (#158) by #632 so the audit and
4
+ // scripts/check-rule-inventory.mjs share one slugifier.
5
+
6
+ // Minimal GitHub-compatible heading→anchor slugifier (#158). GitHub's real algorithm is
7
+ // unpublished; this is deliberately the common-case subset, calibrated against the 47
8
+ // anchor links already live in this repo (CLAUDE.md, CONVENTIONS.md, README*.md,
9
+ // project.schema.md, skills/handbook-sync/SKILL.md, tools/README.md) — every one of
10
+ // them resolves under it. Not a general markdown-heading parser: it does not need to be,
11
+ // because the only headings it is ever asked to slugify are the ones already governing
12
+ // the links this check exists to validate.
13
+ function slugifyHeading(text) {
14
+ return text
15
+ .replace(/`([^`]*)`/g, "$1") // code spans contribute their literal text, not backticks
16
+ .replace(/\[([^\]]*)\]\([^)]*\)/g, "$1") // [text](url) contributes only the text
17
+ .trim()
18
+ .replace(/#+$/, "") // a trailing "##" some repos use to mark a self-anchor
19
+ .toLowerCase()
20
+ // strip punctuation, keep Unicode letters/digits, underscore, hyphens/spaces -- NOT
21
+ // collapsed. `\w` is ASCII-only ([A-Za-z0-9_]); GitHub's real slugifier keeps Unicode
22
+ // letters (Vietnamese, Japanese, accented Latin, ...), so `\w` alone silently deleted
23
+ // them and produced a slug GitHub never renders (#280). `\p{L}`/`\p{N}` (with the `/u`
24
+ // flag) widen letter/digit matching to Unicode while `_` stays its own explicit member
25
+ // of the class -- it must NOT be folded into `\p{L}`/`\p{N}`, because the very next
26
+ // step below (`.replace(/[ _]/g, "-")`) turns underscores into hyphens and needs them
27
+ // to survive this line to do it; the issue's own one-line suggestion dropped `_` from
28
+ // the class and would have silently broken every underscored heading slug.
29
+ .replace(/[^\p{L}\p{N}_\- ]+/gu, "")
30
+ .trim()
31
+ // Each space/underscore becomes its OWN hyphen -- never collapsed. GitHub does not
32
+ // merge runs: a heading like "tier -- required" strips the em-dash but keeps both
33
+ // spaces around where it was, producing "tier--required" (double hyphen), and every
34
+ // link already written against a real heading in this repo is punctuated that way.
35
+ // Collapsing here silently breaks every one of them.
36
+ .replace(/[ _]/g, "-");
37
+ }
38
+
39
+ // Every heading in `text`, in document order, mapped to its resolved slug — including
40
+ // GitHub's duplicate-slug suffixing (`-1`, `-2`, … in heading order, not alphabetical).
41
+ // Fenced code blocks are skipped so a `#` inside a code sample is never read as a heading.
42
+ function collectHeadingSlugs(text) {
43
+ const slugs = new Set();
44
+ const seen = new Map(); // base slug -> next suffix to try
45
+ let inFence = false;
46
+ for (const line of text.split("\n")) {
47
+ if (/^\s*(```|~~~)/.test(line)) { inFence = !inFence; continue; }
48
+ if (inFence) continue;
49
+ const m = /^#{1,6}\s+(.+?)\s*$/.exec(line);
50
+ if (!m) continue;
51
+ const base = slugifyHeading(m[1]);
52
+ if (!base) continue;
53
+ const n = seen.get(base) ?? 0;
54
+ seen.set(base, n + 1);
55
+ slugs.add(n === 0 ? base : `${base}-${n}`);
56
+ }
57
+ return slugs;
58
+ }
59
+
60
+ module.exports = { slugifyHeading, collectHeadingSlugs };