@orkestrel/guide 0.0.15 → 0.0.17

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.
@@ -2,23 +2,41 @@ import { createMarkdown, flattenText, isCodeBlockNode, isCodeSpanNode, isEmphasi
2
2
  import { arrayOf, arrayShape, createContract, isEmptyString, isNonEmptyArray, isNonEmptyString, isString, literalOf, literalShape, objectShape, recordOf, stringShape, unionOf, unionShape } from "@orkestrel/contract";
3
3
  //#region src/core/constants.ts
4
4
  /**
5
- * The `## Surface` heading text a guide's documented exports section is keyed on.
5
+ * Lists the declaration keywords a documented or exported symbol carries, in
6
+ * the order the reflection grammar names them.
7
+ *
8
+ * @remarks
9
+ * One frozen list feeds the `ExportKeyword` type, the `isExportKeyword` guard, and
10
+ * `surfaceSymbolShape`, so a keyword cannot be admitted by one and refused by
11
+ * another. Comment and template payload is excluded before reflection, and
12
+ * `enum` is outside this population rather than forbidden by general package
13
+ * policy.
14
+ */
15
+ var EXPORT_KEYWORDS = Object.freeze([
16
+ "type",
17
+ "interface",
18
+ "const",
19
+ "function",
20
+ "class"
21
+ ]);
22
+ /**
23
+ * Names the `## Surface` heading text a guide's documented exports section is keyed on.
6
24
  */
7
25
  var SURFACE = "Surface";
8
26
  /**
9
- * The `## Methods` heading text a guide's documented interface-methods section is keyed on.
27
+ * Names the `## Methods` heading text a guide's documented interface-methods section is keyed on.
10
28
  */
11
29
  var METHODS = "Methods";
12
30
  /**
13
- * The `## Tests` heading text a guide's documented test-link section is keyed on.
31
+ * Names the `## Tests` heading text a guide's documented test-link section is keyed on.
14
32
  */
15
33
  var TESTS = "Tests";
16
34
  /**
17
- * The `## By concept` heading text the manifest's run-map table is keyed on.
35
+ * Names the `## By concept` heading text the manifest's run-map table is keyed on.
18
36
  */
19
37
  var MANIFEST = "By concept";
20
38
  /**
21
- * The link `href` schemes a guides-parity link check skips as external — a link
39
+ * Lists the link `href` schemes a guides-parity link check skips as external — a link
22
40
  * with one of these prefixes (or a bare `#` anchor, handled separately in
23
41
  * `isExternalLink`) is never resolved against the filesystem.
24
42
  */
@@ -31,42 +49,43 @@ var EXTERNAL_SCHEMES = Object.freeze([
31
49
  //#endregion
32
50
  //#region src/core/validators.ts
33
51
  /**
34
- * Whether `value` is one of the five documented {@link ExportKind} literals — the
35
- * guard behind extracting a Surface table's `Kind` cell into a typed symbol.
52
+ * Checks whether `value` is one of the documented {@link ExportKeyword}
53
+ * literals — the guard behind extracting a Surface table's `Kind` cell into a
54
+ * typed symbol.
36
55
  *
37
56
  * @param value - The candidate value
38
- * @returns `true` when `value` is a valid {@link ExportKind}
57
+ * @returns True if `value` is a valid {@link ExportKeyword}; false otherwise
39
58
  *
40
59
  * @example
41
60
  * ```ts
42
- * isExportKind('class') // true
43
- * isExportKind('enum') // false
61
+ * isExportKeyword('class') // true
62
+ * isExportKeyword('enum') // false
44
63
  * ```
45
64
  */
46
- var isExportKind = literalOf("type", "interface", "const", "function", "class");
65
+ var isExportKeyword = literalOf(EXPORT_KEYWORDS);
47
66
  /**
48
- * Whether `value` is a well-formed {@link SurfaceSymbol} — a `name` string
49
- * paired with a valid {@link ExportKind}.
67
+ * Checks whether `value` is a well-formed {@link SurfaceSymbol} — a `name`
68
+ * string paired with a valid {@link ExportKeyword}.
50
69
  *
51
70
  * @param value - The value to test
52
- * @returns `true` when `value` is a well-formed {@link SurfaceSymbol}
71
+ * @returns True if `value` is a well-formed {@link SurfaceSymbol}; false otherwise
53
72
  *
54
73
  * @example
55
74
  * ```ts
56
- * isSurfaceSymbol({ name: 'Markdown', kind: 'class' }) // true
57
- * isSurfaceSymbol({ name: 'Markdown', kind: 'enum' }) // false
75
+ * isSurfaceSymbol({ name: 'Markdown', keyword: 'class' }) // true
76
+ * isSurfaceSymbol({ name: 'Markdown', keyword: 'enum' }) // false
58
77
  * ```
59
78
  */
60
79
  var isSurfaceSymbol = recordOf({
61
80
  name: isString,
62
- kind: isExportKind
81
+ keyword: isExportKeyword
63
82
  });
64
83
  /**
65
- * Whether `value` is a well-formed {@link MethodGroup} — a backticked
84
+ * Checks whether `value` is a well-formed {@link MethodGroup} — a backticked
66
85
  * `interface` name paired with its documented `methods`.
67
86
  *
68
87
  * @param value - The value to test
69
- * @returns `true` when `value` is a well-formed {@link MethodGroup}
88
+ * @returns True if `value` is a well-formed {@link MethodGroup}; false otherwise
70
89
  *
71
90
  * @example
72
91
  * ```ts
@@ -79,11 +98,12 @@ var isMethodGroup = recordOf({
79
98
  methods: arrayOf(isString)
80
99
  });
81
100
  /**
82
- * Whether `value` is a well-formed {@link ManifestEntry} — a `## By concept`
83
- * manifest row, its `source` accepting either a single directory or several.
101
+ * Checks whether `value` is a well-formed {@link ManifestEntry} — a
102
+ * `## By concept` manifest row, its `source` accepting either a single directory
103
+ * or several.
84
104
  *
85
105
  * @param value - The value to test
86
- * @returns `true` when `value` is a well-formed {@link ManifestEntry}
106
+ * @returns True if `value` is a well-formed {@link ManifestEntry}; false otherwise
87
107
  *
88
108
  * @example
89
109
  * ```ts
@@ -100,7 +120,7 @@ var isManifestEntry = recordOf({
100
120
  //#endregion
101
121
  //#region src/core/helpers.ts
102
122
  /**
103
- * Extract aligned physical source-line records in one character traversal.
123
+ * Extracts aligned physical source-line records in one character traversal.
104
124
  * Real line and block comments and complete template tokens become spaces in
105
125
  * {@link SourceLine.code}, while ordinary code, quoted strings, and recognized
106
126
  * regex literals retain their columns. Genuine JSDoc opened from reflection
@@ -589,12 +609,12 @@ function extractSourceLines(source) {
589
609
  return lines;
590
610
  }
591
611
  /**
592
- * Whether an opaque inventory key contains only canonical slash-separated
612
+ * Checks whether an opaque inventory key contains only canonical slash-separated
593
613
  * segments. Empty, `.` and `..` segments are rejected without rewriting the
594
614
  * key; ordinary dotfile segments remain valid.
595
615
  *
596
616
  * @param key - The opaque inventory key to inspect
597
- * @returns `true` when every segment is canonical
617
+ * @returns True if every segment is canonical; false otherwise
598
618
  *
599
619
  * @example
600
620
  * ```ts
@@ -606,7 +626,7 @@ function hasCanonicalSegments(key) {
606
626
  return key.split("/").every((segment) => segment !== "" && segment !== "." && segment !== "..");
607
627
  }
608
628
  /**
609
- * A module scope normalized to its canonical directory list. `'.'` represents
629
+ * Normalizes a module scope to its canonical directory list. `'.'` represents
610
630
  * workspace root; empty, trailing, and dot-segment spellings reduce through
611
631
  * {@link resolvePath}, and duplicates are removed in first-seen order.
612
632
  *
@@ -631,7 +651,7 @@ function normalizeDirectories(module) {
631
651
  return directories;
632
652
  }
633
653
  /**
634
- * The stable cache key for a {@link GuideModule}. Directories normalize before
654
+ * Computes the stable cache key for a {@link GuideModule}. Directories normalize before
635
655
  * joining, so equivalent module spellings share one key. The NUL separator
636
656
  * cannot occur in filesystem-backed canonical-segment inventory keys, so no
637
657
  * directory boundary can collide with directory text.
@@ -641,14 +661,14 @@ function normalizeDirectories(module) {
641
661
  *
642
662
  * @example
643
663
  * ```ts
644
- * moduleKey(['src/core', 'src/browser']) // 'src/core\0src/browser'
664
+ * computeModuleKey(['src/core', 'src/browser']) // 'src/core\0src/browser'
645
665
  * ```
646
666
  */
647
- function moduleKey(module) {
667
+ function computeModuleKey(module) {
648
668
  return normalizeDirectories(module).join("\0");
649
669
  }
650
670
  /**
651
- * The exact opaque file-inventory keys belonging under any canonical
671
+ * Selects the exact opaque file-inventory keys belonging under any canonical
652
672
  * {@link GuideModule} directory, sorted. `'.'` selects canonical root-relative
653
673
  * keys without accepting `/`, `./`, or `../` aliases. Every selected exact
654
674
  * `index.ts` and every `.test.ts` key is excluded independent of scope order.
@@ -676,22 +696,22 @@ function selectModuleKeys(files, module) {
676
696
  return keys.sort();
677
697
  }
678
698
  /**
679
- * The bijection key for a surface symbol — its kind and name combined — so a
680
- * symbol-set comparison diffs (name, kind) pairs rather than names alone.
699
+ * Computes the bijection key for a surface symbol — its keyword and name combined — so a
700
+ * symbol-set comparison diffs (name, keyword) pairs rather than names alone.
681
701
  *
682
702
  * @param symbol - The symbol to key
683
- * @returns The `${kind} ${name}` key
703
+ * @returns The `${keyword} ${name}` key
684
704
  *
685
705
  * @example
686
706
  * ```ts
687
- * symbolKey({ name: 'Markdown', kind: 'class' }) // 'class Markdown'
707
+ * computeSymbolKey({ name: 'Markdown', keyword: 'class' }) // 'class Markdown'
688
708
  * ```
689
709
  */
690
- function symbolKey(symbol) {
691
- return `${symbol.kind} ${symbol.name}`;
710
+ function computeSymbolKey(symbol) {
711
+ return `${symbol.keyword} ${symbol.name}`;
692
712
  }
693
713
  /**
694
- * The names present in `names` but absent from `source` — the set-difference
714
+ * Finds the names present in `names` but absent from `source` — the set-difference
695
715
  * behind a both-directions bijection assertion.
696
716
  *
697
717
  * @param names - The candidate names
@@ -708,7 +728,7 @@ function findMissing(names, source) {
708
728
  return names.filter((name) => !existing.has(name));
709
729
  }
710
730
  /**
711
- * The fences whose language is absent from the caller's listed languages.
731
+ * Finds the fences whose language is absent from the caller's listed languages.
712
732
  * Untagged fences are always returned because they have no language to list.
713
733
  *
714
734
  * @param fences - The guide fences to check
@@ -726,9 +746,9 @@ function findUnlisted(fences, languages) {
726
746
  return fences.filter((fence) => fence.language === void 0 || !listed.has(fence.language));
727
747
  }
728
748
  /**
729
- * The symbol-key set-difference between two symbol lists — `symbols` present but
730
- * absent from `source`, compared by {@link symbolKey} so a symbol can drift in
731
- * neither name nor kind.
749
+ * Finds the symbol-key set-difference between two symbol lists — `symbols` present but
750
+ * absent from `source`, compared by {@link computeSymbolKey} so a symbol can drift in
751
+ * neither name nor keyword.
732
752
  *
733
753
  * @param symbols - The candidate symbols
734
754
  * @param source - The symbols to compare against
@@ -736,14 +756,14 @@ function findUnlisted(fences, languages) {
736
756
  *
737
757
  * @example
738
758
  * ```ts
739
- * missingSymbols([{ name: 'X', kind: 'class' }], []) // ['class X']
759
+ * findMissingSymbols([{ name: 'X', keyword: 'class' }], []) // ['class X']
740
760
  * ```
741
761
  */
742
- function missingSymbols(symbols, source) {
743
- return findMissing(symbols.map(symbolKey), source.map(symbolKey));
762
+ function findMissingSymbols(symbols, source) {
763
+ return findMissing(symbols.map(computeSymbolKey), source.map(computeSymbolKey));
744
764
  }
745
765
  /**
746
- * The names in `names` that have no example — a fence containing the name at a
766
+ * Finds the names in `names` that have no example — a fence containing the name at a
747
767
  * word boundary in `fences`, or a membership in `examples`, both count as
748
768
  * "has an example"; presence-only, fence and JSDoc content are never checked.
749
769
  *
@@ -762,25 +782,25 @@ function findUnexampled(names, fences, examples) {
762
782
  const exampled = new Set(examples);
763
783
  return names.filter((name) => {
764
784
  if (exampled.has(name)) return false;
765
- const boundary = new RegExp(`\\b${name}\\b`);
785
+ const boundary = new RegExp(`\\b${escapeRegExp(name)}\\b`);
766
786
  return !fences.some((fence) => boundary.test(fence));
767
787
  });
768
788
  }
769
789
  /**
770
- * Parse a fence's `import` statements into per-specifier imported identifier
771
- * names — handles `import type`, mixed multiline braces, and `x as y` aliases
772
- * (resolved to the local name `x`... the ORIGINAL exported name, since it is
773
- * the export that must exist in the checked public/barrel surface).
790
+ * Parses a fence's `import` statements into per-specifier imported identifier
791
+ * names — handles `import type`, mixed multiline braces, and `x as y` aliases,
792
+ * resolving each alias to the exported name `x` because that is the name the
793
+ * checked barrel surface must hold.
774
794
  *
775
795
  * @param fence - A ```ts Patterns fence's verbatim body text
776
796
  * @returns One entry per `import ... from 'specifier'` statement, in fence order
777
797
  *
778
798
  * @example
779
799
  * ```ts
780
- * fenceImports("import { a, b as c } from 'x'\n") // [{ specifier: 'x', names: ['a', 'b'] }]
800
+ * extractFenceImports("import { a, b as c } from 'x'\n") // [{ specifier: 'x', names: ['a', 'b'] }]
781
801
  * ```
782
802
  */
783
- function fenceImports(fence) {
803
+ function extractFenceImports(fence) {
784
804
  const results = [];
785
805
  const pattern = /import\s+(?:type\s+)?\{([^}]*)\}\s*from\s*['"]([^'"]+)['"]/gs;
786
806
  let match;
@@ -799,11 +819,11 @@ function fenceImports(fence) {
799
819
  return results;
800
820
  }
801
821
  /**
802
- * Whether a link `href` should be skipped by the guides-parity link checks — an
803
- * external scheme ({@link EXTERNAL_SCHEMES}) or a bare in-document `#` anchor.
822
+ * Checks whether a guides-parity link check skips a link `href` — an external
823
+ * scheme ({@link EXTERNAL_SCHEMES}) or a bare in-document `#` anchor.
804
824
  *
805
825
  * @param href - The link destination
806
- * @returns `true` when the link should not be resolved against the filesystem
826
+ * @returns True if a link check leaves the href unresolved against the filesystem; false otherwise
807
827
  *
808
828
  * @example
809
829
  * ```ts
@@ -816,7 +836,7 @@ function isExternalLink(href) {
816
836
  return EXTERNAL_SCHEMES.some((scheme) => href.startsWith(scheme));
817
837
  }
818
838
  /**
819
- * Resolve a relative `target` from a root-relative `directory`, normalizing
839
+ * Resolves a relative `target` from a root-relative `directory`, normalizing
820
840
  * forward-slash dot segments without filesystem or extension inference. A
821
841
  * parent pops only a retained real component; every excess leading parent is
822
842
  * preserved.
@@ -847,7 +867,7 @@ function resolvePath(directory, target) {
847
867
  return segments.length === 0 ? "." : segments.join("/");
848
868
  }
849
869
  /**
850
- * Resolve a relative `target` from the directory containing a root-relative
870
+ * Resolves a relative `target` from the directory containing a root-relative
851
871
  * declaring `file`. A slashless file belongs to the workspace root; path
852
872
  * reduction is delegated to {@link resolvePath}.
853
873
  *
@@ -866,7 +886,7 @@ function resolveLink(file, target) {
866
886
  return resolvePath(index < 0 ? "." : file.slice(0, index), target);
867
887
  }
868
888
  /**
869
- * The first code-span value found by descending an inline node list, following
889
+ * Finds the first code-span value by descending an inline node list, following
870
890
  * into `emphasis` / `link` / `image` children — the extraction rule behind a
871
891
  * Surface or Methods table row's first-column identifier.
872
892
  *
@@ -875,30 +895,30 @@ function resolveLink(file, target) {
875
895
  *
876
896
  * @example
877
897
  * ```ts
878
- * firstCode([{ element: 'codeSpan', value: 'Markdown' }]) // 'Markdown'
898
+ * findFirstCode([{ element: 'codeSpan', value: 'Markdown' }]) // 'Markdown'
879
899
  * ```
880
900
  */
881
- function firstCode(nodes) {
901
+ function findFirstCode(nodes) {
882
902
  for (const node of nodes) {
883
903
  if (isCodeSpanNode(node)) return node.value;
884
904
  if (isEmphasisNode(node) || isLinkNode(node) || isImageNode(node)) {
885
- const value = firstCode(node.children);
905
+ const value = findFirstCode(node.children);
886
906
  if (value !== void 0) return value;
887
907
  }
888
908
  }
889
909
  }
890
910
  /**
891
- * The link hrefs found within one table cell's inline content.
911
+ * Extracts the link hrefs within one table cell's inline content.
892
912
  *
893
913
  * @param cell - The cell's inline nodes
894
914
  * @returns The cell's link hrefs, in walk order
895
915
  *
896
916
  * @example
897
917
  * ```ts
898
- * cellLinks([{ element: 'link', href: 'x.ts', children: [] }]) // ['x.ts']
918
+ * extractCellLinks([{ element: 'link', href: 'x.ts', children: [] }]) // ['x.ts']
899
919
  * ```
900
920
  */
901
- function cellLinks(cell) {
921
+ function extractCellLinks(cell) {
902
922
  const links = [];
903
923
  for (const node of walkNodes({
904
924
  element: "paragraph",
@@ -907,7 +927,7 @@ function cellLinks(cell) {
907
927
  return links;
908
928
  }
909
929
  /**
910
- * The identifier prefix of a code-span text — everything before its first `<`,
930
+ * Returns the identifier prefix of a code-span text — everything before its first `<`,
911
931
  * trimmed. Guide cells and headings may annotate a generic-parameterized name
912
932
  * (`MarkdownHandler<TNode, T>`) for readability, but the bijection key is the
913
933
  * bare identifier the source scanner captures, so both sides must normalize
@@ -918,16 +938,16 @@ function cellLinks(cell) {
918
938
  *
919
939
  * @example
920
940
  * ```ts
921
- * identifierOf('MarkdownHandler<TNode, T>') // 'MarkdownHandler'
922
- * identifierOf('fold') // 'fold'
941
+ * normalizeIdentifier('MarkdownHandler<TNode, T>') // 'MarkdownHandler'
942
+ * normalizeIdentifier('fold') // 'fold'
923
943
  * ```
924
944
  */
925
- function identifierOf(code) {
945
+ function normalizeIdentifier(code) {
926
946
  const index = code.indexOf("<");
927
947
  return (index < 0 ? code : code.slice(0, index)).trim();
928
948
  }
929
949
  /**
930
- * The index of a table's `Kind` column, found by its header text so it survives
950
+ * Finds the index of a table's `Kind` column by its header text so it survives
931
951
  * column reordering. The match is exact and case-sensitive (`'Kind'`) — a table
932
952
  * without that exact header contributes no symbols to the surface it feeds.
933
953
  *
@@ -936,10 +956,10 @@ function identifierOf(code) {
936
956
  *
937
957
  * @example
938
958
  * ```ts
939
- * kindIndex(table) // 1, or undefined
959
+ * findKindIndex(table) // 1, or undefined
940
960
  * ```
941
961
  */
942
- function kindIndex(table) {
962
+ function findKindIndex(table) {
943
963
  for (let index = 0; index < table.header.length; index += 1) {
944
964
  const cell = table.header[index];
945
965
  if (cell !== void 0 && flattenText({
@@ -949,10 +969,11 @@ function kindIndex(table) {
949
969
  }
950
970
  }
951
971
  /**
952
- * The module-scope exports declared in one file's source text — matches
972
+ * Extracts the module-scope exports declared in one file's source text — matches
953
973
  * `export (async)? (function(\*)?|class|const|interface|type) Name`, deduped
954
- * by (kind, name). A generator export (`export function* walk`) scans as kind
955
- * `function` — its trailing `*` is stripped before the {@link ExportKind} check.
974
+ * by (keyword, name). A generator export (`export function* walk`) scans as the
975
+ * `function` keyword — its trailing `*` is stripped before the
976
+ * {@link ExportKeyword} check.
956
977
  * Scanning uses {@link extractSourceLines}, so comment and template payload is
957
978
  * excluded while its uninterrupted column-zero head remains required; preserved
958
979
  * columns do not grant membership to leading/interrupted comment forms. The population is
@@ -964,38 +985,37 @@ function kindIndex(table) {
964
985
  *
965
986
  * @example
966
987
  * ```ts
967
- * exportsFrom('export class Markdown {}\n') // [{ name: 'Markdown', kind: 'class' }]
968
- * exportsFrom('export function* walk() {}\n') // [{ name: 'walk', kind: 'function' }]
988
+ * extractExports('export class Markdown {}\n') // [{ name: 'Markdown', keyword: 'class' }]
989
+ * extractExports('export function* walk() {}\n') // [{ name: 'walk', keyword: 'function' }]
969
990
  * ```
970
991
  */
971
- function exportsFrom(source) {
992
+ function extractExports(source) {
972
993
  const symbols = [];
973
994
  const seen = /* @__PURE__ */ new Set();
974
995
  for (const line of extractSourceLines(source)) {
975
996
  const match = line.code.match(/^export (?:async )?(function\*?|class|const|interface|type) (\w+)/);
976
- const rawKind = match?.[1];
997
+ const rawKeyword = match?.[1];
977
998
  const name = match?.[2];
978
- const kind = rawKind === void 0 ? void 0 : rawKind.replace(/\*$/, "");
979
- if (!isNonEmptyString(kind) || !isNonEmptyString(name) || !isExportKind(kind)) continue;
980
- const key = `${kind} ${name}`;
999
+ const keyword = rawKeyword === void 0 ? void 0 : rawKeyword.replace(/\*$/, "");
1000
+ if (!isNonEmptyString(keyword) || !isNonEmptyString(name) || !isExportKeyword(keyword)) continue;
1001
+ const key = `${keyword} ${name}`;
981
1002
  if (seen.has(key)) continue;
982
1003
  seen.add(key);
983
1004
  symbols.push({
984
1005
  name,
985
- kind
1006
+ keyword
986
1007
  });
987
1008
  }
988
1009
  return symbols;
989
1010
  }
990
1011
  /**
991
- * The module-scope declarations LACKING the `export` keyword in one file's
992
- * source text — the mirror image of {@link exportsFrom}'s grammar, anchored
1012
+ * Extracts the module-scope declarations lacking the `export` keyword in one file's
1013
+ * source text — the mirror image of {@link extractExports}'s grammar, anchored
993
1014
  * the same way (column 0, so an indented inner declaration never matches).
994
- * Scans only the five {@link ExportKind} keywords (`function` / `class` /
995
- * `const` / `interface` / `type`) — a module-scope `let` or `var` is a
996
- * different violation class (AGENTS §1 bans `var`; a bare `let` is not a
997
- * declaration kind this scanner's five-kind grammar covers) and is out of
998
- * this check's contract. Scanning uses {@link extractSourceLines}, so comment
1015
+ * Scans only the {@link ExportKeyword} keywords (`function` / `class` /
1016
+ * `const` / `interface` / `type`) — a module-scope `let` or `var` is outside
1017
+ * this scanner's declaration-keyword grammar and out of this check's contract.
1018
+ * Scanning uses {@link extractSourceLines}, so comment
999
1019
  * and template payload is excluded while its uninterrupted column-zero head
1000
1020
  * remains required; preserved columns do not widen membership. `enum` is likewise outside this reflection population, not
1001
1021
  * forbidden by general package policy.
@@ -1005,32 +1025,32 @@ function exportsFrom(source) {
1005
1025
  *
1006
1026
  * @example
1007
1027
  * ```ts
1008
- * hiddenFrom('function secretHelper() {}\n') // [{ name: 'secretHelper', kind: 'function' }]
1009
- * hiddenFrom('export class X {}\n') // []
1028
+ * extractHidden('function secretHelper() {}\n') // [{ name: 'secretHelper', keyword: 'function' }]
1029
+ * extractHidden('export class X {}\n') // []
1010
1030
  * ```
1011
1031
  */
1012
- function hiddenFrom(source) {
1032
+ function extractHidden(source) {
1013
1033
  const symbols = [];
1014
1034
  const seen = /* @__PURE__ */ new Set();
1015
1035
  for (const line of extractSourceLines(source)) {
1016
1036
  if (line.code.startsWith("export ")) continue;
1017
1037
  const match = line.code.match(/^(?:async )?(function\*?|class|const|interface|type) (\w+)/);
1018
- const rawKind = match?.[1];
1038
+ const rawKeyword = match?.[1];
1019
1039
  const name = match?.[2];
1020
- const kind = rawKind === void 0 ? void 0 : rawKind.replace(/\*$/, "");
1021
- if (!isNonEmptyString(kind) || !isNonEmptyString(name) || !isExportKind(kind)) continue;
1022
- const key = `${kind} ${name}`;
1040
+ const keyword = rawKeyword === void 0 ? void 0 : rawKeyword.replace(/\*$/, "");
1041
+ if (!isNonEmptyString(keyword) || !isNonEmptyString(name) || !isExportKeyword(keyword)) continue;
1042
+ const key = `${keyword} ${name}`;
1023
1043
  if (seen.has(key)) continue;
1024
1044
  seen.add(key);
1025
1045
  symbols.push({
1026
1046
  name,
1027
- kind
1047
+ keyword
1028
1048
  });
1029
1049
  }
1030
1050
  return symbols;
1031
1051
  }
1032
1052
  /**
1033
- * Join the declaration head starting at `start` into one space-separated
1053
+ * Joins the declaration head starting at `start` into one space-separated
1034
1054
  * line, consuming lines until the first that ends with `{`.
1035
1055
  *
1036
1056
  * @param lines - The file's source lines
@@ -1055,37 +1075,87 @@ function joinHead(lines, start) {
1055
1075
  }
1056
1076
  }
1057
1077
  /**
1058
- * The body lines of the named `export class` / `export interface` declaration
1059
- * within one file's source text — everything between a projected real head and
1060
- * projected column-0 closing `}`. Structural eligibility is projected while the
1061
- * corresponding returned body lines remain raw for JSDoc evidence.
1078
+ * Escapes every regex metacharacter in a literal string so it reads as text
1079
+ * inside a larger `RegExp` source rather than as syntax.
1080
+ *
1081
+ * @remarks
1082
+ * Every caller-supplied name reaches a `RegExp` through this: {@link
1083
+ * extractDeclaration} splices it into the head grammar and {@link
1084
+ * findUnexampled} into a word-boundary search, so a name carrying `$`, `(`,
1085
+ * `[`, or `.` matches that character literally instead of throwing or matching
1086
+ * text it does not name. Pure and total; never throws.
1087
+ *
1088
+ * @param value - The literal string to escape
1089
+ * @returns `value` with every regex metacharacter backslash-escaped
1090
+ *
1091
+ * @example
1092
+ * ```ts
1093
+ * escapeRegExp('A.B') // 'A\\.B'
1094
+ * new RegExp(`^${escapeRegExp('A.B')}$`).test('AxB') // false
1095
+ * ```
1096
+ */
1097
+ function escapeRegExp(value) {
1098
+ return value.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
1099
+ }
1100
+ /**
1101
+ * Locates the named `export class` / `export interface` declaration in one
1102
+ * file's source text and returns its body lines and its base identifiers read
1103
+ * from that one head, so a body and a heritage clause always come from the same
1104
+ * declaration.
1105
+ *
1106
+ * @remarks
1107
+ * The head is matched on projected lines (column 0, an oxfmt-wrapped signature
1108
+ * joined through {@link joinHead}), with an optional generic parameter list and
1109
+ * an optional heritage clause between the identifier and the opening `{`; the
1110
+ * identifier matches exactly and is escaped through {@link escapeRegExp}, so a
1111
+ * metacharacter in `name` is literal text. The returned body lines are the raw
1112
+ * source between that head and the first projected column-zero `}`, keeping
1113
+ * JSDoc evidence intact. Every balanced `<...>` span is removed from the head
1114
+ * before its `extends` clause is read, so a `T extends Base` type parameter is
1115
+ * never a base and `Base<T>` reads as `Base`; a class's `implements` clause and
1116
+ * everything after it is excluded, and a qualified base such as
1117
+ * `namespace.Base` is returned verbatim. A head that opens no column-zero close
1118
+ * is skipped and the scan continues, so a later real declaration still answers.
1062
1119
  *
1063
1120
  * @param source - The file's source text to search
1064
1121
  * @param keyword - Whether to look for a `class` or an `interface`
1065
1122
  * @param name - The declaration's identifier
1066
- * @returns The declaration's body lines, or an empty array when `source` does not declare it
1123
+ * @returns Its body and bases, or `undefined` when `source` declares no such head
1067
1124
  *
1068
1125
  * @example
1069
1126
  * ```ts
1070
- * declarationBody('export interface X {\n\twalk(): void\n}\n', 'interface', 'X') // ['\twalk(): void']
1127
+ * extractDeclaration('export interface X extends Y {\n\twalk(): void\n}\n', 'interface', 'X')
1128
+ * // { body: ['\twalk(): void'], bases: ['Y'] }
1071
1129
  * ```
1072
1130
  */
1073
- function declarationBody(source, keyword, name) {
1131
+ function extractDeclaration(source, keyword, name) {
1074
1132
  const opener = `export ${keyword} ${name}`;
1075
- const declaration = new RegExp(`^export ${keyword} ${name}(?:<.*>)?(?: .*)? \\{$`);
1133
+ const grammar = new RegExp(`^${escapeRegExp(opener)}(?:<.*>)?(?: .*)? \\{$`);
1076
1134
  const lines = extractSourceLines(source);
1077
1135
  const projected = lines.map((line) => line.code);
1078
1136
  for (let index = 0; index < projected.length; index += 1) {
1079
1137
  const line = projected[index];
1080
1138
  if (line === void 0 || !line.startsWith(opener)) continue;
1081
1139
  const head = joinHead(projected, index);
1082
- if (head === void 0 || !declaration.test(head.text)) continue;
1083
- for (let close = head.end + 1; close < projected.length; close += 1) if (projected[close] === "}") return lines.slice(head.end + 1, close).map((record) => record.source);
1140
+ if (head === void 0 || !grammar.test(head.text)) continue;
1141
+ let depth = 0;
1142
+ let flat = "";
1143
+ for (const character of head.text.slice(opener.length, -1)) if (character === "<") depth += 1;
1144
+ else if (character === ">") depth = Math.max(0, depth - 1);
1145
+ else if (depth === 0) flat += character;
1146
+ const clause = flat.replace(/\bimplements\b[\s\S]*$/, "").match(/\bextends\b([\s\S]*)$/)?.[1];
1147
+ const bases = clause === void 0 ? [] : clause.split(",").map((base) => base.trim()).filter(isNonEmptyString);
1148
+ for (let close = head.end + 1; close < projected.length; close += 1) {
1149
+ if (projected[close] !== "}") continue;
1150
+ return {
1151
+ body: lines.slice(head.end + 1, close).map((record) => record.source),
1152
+ bases
1153
+ };
1154
+ }
1084
1155
  }
1085
- return [];
1086
1156
  }
1087
1157
  /**
1088
- * The member lines declaring a callable member: plain, `async`, generator
1158
+ * Selects the member lines declaring a callable member: plain, `async`, generator
1089
1159
  * (`*`), and optional (`records?(`) methods all count; getters, setters,
1090
1160
  * `static` members, and `#` privates never do (their keyword or `#` breaks
1091
1161
  * the `name(` shape). Matching runs once over projected lines so commented
@@ -1096,32 +1166,32 @@ function declarationBody(source, keyword, name) {
1096
1166
  *
1097
1167
  * @example
1098
1168
  * ```ts
1099
- * memberMethods(['\tmap(): void', '\tfilter(): void']) // ['filter', 'map']
1169
+ * extractMemberMethods(['\tmap(): void', '\tfilter(): void']) // ['filter', 'map']
1100
1170
  * ```
1101
1171
  */
1102
- function memberMethods(lines) {
1172
+ function extractMemberMethods(lines) {
1103
1173
  const methods = [];
1104
1174
  for (const line of extractSourceLines(lines.join("\n"))) {
1105
- const method = line.code.match(/^\t(?:async )?\*?(\w+)(<.*>)?\??\(/);
1175
+ const method = line.code.match(/^\t(?:async )?\*?(\w+)\??(<.*>)?\(/);
1106
1176
  if (method?.[1] !== void 0) methods.push(method[1]);
1107
1177
  }
1108
1178
  return Array.from(new Set(methods)).sort();
1109
1179
  }
1110
1180
  /**
1111
- * The block nodes under the named `##` heading, up to the next `##`-or-higher
1181
+ * Selects the block nodes under the named `##` heading, up to the next `##`-or-higher
1112
1182
  * heading (or the document's end) — the section-scoping window `extractSurface` /
1113
1183
  * `extractMethods` walk over.
1114
1184
  *
1115
1185
  * @param document - The parsed guide document
1116
- * @param heading - The `##` heading text to scope to (e.g. `Surface`)
1186
+ * @param heading - The `##` heading text to scope to, for example `Surface`
1117
1187
  * @returns The blocks belonging to that section, in document order
1118
1188
  *
1119
1189
  * @example
1120
1190
  * ```ts
1121
- * sectionBlocks(document, 'Surface') // the blocks between `## Surface` and the next `##`
1191
+ * selectSectionBlocks(document, 'Surface') // the blocks between `## Surface` and the next `##`
1122
1192
  * ```
1123
1193
  */
1124
- function sectionBlocks(document, heading) {
1194
+ function selectSectionBlocks(document, heading) {
1125
1195
  const blocks = [];
1126
1196
  let active = false;
1127
1197
  for (const block of document.children) {
@@ -1137,10 +1207,10 @@ function sectionBlocks(document, heading) {
1137
1207
  return blocks;
1138
1208
  }
1139
1209
  /**
1140
- * Every `## Surface` identifier the guide documents — each table row's column 0
1210
+ * Extracts every `## Surface` identifier the guide documents — each table row's column 0
1141
1211
  * code span (the name) paired with its `Kind` column (located by header text)
1142
- * UNION every backticked H3 entity heading in the section
1143
- * (`{name: <codeSpan>, kind: 'class'}`), deduped by {@link symbolKey}. A row with
1212
+ * unioned with every backticked H3 entity heading in the section
1213
+ * (`{name: <codeSpan>, keyword: 'class'}`), deduped by {@link computeSymbolKey}. A row with
1144
1214
  * no code-span name, or an unrecognized `Kind` text, is skipped.
1145
1215
  *
1146
1216
  * @param document - The parsed guide document
@@ -1148,31 +1218,31 @@ function sectionBlocks(document, heading) {
1148
1218
  *
1149
1219
  * @example
1150
1220
  * ```ts
1151
- * extractSurface(document) // [{ name: 'Markdown', kind: 'class' }, ...]
1221
+ * extractSurface(document) // [{ name: 'Markdown', keyword: 'class' }, ...]
1152
1222
  * ```
1153
1223
  */
1154
1224
  function extractSurface(document) {
1155
1225
  const symbols = [];
1156
1226
  const seen = /* @__PURE__ */ new Set();
1157
- for (const block of sectionBlocks(document, SURFACE)) {
1227
+ for (const block of selectSectionBlocks(document, SURFACE)) {
1158
1228
  if (isTableNode(block)) {
1159
- const column = kindIndex(block);
1229
+ const column = findKindIndex(block);
1160
1230
  for (const row of block.rows) {
1161
1231
  const nameCell = row[0];
1162
- const rawName = nameCell === void 0 ? void 0 : firstCode(nameCell);
1163
- const name = rawName === void 0 ? void 0 : identifierOf(rawName);
1232
+ const rawName = nameCell === void 0 ? void 0 : findFirstCode(nameCell);
1233
+ const name = rawName === void 0 ? void 0 : normalizeIdentifier(rawName);
1164
1234
  if (name === void 0) continue;
1165
1235
  const kindCell = column === void 0 ? void 0 : row[column];
1166
1236
  const kindText = kindCell === void 0 ? "" : flattenText({
1167
1237
  element: "paragraph",
1168
1238
  children: kindCell
1169
1239
  }).trim();
1170
- if (!isExportKind(kindText)) continue;
1240
+ if (!isExportKeyword(kindText)) continue;
1171
1241
  const symbol = {
1172
1242
  name,
1173
- kind: kindText
1243
+ keyword: kindText
1174
1244
  };
1175
- const key = symbolKey(symbol);
1245
+ const key = computeSymbolKey(symbol);
1176
1246
  if (seen.has(key)) continue;
1177
1247
  seen.add(key);
1178
1248
  symbols.push(symbol);
@@ -1180,14 +1250,14 @@ function extractSurface(document) {
1180
1250
  continue;
1181
1251
  }
1182
1252
  if (isHeadingNode(block) && block.level === 3) {
1183
- const rawName = firstCode(block.children);
1184
- const name = rawName === void 0 ? void 0 : identifierOf(rawName);
1253
+ const rawName = findFirstCode(block.children);
1254
+ const name = rawName === void 0 ? void 0 : normalizeIdentifier(rawName);
1185
1255
  if (name === void 0) continue;
1186
1256
  const symbol = {
1187
1257
  name,
1188
- kind: "class"
1258
+ keyword: "class"
1189
1259
  };
1190
- const key = symbolKey(symbol);
1260
+ const key = computeSymbolKey(symbol);
1191
1261
  if (seen.has(key)) continue;
1192
1262
  seen.add(key);
1193
1263
  symbols.push(symbol);
@@ -1196,7 +1266,7 @@ function extractSurface(document) {
1196
1266
  return symbols;
1197
1267
  }
1198
1268
  /**
1199
- * One {@link MethodGroup} per documented behavioral interface in `## Methods` —
1269
+ * Extracts one {@link MethodGroup} per documented behavioral interface in `## Methods` —
1200
1270
  * an H4 with a code span sets the current interface, and the table immediately
1201
1271
  * following becomes its documented methods.
1202
1272
  *
@@ -1211,18 +1281,18 @@ function extractSurface(document) {
1211
1281
  function extractMethods(document) {
1212
1282
  const groups = [];
1213
1283
  let current;
1214
- for (const block of sectionBlocks(document, METHODS)) {
1284
+ for (const block of selectSectionBlocks(document, METHODS)) {
1215
1285
  if (isHeadingNode(block) && block.level === 4) {
1216
- const rawInterface = firstCode(block.children);
1217
- current = rawInterface === void 0 ? void 0 : identifierOf(rawInterface);
1286
+ const rawInterface = findFirstCode(block.children);
1287
+ current = rawInterface === void 0 ? void 0 : normalizeIdentifier(rawInterface);
1218
1288
  continue;
1219
1289
  }
1220
1290
  if (isTableNode(block) && current !== void 0) {
1221
1291
  const methods = [];
1222
1292
  for (const row of block.rows) {
1223
1293
  const cell = row[0];
1224
- const rawName = cell === void 0 ? void 0 : firstCode(cell);
1225
- const name = rawName === void 0 ? void 0 : identifierOf(rawName);
1294
+ const rawName = cell === void 0 ? void 0 : findFirstCode(cell);
1295
+ const name = rawName === void 0 ? void 0 : normalizeIdentifier(rawName);
1226
1296
  if (name !== void 0) methods.push(name);
1227
1297
  }
1228
1298
  groups.push({
@@ -1235,7 +1305,7 @@ function extractMethods(document) {
1235
1305
  return groups;
1236
1306
  }
1237
1307
  /**
1238
- * Every link href in the guide document, including table cells — a full,
1308
+ * Extracts every link href in the guide document, including table cells — a full,
1239
1309
  * depth-first walk of the whole AST.
1240
1310
  *
1241
1311
  * @param document - The parsed guide document
@@ -1252,7 +1322,7 @@ function extractLinks(document) {
1252
1322
  return links;
1253
1323
  }
1254
1324
  /**
1255
- * The relative test links declared under `## Tests` — every link href found
1325
+ * Extracts the relative test links declared under `## Tests` — every link href found
1256
1326
  * within that section only.
1257
1327
  *
1258
1328
  * @param document - The parsed guide document
@@ -1265,11 +1335,11 @@ function extractLinks(document) {
1265
1335
  */
1266
1336
  function extractTests(document) {
1267
1337
  const links = [];
1268
- for (const block of sectionBlocks(document, TESTS)) for (const node of walkNodes(block)) if (isLinkNode(node)) links.push(node.href);
1338
+ for (const block of selectSectionBlocks(document, TESTS)) for (const node of walkNodes(block)) if (isLinkNode(node)) links.push(node.href);
1269
1339
  return links;
1270
1340
  }
1271
1341
  /**
1272
- * Select the next physical record after an eligible genuine JSDoc whose final
1342
+ * Selects the next physical record after an eligible genuine JSDoc whose final
1273
1343
  * authoritative span carries an exact block-position `@example` tag. Title
1274
1344
  * text is allowed. A leading whitespace-separated span chain is last-span
1275
1345
  * authoritative; intervening source material severs association, while a
@@ -1350,7 +1420,7 @@ function extractExampleLines(lines) {
1350
1420
  return examples;
1351
1421
  }
1352
1422
  /**
1353
- * The exported functions in one file's source text whose immediately preceding
1423
+ * Extracts the exported functions in one file's source text whose immediately preceding
1354
1424
  * eligible genuine JSDoc block carries `@example`. Shared adjacency comes from
1355
1425
  * {@link extractExampleLines}; exported-function membership is matched against
1356
1426
  * the aligned code projection, so comment and template payload cannot qualify.
@@ -1361,11 +1431,11 @@ function extractExampleLines(lines) {
1361
1431
  * @example
1362
1432
  * ```ts
1363
1433
  * const block = ['/**', ' * @example', ' *' + '/', 'export function walk() {}', ''].join('\n')
1364
- * examplesFrom(block) // ['walk']
1365
- * examplesFrom('export function walk() {}\n') // []
1434
+ * extractExamples(block) // ['walk']
1435
+ * extractExamples('export function walk() {}\n') // []
1366
1436
  * ```
1367
1437
  */
1368
- function examplesFrom(source) {
1438
+ function extractExamples(source) {
1369
1439
  const names = [];
1370
1440
  const seen = /* @__PURE__ */ new Set();
1371
1441
  for (const line of extractExampleLines(extractSourceLines(source))) {
@@ -1378,7 +1448,7 @@ function examplesFrom(source) {
1378
1448
  return names;
1379
1449
  }
1380
1450
  /**
1381
- * The callable-member names in a declaration body (per {@link memberMethods}'
1451
+ * Extracts the callable-member names in a declaration body (per {@link extractMemberMethods}'
1382
1452
  * grammar) whose immediately preceding eligible genuine JSDoc block, within
1383
1453
  * the same body, carries `@example`. Shared adjacency comes from
1384
1454
  * {@link extractExampleLines}; member membership is matched against aligned
@@ -1389,14 +1459,14 @@ function examplesFrom(source) {
1389
1459
  *
1390
1460
  * @example
1391
1461
  * ```ts
1392
- * exampleMethods(['\t/**', '\t * @example', '\t *' + '/', '\twalk(): void']) // ['walk']
1462
+ * extractExampleMethods(['\t/**', '\t * @example', '\t *' + '/', '\twalk(): void']) // ['walk']
1393
1463
  * ```
1394
1464
  */
1395
- function exampleMethods(lines) {
1465
+ function extractExampleMethods(lines) {
1396
1466
  const methods = [];
1397
1467
  const seen = /* @__PURE__ */ new Set();
1398
1468
  for (const line of extractExampleLines(extractSourceLines(lines.join("\n")))) {
1399
- const name = line.code.match(/^\t(?:async )?\*?(\w+)(<.*>)?\??\(/)?.[1];
1469
+ const name = line.code.match(/^\t(?:async )?\*?(\w+)\??(<.*>)?\(/)?.[1];
1400
1470
  if (isNonEmptyString(name) && !seen.has(name)) {
1401
1471
  seen.add(name);
1402
1472
  methods.push(name);
@@ -1405,7 +1475,7 @@ function exampleMethods(lines) {
1405
1475
  return Array.from(new Set(methods)).sort();
1406
1476
  }
1407
1477
  /**
1408
- * Every fenced code block anywhere in the guide document. A full AST walk
1478
+ * Extracts every fenced code block anywhere in the guide document. A full AST walk
1409
1479
  * includes fences nested inside blockquotes and lists.
1410
1480
  *
1411
1481
  * @param document - The parsed guide document
@@ -1427,7 +1497,7 @@ function extractFences(document) {
1427
1497
  //#endregion
1428
1498
  //#region src/core/parsers.ts
1429
1499
  /**
1430
- * Parse a `## By concept` manifest table into its {@link ManifestEntry} rows —
1500
+ * Parses a `## By concept` manifest table into its {@link ManifestEntry} rows —
1431
1501
  * each row's Concept cell (flattened text), Spec / Tests cells (a single link
1432
1502
  * href, resolved against `directory`), and Source cell (every link href,
1433
1503
  * resolved against `directory`; Source links canonicalize through
@@ -1435,7 +1505,7 @@ function extractFences(document) {
1435
1505
  * a `readonly string[]`). A row missing a concept, spec link, tests link, or
1436
1506
  * source link is skipped as malformed.
1437
1507
  *
1438
- * @param markdown - The manifest markdown source (e.g. `guides/README.md`'s content)
1508
+ * @param markdown - The manifest markdown source, for example the content of `guides/README.md`
1439
1509
  * @param directory - The root-relative directory containing the manifest
1440
1510
  * @returns The manifest's entries, in row order
1441
1511
  *
@@ -1447,7 +1517,7 @@ function extractFences(document) {
1447
1517
  function parseManifest(markdown, directory) {
1448
1518
  const document = createMarkdown(markdown).document;
1449
1519
  const entries = [];
1450
- for (const block of sectionBlocks(document, MANIFEST)) {
1520
+ for (const block of selectSectionBlocks(document, MANIFEST)) {
1451
1521
  if (!isTableNode(block)) continue;
1452
1522
  for (const row of block.rows) {
1453
1523
  const conceptCell = row[0];
@@ -1460,10 +1530,10 @@ function parseManifest(markdown, directory) {
1460
1530
  children: conceptCell
1461
1531
  }).trim();
1462
1532
  if (isEmptyString(concept)) continue;
1463
- const specHref = cellLinks(specCell)[0];
1464
- const testsHref = cellLinks(testsCell)[0];
1533
+ const specHref = extractCellLinks(specCell)[0];
1534
+ const testsHref = extractCellLinks(testsCell)[0];
1465
1535
  if (specHref === void 0 || testsHref === void 0) continue;
1466
- const sourceHrefs = normalizeDirectories(cellLinks(sourceCell).map((href) => resolvePath(directory, href)));
1536
+ const sourceHrefs = normalizeDirectories(extractCellLinks(sourceCell).map((href) => resolvePath(directory, href)));
1467
1537
  if (!isNonEmptyArray(sourceHrefs)) continue;
1468
1538
  const [firstSource] = sourceHrefs;
1469
1539
  const source = sourceHrefs.length === 1 ? firstSource : sourceHrefs;
@@ -1480,8 +1550,8 @@ function parseManifest(markdown, directory) {
1480
1550
  //#endregion
1481
1551
  //#region src/core/shapers.ts
1482
1552
  /**
1483
- * The shape of a {@link SurfaceSymbol} — a documented / exported symbol's
1484
- * `name` paired with its {@link ExportKind}.
1553
+ * Shapes a {@link SurfaceSymbol} — a documented / exported symbol's `name`
1554
+ * paired with its {@link ExportKeyword}.
1485
1555
  *
1486
1556
  * @example
1487
1557
  * ```ts
@@ -1489,22 +1559,16 @@ function parseManifest(markdown, directory) {
1489
1559
  * import { surfaceSymbolShape } from '@orkestrel/guide'
1490
1560
  *
1491
1561
  * const surfaceSymbol = createContract(surfaceSymbolShape)
1492
- * surfaceSymbol.is({ name: 'Markdown', kind: 'class' }) // true
1562
+ * surfaceSymbol.is({ name: 'Markdown', keyword: 'class' }) // true
1493
1563
  * ```
1494
1564
  */
1495
1565
  var surfaceSymbolShape = objectShape({
1496
1566
  name: stringShape(),
1497
- kind: literalShape([
1498
- "type",
1499
- "interface",
1500
- "const",
1501
- "function",
1502
- "class"
1503
- ])
1567
+ keyword: literalShape(EXPORT_KEYWORDS)
1504
1568
  });
1505
1569
  /**
1506
- * The shape of a {@link MethodGroup} — a backticked `interface` name paired
1507
- * with its documented `methods`.
1570
+ * Shapes a {@link MethodGroup} — a backticked `interface` name paired with
1571
+ * its documented `methods`.
1508
1572
  *
1509
1573
  * @example
1510
1574
  * ```ts
@@ -1520,8 +1584,8 @@ var methodGroupShape = objectShape({
1520
1584
  methods: arrayShape(stringShape())
1521
1585
  });
1522
1586
  /**
1523
- * The shape of a {@link ManifestEntry} — one `## By concept` manifest row,
1524
- * `source` accepting either a single directory or several.
1587
+ * Shapes a {@link ManifestEntry} — one `## By concept` manifest row, `source`
1588
+ * accepting either a single directory or several.
1525
1589
  *
1526
1590
  * @example
1527
1591
  * ```ts
@@ -1541,22 +1605,22 @@ var manifestEntryShape = objectShape({
1541
1605
  //#endregion
1542
1606
  //#region src/core/Guide.ts
1543
1607
  /**
1544
- * A stateful, structured view over one parsed guide — the six documented
1608
+ * Presents a pure, structured view over one parsed guide — the documented
1545
1609
  * projections (`sections` / `surface` / `methods` / `links` / `tests` /
1546
1610
  * `fences`) are extracted once at construction and cached.
1547
1611
  *
1548
1612
  * @remarks
1549
- * Pure: parses `source` once via `@orkestrel/markdown` and never touches the
1550
- * filesystem — `Guide` has no notion of "where" the guide came from, only its
1551
- * markdown text. Every accessor returns the same cached, readonly array on
1552
- * every call.
1613
+ * Parses `source` once through `@orkestrel/markdown` and never touches the
1614
+ * filesystem — `Guide` reads only the markdown text it is given and records
1615
+ * nothing about where the guide came from. Every accessor returns the same
1616
+ * cached, readonly array on every call.
1553
1617
  *
1554
1618
  * @example
1555
1619
  * ```ts
1556
1620
  * import { Guide } from '@orkestrel/guide'
1557
1621
  *
1558
1622
  * const guide = new Guide('## Surface\n\n| Name | Kind |\n| --- | --- |\n| `X` | class |')
1559
- * guide.surface() // [{ name: 'X', kind: 'class' }]
1623
+ * guide.surface() // [{ name: 'X', keyword: 'class' }]
1560
1624
  * ```
1561
1625
  */
1562
1626
  var Guide = class {
@@ -1597,10 +1661,10 @@ var Guide = class {
1597
1661
  //#endregion
1598
1662
  //#region src/core/sources/Source.ts
1599
1663
  /**
1600
- * A pure `SourceInterface` — reflects a module scope's intentional direct
1601
- * declarations, conventional barrel-reachable surface, and member methods over
1602
- * a consumer-supplied file inventory, using text-only line scanners rather than
1603
- * the TypeScript compiler API or the filesystem. `Source` never touches disk:
1664
+ * Reflects, as a pure `SourceInterface`, a module scope's intentional direct declarations,
1665
+ * conventional barrel-reachable surface, and member methods over a consumer-supplied file
1666
+ * inventory, using text-only line scanners rather than the TypeScript compiler API or the
1667
+ * filesystem. `Source` never touches disk:
1604
1668
  * the consumer gathers the inventory however their environment allows
1605
1669
  * (`node:fs` in a Node script, `import.meta.glob` in a browser/vitest run) and
1606
1670
  * passes it in as `files`. Conventional barrel traversal recurses through both
@@ -1609,7 +1673,12 @@ var Guide = class {
1609
1673
  * construction, and exact opaque inventory keys are never rewritten; keys with
1610
1674
  * empty, `.` or `..` segments stay outside both initial and resolved barrel
1611
1675
  * inventory entrances after relative-row reduction; canonical parent hops
1612
- * remain valid. Source projection preserves columns without widening
1676
+ * remain valid. `methods` resolves a declaration's members through its
1677
+ * `extends` chain within the same module scope, keeping the keyword it started
1678
+ * from; a base the scope does not declare contributes nothing. One declaration
1679
+ * answers for a name: the first file in sorted key order that declares the head
1680
+ * supplies its members and its bases, and a second file declaring the same name
1681
+ * adds nothing. Source projection preserves columns without widening
1613
1682
  * direct/hidden column-zero heads. Literal ECMAScript Unicode identifiers
1614
1683
  * participate in bounded slash-state recognition without escape decoding.
1615
1684
  * Regex recognition is bounded: slash after bare `}` is division, so a
@@ -1629,8 +1698,8 @@ var Guide = class {
1629
1698
  * },
1630
1699
  * module: 'src/core',
1631
1700
  * })
1632
- * source.exports() // [{ name: 'Guide', kind: 'class' }, { name: 'GuideInterface', kind: 'interface' }]
1633
- * source.surface() // [{ name: 'Guide', kind: 'class' }, { name: 'GuideInterface', kind: 'interface' }]
1701
+ * source.exports() // [{ name: 'Guide', keyword: 'class' }, { name: 'GuideInterface', keyword: 'interface' }]
1702
+ * source.surface() // [{ name: 'Guide', keyword: 'class' }, { name: 'GuideInterface', keyword: 'interface' }]
1634
1703
  * source.methods('GuideInterface') // ['sections']
1635
1704
  * source.exists('src/core/Guide.ts') // true
1636
1705
  * ```
@@ -1647,7 +1716,7 @@ var Source = class {
1647
1716
  this.#directories = normalizeDirectories(options.module);
1648
1717
  }
1649
1718
  exports() {
1650
- if (this.#exports === void 0) this.#exports = this.#scanSymbols(exportsFrom);
1719
+ if (this.#exports === void 0) this.#exports = this.#scanSymbols(extractExports);
1651
1720
  return this.#exports;
1652
1721
  }
1653
1722
  surface() {
@@ -1655,15 +1724,16 @@ var Source = class {
1655
1724
  return this.#surface;
1656
1725
  }
1657
1726
  methods(name) {
1658
- const interfaceBody = this.#declarationBody("interface", name);
1659
- if (interfaceBody.length > 0) return memberMethods(interfaceBody);
1660
- return memberMethods(this.#declarationBody("class", name)).filter((method) => method !== "constructor");
1727
+ const declared = this.#members("interface", name, /* @__PURE__ */ new Set());
1728
+ if (declared !== void 0) return declared;
1729
+ const inherited = this.#members("class", name, /* @__PURE__ */ new Set());
1730
+ return inherited === void 0 ? [] : inherited.filter((method) => method !== "constructor");
1661
1731
  }
1662
1732
  exists(relative) {
1663
1733
  return Object.keys(this.#files).some((key) => key === relative || key.startsWith(`${relative}/`));
1664
1734
  }
1665
1735
  hidden() {
1666
- if (this.#hidden === void 0) this.#hidden = this.#scanSymbols(hiddenFrom);
1736
+ if (this.#hidden === void 0) this.#hidden = this.#scanSymbols(extractHidden);
1667
1737
  return this.#hidden;
1668
1738
  }
1669
1739
  examples(name) {
@@ -1679,7 +1749,7 @@ var Source = class {
1679
1749
  for (const key of selectModuleKeys(this.#files, this.#directories)) {
1680
1750
  const text = this.#files[key];
1681
1751
  if (text === void 0) continue;
1682
- for (const name of examplesFrom(text)) {
1752
+ for (const name of extractExamples(text)) {
1683
1753
  if (seen.has(name)) continue;
1684
1754
  seen.add(name);
1685
1755
  names.push(name);
@@ -1714,8 +1784,8 @@ var Source = class {
1714
1784
  visited.add(path);
1715
1785
  const text = this.#files[path];
1716
1786
  if (text === void 0) continue;
1717
- for (const symbol of exportsFrom(text)) {
1718
- const identity = symbolKey(symbol);
1787
+ for (const symbol of extractExports(text)) {
1788
+ const identity = computeSymbolKey(symbol);
1719
1789
  if (seen.has(identity)) continue;
1720
1790
  seen.add(identity);
1721
1791
  symbols.push(symbol);
@@ -1723,9 +1793,7 @@ var Source = class {
1723
1793
  }
1724
1794
  }
1725
1795
  #exampleMembers(name) {
1726
- const interfaceBody = this.#declarationBody("interface", name);
1727
- const classBody = this.#declarationBody("class", name);
1728
- const members = /* @__PURE__ */ new Set([...exampleMethods(interfaceBody), ...exampleMethods(classBody)]);
1796
+ const members = /* @__PURE__ */ new Set([...extractExampleMethods(this.#locate("interface", name)?.body ?? []), ...extractExampleMethods(this.#locate("class", name)?.body ?? [])]);
1729
1797
  return Array.from(members).sort();
1730
1798
  }
1731
1799
  #scanSymbols(scan) {
@@ -1735,7 +1803,7 @@ var Source = class {
1735
1803
  const text = this.#files[key];
1736
1804
  if (text === void 0) continue;
1737
1805
  for (const symbol of scan(text)) {
1738
- const identity = symbolKey(symbol);
1806
+ const identity = computeSymbolKey(symbol);
1739
1807
  if (seen.has(identity)) continue;
1740
1808
  seen.add(identity);
1741
1809
  symbols.push(symbol);
@@ -1743,14 +1811,24 @@ var Source = class {
1743
1811
  }
1744
1812
  return symbols.sort((a, b) => a.name === b.name ? 0 : a.name < b.name ? -1 : 1);
1745
1813
  }
1746
- #declarationBody(keyword, name) {
1814
+ #members(keyword, name, visited) {
1815
+ if (visited.has(name)) return [];
1816
+ visited.add(name);
1817
+ const declaration = this.#locate(keyword, name);
1818
+ if (declaration === void 0) return void 0;
1819
+ const methods = new Set(extractMemberMethods(declaration.body));
1820
+ for (const base of declaration.bases) for (const member of this.#members(keyword, base, visited) ?? []) methods.add(member);
1821
+ return Array.from(methods).sort();
1822
+ }
1823
+ #locate(keyword, name) {
1747
1824
  for (const key of selectModuleKeys(this.#files, this.#directories)) {
1748
1825
  const text = this.#files[key];
1749
1826
  if (text === void 0) continue;
1750
- const body = declarationBody(text, keyword, name);
1751
- if (body.length > 0) return body;
1827
+ const declaration = extractDeclaration(text, keyword, name);
1828
+ if (declaration === void 0) continue;
1829
+ if (declaration.body.length === 0 && declaration.bases.length === 0) continue;
1830
+ return declaration;
1752
1831
  }
1753
- return [];
1754
1832
  }
1755
1833
  };
1756
1834
  //#endregion
@@ -1759,6 +1837,8 @@ var Source = class {
1759
1837
  * Resolves a consumer-owned import-specifier policy into pure source views and
1760
1838
  * caches those views by module, so aliases for one module share one entity.
1761
1839
  * Unmapped specifiers remain foreign to the consumer and return `undefined`.
1840
+ * `sources()` enumerates the same shared views, one per distinct module the
1841
+ * policy maps.
1762
1842
  *
1763
1843
  * @example
1764
1844
  * ```ts
@@ -1769,6 +1849,7 @@ var Source = class {
1769
1849
  * modules: { '@scope/package': 'src/core' },
1770
1850
  * })
1771
1851
  * sources.source('@scope/package')?.surface()
1852
+ * sources.sources() // [the same shared view]
1772
1853
  * ```
1773
1854
  */
1774
1855
  var SourceManager = class {
@@ -1783,7 +1864,7 @@ var SourceManager = class {
1783
1864
  if (!Object.hasOwn(this.#modules, specifier)) return void 0;
1784
1865
  const module = this.#modules[specifier];
1785
1866
  if (module === void 0) return void 0;
1786
- const key = moduleKey(module);
1867
+ const key = computeModuleKey(module);
1787
1868
  const existing = this.#sources.get(key);
1788
1869
  if (existing !== void 0) return existing;
1789
1870
  const source = new Source({
@@ -1793,11 +1874,22 @@ var SourceManager = class {
1793
1874
  this.#sources.set(key, source);
1794
1875
  return source;
1795
1876
  }
1877
+ sources() {
1878
+ const views = [];
1879
+ const seen = /* @__PURE__ */ new Set();
1880
+ for (const specifier of Object.keys(this.#modules)) {
1881
+ const view = this.source(specifier);
1882
+ if (view === void 0 || seen.has(view)) continue;
1883
+ seen.add(view);
1884
+ views.push(view);
1885
+ }
1886
+ return views;
1887
+ }
1796
1888
  };
1797
1889
  //#endregion
1798
1890
  //#region src/core/factories.ts
1799
1891
  /**
1800
- * Create a structured {@link GuideInterface} view over one guide's markdown
1892
+ * Creates a structured {@link GuideInterface} view over one guide's markdown
1801
1893
  * source — parses once and caches its `sections` / `surface` / `methods` /
1802
1894
  * `links` / `tests` / `fences` projections.
1803
1895
  *
@@ -1809,14 +1901,14 @@ var SourceManager = class {
1809
1901
  * import { createGuide } from '@orkestrel/guide'
1810
1902
  *
1811
1903
  * const guide = createGuide('## Surface\n\n| Name | Kind |\n| --- | --- |\n| `X` | class |')
1812
- * guide.surface() // [{ name: 'X', kind: 'class' }]
1904
+ * guide.surface() // [{ name: 'X', keyword: 'class' }]
1813
1905
  * ```
1814
1906
  */
1815
1907
  function createGuide(source) {
1816
1908
  return new Guide(source);
1817
1909
  }
1818
1910
  /**
1819
- * Create a pure {@link SourceInterface} over a consumer-supplied file
1911
+ * Creates a pure {@link SourceInterface} over a consumer-supplied file
1820
1912
  * inventory — see {@link Source}.
1821
1913
  *
1822
1914
  * @param options - The file inventory and module scope to reflect
@@ -1830,14 +1922,14 @@ function createGuide(source) {
1830
1922
  * files: { 'src/core/Guide.ts': 'export class Guide {}\n' },
1831
1923
  * module: 'src/core',
1832
1924
  * })
1833
- * source.exports() // [{ name: 'Guide', kind: 'class' }]
1925
+ * source.exports() // [{ name: 'Guide', keyword: 'class' }]
1834
1926
  * ```
1835
1927
  */
1836
1928
  function createSource(options) {
1837
1929
  return new Source(options);
1838
1930
  }
1839
1931
  /**
1840
- * Create a {@link SourceManagerInterface} that resolves the consumer's local
1932
+ * Creates a {@link SourceManagerInterface} that resolves the consumer's local
1841
1933
  * import specifiers and shares one source view per module.
1842
1934
  *
1843
1935
  * @param options - The shared file inventory and specifier-to-module policy
@@ -1858,9 +1950,9 @@ function createSourceManager(options) {
1858
1950
  return new SourceManager(options);
1859
1951
  }
1860
1952
  /**
1861
- * Compile the {@link surfaceSymbolShape} into a {@link ContractInterface} for
1953
+ * Compiles the {@link surfaceSymbolShape} into a {@link ContractInterface} for
1862
1954
  * {@link SurfaceSymbol} — a guard, coercing parser, JSON Schema, and seeded
1863
- * generator from one shape declaration (AGENTS §14).
1955
+ * generator from one shape declaration (AGENTS.md § Design laws).
1864
1956
  *
1865
1957
  * @returns A `SurfaceSymbol` contract bundling `schema` / `is` / `parse` / `generate`
1866
1958
  *
@@ -1869,16 +1961,16 @@ function createSourceManager(options) {
1869
1961
  * import { createSurfaceSymbolContract } from '@orkestrel/guide'
1870
1962
  *
1871
1963
  * const surfaceSymbol = createSurfaceSymbolContract()
1872
- * surfaceSymbol.is({ name: 'Markdown', kind: 'class' }) // true
1964
+ * surfaceSymbol.is({ name: 'Markdown', keyword: 'class' }) // true
1873
1965
  * ```
1874
1966
  */
1875
1967
  function createSurfaceSymbolContract() {
1876
1968
  return createContract(surfaceSymbolShape);
1877
1969
  }
1878
1970
  /**
1879
- * Compile the {@link methodGroupShape} into a {@link ContractInterface} for
1971
+ * Compiles the {@link methodGroupShape} into a {@link ContractInterface} for
1880
1972
  * {@link MethodGroup} — a guard, coercing parser, JSON Schema, and seeded
1881
- * generator from one shape declaration (AGENTS §14).
1973
+ * generator from one shape declaration (AGENTS.md § Design laws).
1882
1974
  *
1883
1975
  * @returns A `MethodGroup` contract bundling `schema` / `is` / `parse` / `generate`
1884
1976
  *
@@ -1894,9 +1986,9 @@ function createMethodGroupContract() {
1894
1986
  return createContract(methodGroupShape);
1895
1987
  }
1896
1988
  /**
1897
- * Compile the {@link manifestEntryShape} into a {@link ContractInterface} for
1989
+ * Compiles the {@link manifestEntryShape} into a {@link ContractInterface} for
1898
1990
  * {@link ManifestEntry} — a guard, coercing parser, JSON Schema, and seeded
1899
- * generator from one shape declaration (AGENTS §14).
1991
+ * generator from one shape declaration (AGENTS.md § Design laws).
1900
1992
  *
1901
1993
  * @returns A `ManifestEntry` contract bundling `schema` / `is` / `parse` / `generate`
1902
1994
  *
@@ -1912,6 +2004,6 @@ function createManifestEntryContract() {
1912
2004
  return createContract(manifestEntryShape);
1913
2005
  }
1914
2006
  //#endregion
1915
- export { EXTERNAL_SCHEMES, Guide, MANIFEST, METHODS, SURFACE, Source, SourceManager, TESTS, cellLinks, createGuide, createManifestEntryContract, createMethodGroupContract, createSource, createSourceManager, createSurfaceSymbolContract, declarationBody, exampleMethods, examplesFrom, exportsFrom, extractExampleLines, extractFences, extractLinks, extractMethods, extractSourceLines, extractSurface, extractTests, fenceImports, findMissing, findUnexampled, findUnlisted, firstCode, hasCanonicalSegments, hiddenFrom, identifierOf, isExportKind, isExternalLink, isManifestEntry, isMethodGroup, isSurfaceSymbol, joinHead, kindIndex, manifestEntryShape, memberMethods, methodGroupShape, missingSymbols, moduleKey, normalizeDirectories, parseManifest, resolveLink, resolvePath, sectionBlocks, selectModuleKeys, surfaceSymbolShape, symbolKey };
2007
+ export { EXPORT_KEYWORDS, EXTERNAL_SCHEMES, Guide, MANIFEST, METHODS, SURFACE, Source, SourceManager, TESTS, computeModuleKey, computeSymbolKey, createGuide, createManifestEntryContract, createMethodGroupContract, createSource, createSourceManager, createSurfaceSymbolContract, escapeRegExp, extractCellLinks, extractDeclaration, extractExampleLines, extractExampleMethods, extractExamples, extractExports, extractFenceImports, extractFences, extractHidden, extractLinks, extractMemberMethods, extractMethods, extractSourceLines, extractSurface, extractTests, findFirstCode, findKindIndex, findMissing, findMissingSymbols, findUnexampled, findUnlisted, hasCanonicalSegments, isExportKeyword, isExternalLink, isManifestEntry, isMethodGroup, isSurfaceSymbol, joinHead, manifestEntryShape, methodGroupShape, normalizeDirectories, normalizeIdentifier, parseManifest, resolveLink, resolvePath, selectModuleKeys, selectSectionBlocks, surfaceSymbolShape };
1916
2008
 
1917
2009
  //# sourceMappingURL=index.js.map