@orkestrel/guide 0.0.26 → 0.0.28

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.
@@ -1,5 +1,5 @@
1
+ import { INTRINSICS, arrayOf, arrayShape, createContract, holds, isBoundedJSONRecord, isEmptyString, isNonEmptyArray, isNonEmptyString, isString, literalOf, literalShape, objectShape, optionalShape, recordOf, stringShape, unionOf, unionShape } from "@orkestrel/contract";
1
2
  import { coalesceText, createMarkdown, flattenText, isBlockquoteNode, isCodeBlockNode, isCodeSpanNode, isEmphasisNode, isHeadingNode, isImageNode, isLinkNode, isParagraphNode, isTableNode, renderMarkdown, walkNodes } from "@orkestrel/markdown";
2
- import { arrayOf, arrayShape, createContract, isEmptyString, isNonEmptyArray, isNonEmptyString, isString, literalOf, literalShape, objectShape, optionalShape, recordOf, stringShape, unionOf, unionShape } from "@orkestrel/contract";
3
3
  // src/core/constants.ts
4
4
  /**
5
5
  * Lists the declaration keywords a documented or exported symbol carries, in the order the
@@ -21,12 +21,32 @@ var EXPORT_KEYWORDS = Object.freeze([
21
21
  /**
22
22
  * Lists the compared sites a {@link Drift} can describe.
23
23
  */
24
- var DRIFT_CATEGORIES = Object.freeze(["summary", "example"]);
24
+ var DRIFT_CATEGORIES = Object.freeze([
25
+ "summary",
26
+ "signature",
27
+ "example"
28
+ ]);
25
29
  /**
26
30
  * Names the `## Surface` heading text a guide's documented exports section is keyed on.
27
31
  */
28
32
  var SURFACE = "Surface";
29
33
  /**
34
+ * Lists the codes a {@link GuideError} carries: a refused Surface `header` or empty `signature`
35
+ * cell, a name two modules of one manifest entry declare (`collision`), and the compiler faults —
36
+ * a failed `compile`, an `empty` emit, a `timeout`, and an output `overflow`.
37
+ */
38
+ var GUIDE_CODES = Object.freeze([
39
+ "header",
40
+ "signature",
41
+ "collision",
42
+ "compile",
43
+ "empty",
44
+ "timeout",
45
+ "overflow"
46
+ ]);
47
+ /** Names the cross-copy identity marker of a Guide error. */
48
+ var GUIDE_ERROR_BRAND = Symbol.for("@orkestrel/guide.GuideError");
49
+ /**
30
50
  * Names the `## Methods` heading text a guide's documented interface-methods section is keyed on.
31
51
  */
32
52
  var METHODS = "Methods";
@@ -39,11 +59,28 @@ var TESTS = "Tests";
39
59
  */
40
60
  var KIND = "Kind";
41
61
  /**
62
+ * Names the header text of the column a `## Surface` table's TypeScript signature is read from.
63
+ */
64
+ var SIGNATURE = "Signature";
65
+ /**
42
66
  * Names the header text of the column a `## Surface` or `## Methods` table's compared
43
67
  * description paragraph is read from.
44
68
  */
45
69
  var SUMMARY = "Summary";
46
70
  /**
71
+ * Names the header text of a `## Surface` or `## Methods` table's first column, the symbol name.
72
+ */
73
+ var NAME = "Name";
74
+ /**
75
+ * Lists the uniform `## Surface` table header, column by column, that guide construction requires.
76
+ */
77
+ var SURFACE_HEADER = Object.freeze([
78
+ NAME,
79
+ KIND,
80
+ SIGNATURE,
81
+ SUMMARY
82
+ ]);
83
+ /**
47
84
  * Names the `## By concept` heading text the manifest's run-map table is keyed on.
48
85
  */
49
86
  var MANIFEST = "By concept";
@@ -73,6 +110,37 @@ var EXTERNAL_SCHEMES = Object.freeze([
73
110
  "mailto:",
74
111
  "tel:"
75
112
  ]);
113
+ // src/core/errors.ts
114
+ /** Carries a coded refusal of a guide, a manifest entry, or a module compile. */
115
+ var GuideError = class extends Error {
116
+ name = "GuideError";
117
+ code;
118
+ context;
119
+ constructor(message, code, options) {
120
+ super(message, options);
121
+ this.code = code;
122
+ this.context = options?.context;
123
+ INTRINSICS.define(this, GUIDE_ERROR_BRAND, { value: this });
124
+ }
125
+ };
126
+ /**
127
+ * Checks whether a value carries the Guide error brand and declared members across package copies.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * isGuideError(new GuideError('Invalid Surface header', 'header')) // true
132
+ * ```
133
+ */
134
+ function isGuideError(value) {
135
+ return holds(() => {
136
+ if (!(value instanceof INTRINSICS.error)) return false;
137
+ if (INTRINSICS.prototype(value) === INTRINSICS.error.prototype) return false;
138
+ if (INTRINSICS.describe(value, GUIDE_ERROR_BRAND)?.value !== value) return false;
139
+ const code = INTRINSICS.reflect.read(value, "code");
140
+ const context = INTRINSICS.reflect.read(value, "context");
141
+ return GUIDE_CODES.some((candidate) => candidate === code) && (context === void 0 || isBoundedJSONRecord(context)) && typeof INTRINSICS.reflect.read(value, "name") === "string" && typeof INTRINSICS.reflect.read(value, "message") === "string";
142
+ });
143
+ }
76
144
  // src/core/validators.ts
77
145
  /**
78
146
  * Checks whether `value` is one of the documented {@link ExportKeyword}
@@ -93,7 +161,7 @@ var isExportKeyword = literalOf(EXPORT_KEYWORDS);
93
161
  var isDriftCategory = literalOf(DRIFT_CATEGORIES);
94
162
  /**
95
163
  * Checks whether `value` is a well-formed {@link SurfaceSymbol} — a `name`
96
- * string paired with a valid {@link ExportKeyword}, and an optional `summary`.
164
+ * string paired with a valid {@link ExportKeyword}, and optional `signature` and `summary` strings.
97
165
  *
98
166
  * @param value - The value to test
99
167
  * @returns True if `value` is a well-formed {@link SurfaceSymbol}; false otherwise
@@ -107,8 +175,9 @@ var isDriftCategory = literalOf(DRIFT_CATEGORIES);
107
175
  var isSurfaceSymbol = recordOf({
108
176
  name: isString,
109
177
  keyword: isExportKeyword,
178
+ signature: isString,
110
179
  summary: isString
111
- }, ["summary"]);
180
+ }, ["signature", "summary"]);
112
181
  /**
113
182
  * Checks whether `value` is a well-formed {@link MethodEntry} — a `name` string with an
114
183
  * optional `summary`.
@@ -848,7 +917,7 @@ function findUnlisted(fences, languages) {
848
917
  *
849
918
  * @example
850
919
  * ```ts
851
- * findMissingSymbols([{ name: 'X', keyword: 'class' }], []) // ['class X']
920
+ * findMissingSymbols([{ name: 'X', keyword: 'class', signature: '`new () => X`' }], []) // ['class X']
852
921
  * ```
853
922
  */
854
923
  function findMissingSymbols(symbols, source) {
@@ -1242,6 +1311,293 @@ function extractHidden(source) {
1242
1311
  return symbols;
1243
1312
  }
1244
1313
  /**
1314
+ * Computes the bracket depth of every character of projected declaration code: an opening `(`,
1315
+ * `[`, `{`, or `<` and its closing partner carry the depth outside the pair, the characters
1316
+ * between them one more, and every character of a quoted string, its quotes included, `-1`.
1317
+ *
1318
+ * @remarks
1319
+ * The `>` of an `=>` arrow closes nothing. A backslash escapes the next character inside a
1320
+ * quoted string. Template literal text is outside the reading, because
1321
+ * {@link extractSourceLines} masks it to spaces in the code this function reads.
1322
+ *
1323
+ * @param code - The projected code of one declaration
1324
+ * @returns One depth per UTF-16 code unit of `code`
1325
+ *
1326
+ * @example
1327
+ * ```ts
1328
+ * computeDepths("f(a, 'b')") // [0, 0, 1, 1, 1, -1, -1, -1, 0]
1329
+ * ```
1330
+ */
1331
+ function computeDepths(code) {
1332
+ const depths = [];
1333
+ code.split("").reduce((state, character, index) => {
1334
+ if (state.quote !== void 0) {
1335
+ depths.push(-1);
1336
+ if (state.escaped) return {
1337
+ ...state,
1338
+ escaped: false
1339
+ };
1340
+ if (character === "\\") return {
1341
+ ...state,
1342
+ escaped: true
1343
+ };
1344
+ return character === state.quote ? {
1345
+ ...state,
1346
+ quote: void 0
1347
+ } : state;
1348
+ }
1349
+ if (character === "'" || character === "\"") {
1350
+ depths.push(-1);
1351
+ return {
1352
+ ...state,
1353
+ quote: character
1354
+ };
1355
+ }
1356
+ if (")]}".includes(character) || character === ">" && code[index - 1] !== "=") {
1357
+ const depth = Math.max(0, state.depth - 1);
1358
+ depths.push(depth);
1359
+ return {
1360
+ ...state,
1361
+ depth
1362
+ };
1363
+ }
1364
+ depths.push(state.depth);
1365
+ return "([{<".includes(character) ? {
1366
+ ...state,
1367
+ depth: state.depth + 1
1368
+ } : state;
1369
+ }, {
1370
+ depth: 0,
1371
+ quote: void 0,
1372
+ escaped: false
1373
+ });
1374
+ return depths;
1375
+ }
1376
+ /**
1377
+ * Finds the index of the bracket closing the opener at `start`: the first later character whose
1378
+ * {@link computeDepths} depth equals the opener's.
1379
+ *
1380
+ * @param depths - The depths {@link computeDepths} returned for the code
1381
+ * @param start - The index of an opening `(`, `[`, `{`, or `<`
1382
+ * @returns The closing bracket's index, or `undefined` when the opener never closes
1383
+ *
1384
+ * @example
1385
+ * ```ts
1386
+ * findClosing(computeDepths('<T>(x: T)'), 3) // 8
1387
+ * ```
1388
+ */
1389
+ function findClosing(depths, start) {
1390
+ const depth = depths[start];
1391
+ if (depth === void 0 || depth < 0) return void 0;
1392
+ const index = depths.findIndex((value, position) => position > start && value === depth);
1393
+ return index < 0 ? void 0 : index;
1394
+ }
1395
+ /**
1396
+ * Finds every index at which `separator` sits at `depth` outside quoted text, in code order.
1397
+ *
1398
+ * @param code - The projected code to search
1399
+ * @param depths - The depths {@link computeDepths} returned for `code`
1400
+ * @param separator - The single character to find
1401
+ * @param depth - The bracket depth the separator must sit at
1402
+ * @returns The separator indices, in code order
1403
+ *
1404
+ * @example
1405
+ * ```ts
1406
+ * findSeparators('a, f(b, c)', computeDepths('a, f(b, c)'), ',', 0) // [1]
1407
+ * ```
1408
+ */
1409
+ function findSeparators(code, depths, separator, depth) {
1410
+ return depths.keys().filter((index) => depths[index] === depth && code[index] === separator).toArray();
1411
+ }
1412
+ /**
1413
+ * Renders one emitted interface member as its signature entry: a property as its name, an
1414
+ * optional one with `?`, a method as `name()` or `name?()`, an accessor as its name, and a call,
1415
+ * construct, or index signature as its own text with whitespace collapsed.
1416
+ *
1417
+ * @remarks
1418
+ * `code` is the member's projected code and `source` its text at the same columns, both without
1419
+ * the terminating `;`. A leading `readonly` modifier never enters a name. A computed name keeps
1420
+ * its brackets, and a quoted name keeps its quotes.
1421
+ *
1422
+ * @param code - The member's projected code
1423
+ * @param source - The member's source text, aligned with `code`
1424
+ * @returns The member's entry, or `undefined` when the member is empty
1425
+ *
1426
+ * @example
1427
+ * ```ts
1428
+ * renderMember('readonly name?: string', 'readonly name?: string') // 'name?'
1429
+ * renderMember('walk(depth: number): void', 'walk(depth: number): void') // 'walk()'
1430
+ * renderMember('[key: string]: number', '[key: string]: number') // '[key: string]: number'
1431
+ * ```
1432
+ */
1433
+ function renderMember(code, source) {
1434
+ const text = source.replace(/\s+/g, " ").trim();
1435
+ if (text.length === 0) return void 0;
1436
+ const leading = code.length - code.trimStart().length;
1437
+ const modifier = leading + (/^readonly\s+/.exec(code.slice(leading))?.[0].length ?? 0);
1438
+ const rest = code.slice(modifier);
1439
+ if (/^(?:new\s*)?[(<]/.test(rest)) return text;
1440
+ const depths = computeDepths(rest);
1441
+ const bracket = rest.startsWith("[") ? findClosing(depths, 0) : void 0;
1442
+ if (bracket !== void 0 && findSeparators(rest, depths, ":", 1).some((index) => index < bracket)) return text;
1443
+ const accessor = /^(?:get|set)\s+(?=[^\s(:?<])/.exec(rest)?.[0].length ?? 0;
1444
+ const named = rest.slice(accessor);
1445
+ const computed = named.startsWith("[") ? findClosing(computeDepths(named), 0) : void 0;
1446
+ const length = computed === void 0 ? /^(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|[^\s?(:<]+)/.exec(named)?.[0].length ?? 0 : computed + 1;
1447
+ if (length === 0) return text;
1448
+ const offset = modifier + accessor;
1449
+ const tail = named.slice(length);
1450
+ const optional = tail.startsWith("?");
1451
+ const method = accessor === 0 && /^\??\s*[(<]/.test(tail);
1452
+ return `${source.slice(offset, offset + length)}${optional ? "?" : ""}${method ? "()" : ""}`;
1453
+ }
1454
+ /**
1455
+ * Extracts one emitted declaration's signature: the symbol its column-zero `export` head names,
1456
+ * carrying the type text the compiler emitted for it.
1457
+ *
1458
+ * @remarks
1459
+ * `code` is the declaration's projected code and `source` its text at the same columns, each
1460
+ * physical line trimmed and the lines joined with single spaces. The forms:
1461
+ *
1462
+ * - `function`: `<T>(params) => RET` from `NAME<T>(params): RET`.
1463
+ * - `class`: `new <T>(params) => YIELD` per `constructor(params)`, several as an intersection of
1464
+ * parenthesized signatures, none as `new <T>() => YIELD`. `YIELD` is the first `implements`
1465
+ * type, else the class's own name with its type parameter names. Every other member is ignored.
1466
+ * - `interface`: `{ entries }` from {@link renderMember} over its own members, in emitted order,
1467
+ * each entry once, or `{}` when it declares none. The `extends` clause is not read.
1468
+ * - `type`: the text after `=` to the terminating `;`, type parameters omitted.
1469
+ * - `const`: the text after `NAME:` to the `;`, or after `NAME =` for a literal the compiler
1470
+ * emitted as the constant's type.
1471
+ *
1472
+ * @param code - The declaration's projected code
1473
+ * @param source - The declaration's source text, aligned with `code`
1474
+ * @returns The declared symbol with its signature, or `undefined` when no supported head opens it
1475
+ *
1476
+ * @example
1477
+ * ```ts
1478
+ * const text = 'export declare function walk<T>(node: T): void;'
1479
+ * extractSignature(text, text) // { name: 'walk', keyword: 'function', signature: '<T>(node: T) => void' }
1480
+ * ```
1481
+ */
1482
+ function extractSignature(code, source) {
1483
+ const head = /^export (?:declare )?(?:abstract )?(function|class|interface|type|const(?! enum\b)) ([^\s<(:=;{]+)/.exec(code);
1484
+ const keyword = head?.[1];
1485
+ const name = head?.[2];
1486
+ if (head === null || name === void 0 || !isExportKeyword(keyword)) return void 0;
1487
+ const depths = computeDepths(code);
1488
+ const start = head[0].length;
1489
+ const generic = code[start] === "<" ? findClosing(depths, start) : void 0;
1490
+ const typed = generic === void 0 ? start : generic + 1;
1491
+ const generics = source.slice(start, typed);
1492
+ const end = findSeparators(code, depths, ";", 0).find((index) => index >= typed) ?? code.length;
1493
+ if (keyword === "function") {
1494
+ const close = code[typed] === "(" ? findClosing(depths, typed) : void 0;
1495
+ if (close === void 0) return void 0;
1496
+ const colon = /^\s*:/.exec(code.slice(close + 1))?.[0].length;
1497
+ if (colon === void 0) return void 0;
1498
+ const returns = source.slice(close + 1 + colon, end).trim();
1499
+ return {
1500
+ name,
1501
+ keyword,
1502
+ signature: `${generics}(${source.slice(typed + 1, close)}) => ${returns}`
1503
+ };
1504
+ }
1505
+ if (keyword === "const" || keyword === "type") {
1506
+ const assigned = (keyword === "const" ? /^\s*[:=]/ : /^\s*=/).exec(code.slice(typed));
1507
+ if (assigned === null) return void 0;
1508
+ return {
1509
+ name,
1510
+ keyword,
1511
+ signature: source.slice(typed + assigned[0].length, end).trim()
1512
+ };
1513
+ }
1514
+ const open = findSeparators(code, depths, "{", 0).find((index) => index >= typed);
1515
+ const close = open === void 0 ? void 0 : findClosing(depths, open);
1516
+ if (open === void 0 || close === void 0) return void 0;
1517
+ const boundaries = [
1518
+ open,
1519
+ ...findSeparators(code, depths, ";", 1).filter((index) => index > open && index < close),
1520
+ close
1521
+ ];
1522
+ const members = boundaries.slice(0, -1).map((boundary, position) => {
1523
+ const next = boundaries[position + 1] ?? close;
1524
+ return {
1525
+ code: code.slice(boundary + 1, next),
1526
+ source: source.slice(boundary + 1, next)
1527
+ };
1528
+ });
1529
+ if (keyword === "interface") {
1530
+ const entries = Array.from(new Set(members.map((member) => renderMember(member.code, member.source)).filter((entry) => entry !== void 0)));
1531
+ return {
1532
+ name,
1533
+ keyword,
1534
+ signature: entries.length === 0 ? "{}" : `{ ${entries.join(", ")} }`
1535
+ };
1536
+ }
1537
+ const heritage = /\bimplements\b/.exec(code.slice(typed, open));
1538
+ const implemented = heritage === null || depths[typed + heritage.index] !== 0 ? void 0 : typed + heritage.index + heritage[0].length;
1539
+ const comma = implemented === void 0 ? void 0 : findSeparators(code, depths, ",", 0).find((index) => index > implemented && index < open);
1540
+ const parameters = generic === void 0 ? [] : [start, ...findSeparators(code, depths, ",", 1).filter((index) => index < generic)].map((boundary, position, list) => /^\s*(?:(?:const|in|out)\s+)*([^\s=,>]+)/.exec(code.slice(boundary + 1, list[position + 1] ?? generic))?.[1] ?? "");
1541
+ const yielded = implemented === void 0 ? `${name}${parameters.length === 0 ? "" : `<${parameters.join(", ")}>`}` : source.slice(implemented, comma ?? open).trim();
1542
+ const constructors = members.filter((member) => /^\s*(?:(?:public|private|protected)\s+)?constructor\s*\(/.test(member.code)).map((member) => {
1543
+ const parenthesis = member.code.indexOf("(");
1544
+ const closed = findClosing(computeDepths(member.code), parenthesis) ?? member.code.length;
1545
+ return `new ${generics}(${member.source.slice(parenthesis + 1, closed)}) => ${yielded}`;
1546
+ });
1547
+ return {
1548
+ name,
1549
+ keyword,
1550
+ signature: constructors.length === 0 ? `new ${generics}() => ${yielded}` : constructors.length === 1 ? constructors[0] ?? "" : constructors.map((entry) => `(${entry})`).join(" & ")
1551
+ };
1552
+ }
1553
+ /**
1554
+ * Extracts every signature one compiler-emitted declaration file declares: each column-zero
1555
+ * `export` head read through {@link extractSignature}, an overload set's emitted heads joined in
1556
+ * order as an intersection of parenthesized signatures.
1557
+ *
1558
+ * @remarks
1559
+ * The text is read through {@link extractSourceLines}, so comment and template payload never
1560
+ * opens or closes a bracket. Each physical line is trimmed and a declaration's lines are joined
1561
+ * with single spaces, so a multi-line emitted type reads as one line. A head the projector does
1562
+ * not support, such as an `enum` or a re-export, contributes nothing. Every other repeated head
1563
+ * keeps its first signature.
1564
+ *
1565
+ * @param declaration - The emitted `.d.ts` text
1566
+ * @returns The declared symbols with their signatures, in first-seen order
1567
+ *
1568
+ * @example
1569
+ * ```ts
1570
+ * extractSignatures('export declare function open(id: string): boolean;\nexport declare function open(ids: readonly string[]): boolean;\n')
1571
+ * // [{ name: 'open', keyword: 'function', signature: '((id: string) => boolean) & ((ids: readonly string[]) => boolean)' }]
1572
+ * ```
1573
+ */
1574
+ function extractSignatures(declaration) {
1575
+ const records = extractSourceLines(declaration).map((line) => {
1576
+ const start = line.code.length - line.code.trimStart().length;
1577
+ const end = line.code.trimEnd().length;
1578
+ return {
1579
+ code: line.code.slice(start, end),
1580
+ source: line.source.slice(start, end),
1581
+ head: start === 0 && line.code.startsWith("export ")
1582
+ };
1583
+ }).filter((record) => record.code.length > 0);
1584
+ const heads = records.keys().filter((index) => records[index]?.head === true).toArray();
1585
+ const symbols = heads.map((head, position) => {
1586
+ const segment = records.slice(head, heads[position + 1] ?? records.length);
1587
+ return extractSignature(segment.map((record) => record.code).join(" "), segment.map((record) => record.source).join(" "));
1588
+ }).filter((symbol) => symbol !== void 0);
1589
+ return Array.from(new Set(symbols.map(computeSymbolKey))).flatMap((key) => {
1590
+ const declared = symbols.filter((symbol) => computeSymbolKey(symbol) === key);
1591
+ const [first] = declared;
1592
+ if (first === void 0) return [];
1593
+ if (first.keyword !== "function" || declared.length === 1) return [first];
1594
+ return [{
1595
+ ...first,
1596
+ signature: declared.map((symbol) => `(${symbol.signature ?? ""})`).join(" & ")
1597
+ }];
1598
+ });
1599
+ }
1600
+ /**
1245
1601
  * Joins the declaration head starting at `start` into one space-separated
1246
1602
  * line, consuming lines until the first that opens a body: one that ends with
1247
1603
  * `{`, or one that closes an empty body with `{}` or `{ }`.
@@ -1483,9 +1839,100 @@ function selectSectionBlocks(document, heading) {
1483
1839
  return scanned.filter((entry) => entry.active && !entry.heading).map((entry) => entry.block);
1484
1840
  }
1485
1841
  /**
1842
+ * Validates every `## Surface` table a guide carries: each header must be exactly
1843
+ * {@link SURFACE_HEADER}, and each row that keys a symbol must carry a non-empty `Signature` cell.
1844
+ *
1845
+ * @remarks
1846
+ * Reads each `## Surface` section through {@link selectSectionBlocks}, a repeated section
1847
+ * included, and refuses at the first offending table in document order, through {@link GuideError} with code
1848
+ * `header` for a nonuniform header and `signature` for a keyed empty cell. Header and row text in
1849
+ * the message is JSON-encoded and capped at 200 characters.
1850
+ *
1851
+ * @param document - The parsed guide document
1852
+ * @throws {@link GuideError} at the first nonuniform header or keyed empty Signature cell
1853
+ *
1854
+ * @example
1855
+ * ```ts
1856
+ * validateSurface(createMarkdown('## Surface\n\n| Name | Kind |\n| --- | --- |').document)
1857
+ * // throws GuideError: ## Surface table 1 has header "Name | Kind"; expected "Name | Kind | Signature | Summary".
1858
+ * ```
1859
+ */
1860
+ function validateSurface(document) {
1861
+ const expected = SURFACE_HEADER.join(" | ");
1862
+ const signed = SURFACE_HEADER.indexOf(SIGNATURE);
1863
+ const tables = new Set(document.children.flatMap((block, start) => isHeadingNode(block) && block.level === 2 && flattenText(block).trim() === "Surface" ? selectSectionBlocks({
1864
+ ...document,
1865
+ children: document.children.slice(start)
1866
+ }, SURFACE) : []).filter(isTableNode));
1867
+ for (const [index, table] of Array.from(tables).entries()) {
1868
+ const header = table.header.map((children) => flattenText({
1869
+ element: "paragraph",
1870
+ children
1871
+ }).trim());
1872
+ if (header.length !== SURFACE_HEADER.length || !SURFACE_HEADER.every((name, column) => header[column] === name)) throw new GuideError(`## Surface table ${index + 1} has header ${JSON.stringify(header.join(" | ").slice(0, 200))}; expected ${JSON.stringify(expected)}.`, "header");
1873
+ for (const position of table.rows.keys()) {
1874
+ const symbol = extractRowSymbol(table, position);
1875
+ if (symbol === void 0) continue;
1876
+ const cell = table.rows[position]?.[signed];
1877
+ if (cell !== void 0 && flattenText({
1878
+ element: "paragraph",
1879
+ children: cell
1880
+ }).trim().length > 0) continue;
1881
+ throw new GuideError(`## Surface table ${index + 1} row ${position + 1} (${JSON.stringify(`${symbol.keyword} ${symbol.name}`.slice(0, 200))}) has an empty Signature cell; expected a non-empty TypeScript signature code span under ${JSON.stringify(expected)}.`, "signature");
1882
+ }
1883
+ }
1884
+ }
1885
+ /**
1886
+ * Validates that the modules one manifest entry spans declare disjoint exports: one name exported
1887
+ * from two modules, whatever its keyword, is one capability split across environments.
1888
+ *
1889
+ * @remarks
1890
+ * Each source file answers for the most specific listed module directory that contains it, so a
1891
+ * nested module listed beside its parent never collides with itself. Logic that serves several
1892
+ * environments lives once in its layer's `core` directory, such as `src/core` or `app/core`;
1893
+ * environments whose internals differ each export a distinct name. Every colliding name is
1894
+ * reported in one refusal, in key order, each with every module that declares it; name and module
1895
+ * text is JSON-encoded and capped at 200 characters.
1896
+ *
1897
+ * @param files - The workspace-relative inventory the modules are read from
1898
+ * @param module - The manifest entry's source scope
1899
+ * @throws {@link GuideError} with code `collision` naming each name and the modules that declare it
1900
+ *
1901
+ * @example
1902
+ * ```ts
1903
+ * validateModules(
1904
+ * { 'src/core/a.ts': 'export function open() {}', 'src/server/a.ts': 'export function open() {}' },
1905
+ * ['src/core', 'src/server'],
1906
+ * )
1907
+ * // throws GuideError: "open" is declared in "src/core" and "src/server"; …
1908
+ * ```
1909
+ */
1910
+ function validateModules(files, module) {
1911
+ const directories = normalizeDirectories(module);
1912
+ const declared = selectModuleKeys(files, directories).flatMap((key) => {
1913
+ const owner = directories.filter((directory) => directory === "." || key.startsWith(`${directory}/`)).reduce((current, directory) => directory.length > current.length ? directory : current, "");
1914
+ return extractExports(files[key] ?? "").map((symbol) => ({
1915
+ key: symbol.name,
1916
+ owner
1917
+ }));
1918
+ });
1919
+ const collisions = Array.from(new Set(declared.map((entry) => entry.key))).sort().map((key) => ({
1920
+ key,
1921
+ owners: directories.filter((directory) => declared.some((entry) => entry.key === key && entry.owner === directory))
1922
+ })).filter((collision) => collision.owners.length > 1);
1923
+ if (collisions.length === 0) return;
1924
+ const named = collisions.map((collision) => `${JSON.stringify(collision.key.slice(0, 200))} is declared in ${collision.owners.map((owner) => JSON.stringify(owner.slice(0, 200))).join(" and ")}`);
1925
+ const cores = Array.from(new Set(collisions.flatMap((collision) => collision.owners.filter((owner) => owner !== ".").map((owner) => `${owner.replace(/\/.*$/u, "").slice(0, 200)}/core`)))).sort();
1926
+ throw new GuideError(`${named.join("; ")}; one name exported from two environments is a conflict. Declare logic both environments share once in ${cores.join(" or ")}, and give each environment's own logic a distinct name.`, "collision", { context: { collisions: collisions.map((collision) => ({
1927
+ name: collision.key,
1928
+ modules: collision.owners
1929
+ })) } });
1930
+ }
1931
+ /**
1486
1932
  * Extracts one `## Surface` table row's symbol — its column 0 code span as the name, its
1487
- * {@link KIND} column as the keyword, and its {@link SUMMARY} column as the compared summary
1488
- * when the table has that column. A row with no code-span name and a row whose `Kind` text is
1933
+ * {@link KIND} column as the keyword, and its exact `Signature` and {@link SUMMARY} columns as
1934
+ * normalized text when those columns exist. Empty cells remain absent. A row with no code-span
1935
+ * name and a row whose `Kind` text is
1489
1936
  * no {@link ExportKeyword} have no symbol to key, so each returns `undefined`.
1490
1937
  *
1491
1938
  * @param table - The table to read
@@ -1512,9 +1959,13 @@ function extractRowSymbol(table, row) {
1512
1959
  }).trim();
1513
1960
  if (!isExportKeyword(keyword)) return void 0;
1514
1961
  const summary = extractRowSummary(table, row);
1962
+ const signed = findColumnIndex(table, SIGNATURE);
1963
+ const signatureCell = signed === void 0 ? void 0 : cells[signed];
1964
+ const signature = signatureCell === void 0 ? "" : normalizeSummary(extractCellText(signatureCell));
1515
1965
  return {
1516
1966
  name,
1517
1967
  keyword,
1968
+ ...signature.length === 0 ? {} : { signature },
1518
1969
  ...summary === void 0 ? {} : { summary }
1519
1970
  };
1520
1971
  }
@@ -1575,7 +2026,8 @@ function extractRowSummary(table, row) {
1575
2026
  * symbol on, so this reader skips it and {@link extractUnnamed} reports it; a row with an
1576
2027
  * unrecognized `Kind` text is skipped. A row also carries its {@link SUMMARY} column's compared
1577
2028
  * text when the table has that column; a table without it leaves every row's summary absent,
1578
- * which {@link findDrift} reports.
2029
+ * which {@link findDrift} reports. The exact `Signature` column contributes normalized signature
2030
+ * text, including code spans, when present and non-empty; no other header supplies it.
1579
2031
  *
1580
2032
  * @remarks
1581
2033
  * The heading boundary compares {@link extractCellText} with the raw value from
@@ -1583,7 +2035,7 @@ function extractRowSummary(table, row) {
1583
2035
  * Surrounding spaces, emphasis, and links preserve that identity. This reader refuses a heading
1584
2036
  * carrying any other visible text or an additional code span. Entries retain encounter order, and
1585
2037
  * the first-seen name + keyword wins: a genuine heading before its table row keeps the heading's
1586
- * summary-less class entry, while a table row before that heading keeps its `Summary`.
2038
+ * class entry without signature or summary, while a preceding table row keeps both cells.
1587
2039
  *
1588
2040
  * @param document - The parsed guide document
1589
2041
  * @returns The documented surface, in encounter order
@@ -2437,8 +2889,9 @@ function formatDrift(drift) {
2437
2889
  }
2438
2890
  /**
2439
2891
  * Finds every disagreement between a guide and the source it documents, naming both sites:
2440
- * each `## Surface` row against its declaration's description paragraph, each `## Methods`
2441
- * row against its member's, and the first titled guide fence of a heading against the
2892
+ * each `## Surface` row against its declaration's description paragraph, each present
2893
+ * `Signature` cell against the declaration's computed signature written as a code span, each
2894
+ * `## Methods` row against its member's, and the first titled guide fence of a heading against the
2442
2895
  * `@example` block of the same title. An example's compared text is its language on the first
2443
2896
  * line and its body beneath, so a fence that names another language drifts on its own.
2444
2897
  *
@@ -2449,11 +2902,14 @@ function formatDrift(drift) {
2449
2902
  * pair where one side carries none, and a pair where neither side carries text are all drift.
2450
2903
  * The pairing is per title across the whole document, not per heading: the first fence a title
2451
2904
  * reaches is the compared one, and every later fence of that title is outside the comparison,
2452
- * whether it sits under the same heading or under a second heading of the same text.
2905
+ * whether it sits under the same heading or under a second heading of the same text. A signature
2906
+ * is compared only when both sides carry one, so an H3 entity heading, which carries no cell, and
2907
+ * a source reflected without emitted declarations stay outside that comparison.
2453
2908
  *
2454
2909
  * @param guide - The parsed guide
2455
2910
  * @param source - The reflected source the guide documents
2456
- * @returns One entry per disagreement: Surface rows, then Methods rows, then examples
2911
+ * @returns One entry per disagreement: each Surface row's summary then signature, then Methods
2912
+ * rows, then examples
2457
2913
  *
2458
2914
  * @example
2459
2915
  * ```ts
@@ -2469,6 +2925,13 @@ function findDrift(guide, source) {
2469
2925
  if (match === void 0) continue;
2470
2926
  const drift = computeDrift(key, "summary", symbol.summary, match.summary);
2471
2927
  if (drift !== void 0) drifts.push(drift);
2928
+ if (symbol.signature === void 0 || match.signature === void 0) continue;
2929
+ const computed = normalizeSummary(extractCellText([{
2930
+ element: "codeSpan",
2931
+ value: match.signature
2932
+ }]));
2933
+ const signed = computeDrift(key, "signature", symbol.signature, computed);
2934
+ if (signed !== void 0) drifts.push(signed);
2472
2935
  }
2473
2936
  for (const group of guide.methods()) {
2474
2937
  const members = new Map(source.methods(group.interface).map((entry) => [entry.name, entry]));
@@ -2516,26 +2979,26 @@ function collectTitles(guide, source) {
2516
2979
  return titled;
2517
2980
  }
2518
2981
  /**
2519
- * Builds a copy of `table` with one cell's inline content rebuilt from `text` through
2520
- * {@link buildCell}. Every other cell keeps its own nodes, so a rewrite touches the one cell it
2521
- * names and the header and the alignment row travel unchanged.
2982
+ * Builds a copy of `table` with one cell's inline content replaced by `cell`. Every other cell
2983
+ * keeps its own nodes, so a rewrite touches the one cell it names and the header and the
2984
+ * alignment row travel unchanged.
2522
2985
  *
2523
2986
  * @param table - The table to copy
2524
2987
  * @param row - The index of the row to rewrite within {@link TableNode.rows}
2525
2988
  * @param column - The index of the cell to rewrite within that row
2526
- * @param text - The cell's new compared text
2989
+ * @param cell - The cell's new inline content, such as {@link buildCell} returns
2527
2990
  * @returns The rewritten table
2528
2991
  *
2529
2992
  * @example
2530
2993
  * ```ts
2531
- * buildTable(table, 0, 2, 'Walks the tree.').rows[0]?.[2] // [{ element: 'text', value: 'Walks the tree.' }]
2994
+ * buildTable(table, 0, 3, buildCell('Walks the tree.')).rows[0]?.[3] // [{ element: 'text', value: 'Walks the tree.' }]
2532
2995
  * ```
2533
2996
  */
2534
- function buildTable(table, row, column, text) {
2997
+ function buildTable(table, row, column, cell) {
2535
2998
  return {
2536
2999
  element: "table",
2537
3000
  header: table.header,
2538
- rows: table.rows.map((cells, index) => index === row ? cells.map((cell, position) => position === column ? buildCell(text) : cell) : cells),
3001
+ rows: table.rows.map((cells, index) => index === row ? cells.map((current, position) => position === column ? cell : current) : cells),
2539
3002
  align: table.align
2540
3003
  };
2541
3004
  }
@@ -2578,10 +3041,10 @@ function spliceSpan(source, span, replacement) {
2578
3041
  return source.slice(0, span.start) + replacement + source.slice(span.end);
2579
3042
  }
2580
3043
  /**
2581
- * Renders a `## Surface` table from the symbols a source declares — a `Name`, {@link KIND}, and
2582
- * {@link SUMMARY} table with one row per symbol, the name as a code span, the keyword as its
2583
- * text, and the summary through {@link buildCell}. A symbol carrying no summary renders an empty
2584
- * cell, which {@link extractSurface} reads back as an absent summary.
3044
+ * Renders a uniform `Name | Kind | Signature | Summary` table with one row per symbol, the name
3045
+ * as a code span, the keyword as text, and the signature and summary through {@link buildCell}.
3046
+ * An absent signature or summary renders an empty cell, which {@link extractSurface} reads back
3047
+ * as absent. Guide construction refuses an empty signature cell.
2585
3048
  *
2586
3049
  * @remarks
2587
3050
  * The render carries no `## Surface` heading, because a guide documents its surface in several
@@ -2596,7 +3059,7 @@ function spliceSpan(source, span, replacement) {
2596
3059
  * @example
2597
3060
  * ```ts
2598
3061
  * renderSurface([{ name: 'walk', keyword: 'function', summary: 'Walks the tree.' }])
2599
- * // '| Name | Kind | Summary |\n| --- | --- | --- |\n| `walk` | function | Walks the tree. |'
3062
+ * // '| Name | Kind | Signature | Summary |\n| --- | --- | --- | --- |\n| `walk` | function | | Walks the tree. |'
2600
3063
  * ```
2601
3064
  */
2602
3065
  function renderSurface(symbols) {
@@ -2605,12 +3068,16 @@ function renderSurface(symbols) {
2605
3068
  header: [
2606
3069
  [{
2607
3070
  element: "text",
2608
- value: "Name"
3071
+ value: NAME
2609
3072
  }],
2610
3073
  [{
2611
3074
  element: "text",
2612
3075
  value: KIND
2613
3076
  }],
3077
+ [{
3078
+ element: "text",
3079
+ value: SIGNATURE
3080
+ }],
2614
3081
  [{
2615
3082
  element: "text",
2616
3083
  value: SUMMARY
@@ -2625,9 +3092,11 @@ function renderSurface(symbols) {
2625
3092
  element: "text",
2626
3093
  value: symbol.keyword
2627
3094
  }],
3095
+ buildCell(symbol.signature ?? ""),
2628
3096
  buildCell(symbol.summary ?? "")
2629
3097
  ]),
2630
3098
  align: [
3099
+ null,
2631
3100
  null,
2632
3101
  null,
2633
3102
  null
@@ -2666,7 +3135,7 @@ function renderMethods(group) {
2666
3135
  element: "table",
2667
3136
  header: [[{
2668
3137
  element: "text",
2669
- value: "Name"
3138
+ value: NAME
2670
3139
  }], [{
2671
3140
  element: "text",
2672
3141
  value: SUMMARY
@@ -2718,33 +3187,36 @@ function renderExample(example) {
2718
3187
  /**
2719
3188
  * Replaces one compared cell in a guide's text and returns the whole guide back. `key` names the
2720
3189
  * row the way {@link findDrift} names it — a {@link computeSymbolKey} key for a `## Surface` row,
2721
- * an `Owner.member` key for a `## Methods` row — and the row's {@link SUMMARY} cell becomes
2722
- * `summary`. Only the table's own source region is rewritten, so every byte outside it travels
2723
- * unchanged; a key reaching no cell returns `undefined`, and a row already carrying the summary
2724
- * returns the guide byte for byte.
3190
+ * an `Owner.member` key for a `## Methods` row — and the row's cell under the `column` header
3191
+ * becomes `cell`. Only the table's own source region is rewritten, so every byte outside it
3192
+ * travels unchanged; a key reaching no cell returns `undefined`, and a row already carrying that
3193
+ * cell returns the guide byte for byte.
2725
3194
  *
2726
3195
  * @remarks
2727
- * A row the key does not reach, a table carrying no {@link SUMMARY} column, and a document whose
2728
- * parse recorded no region for the table are each a miss, and a miss returns `undefined` rather
2729
- * than throwing, so a caller reports the key it could not place — the one meaning `undefined`
2730
- * carries in every replacer here. A row already carrying `summary` returns the guide byte for
2731
- * byte, because a rewrite would re-pad the whole table for no change; that identity reads both
2732
- * sides through {@link normalizeSummary}, so a caller passing text the compared form still moves
2733
- * is a fixed point on the second run rather than a row rewritten forever. The rewritten table
2734
- * renders one-space padded whatever padding it carried, so the checkout's formatter re-aligns it.
3196
+ * A row the key does not reach, a table carrying no `column` header, and a document whose parse
3197
+ * recorded no region for the table are each a miss, and a miss returns `undefined` rather than
3198
+ * throwing, so a caller reports the key it could not place — the one meaning `undefined` carries
3199
+ * in every replacer here. A row already carrying `cell` returns the guide byte for byte, because
3200
+ * a rewrite would re-pad the whole table for no change; that identity reads both cells through
3201
+ * {@link extractCellText} and {@link normalizeSummary}, so a caller passing text the compared form
3202
+ * still moves is a fixed point on the second run rather than a row rewritten forever. The
3203
+ * rewritten table renders one-space padded whatever padding it carried, so the checkout's
3204
+ * formatter re-aligns it, and a code span renders with every `|` written `\|` and a longer
3205
+ * backtick fence when its text holds a backtick.
2735
3206
  *
2736
3207
  * @param guide - The guide's markdown source
2737
3208
  * @param key - The compared key naming the row
2738
- * @param summary - The row's new compared text
3209
+ * @param column - The header text of the column to write, {@link SUMMARY} or {@link SIGNATURE}
3210
+ * @param cell - The cell's new inline content, such as {@link buildCell} returns
2739
3211
  * @returns The guide's text with that cell replaced, or `undefined` when the key reaches no cell
2740
3212
  *
2741
3213
  * @example
2742
3214
  * ```ts
2743
- * replaceCell('## Surface\n\n| Name | Kind | Summary |\n| --- | --- | --- |\n| `walk` | function | Walks. |', 'function walk', 'Walks a tree.')
2744
- * // '## Surface\n\n| Name | Kind | Summary |\n| --- | --- | --- |\n| `walk` | function | Walks a tree. |'
3215
+ * replaceCell('## Surface\n\n| Name | Kind | Signature | Summary |\n| --- | --- | --- | --- |\n| `walk` | function | `() => void` | Walks. |', 'function walk', SUMMARY, buildCell('Walks a tree.'))
3216
+ * // '## Surface\n\n| Name | Kind | Signature | Summary |\n| --- | --- | --- | --- |\n| `walk` | function | `() => void` | Walks a tree. |'
2745
3217
  * ```
2746
3218
  */
2747
- function replaceCell(guide, key, summary) {
3219
+ function replaceCell(guide, key, column, cell) {
2748
3220
  const markdown = createMarkdown(guide);
2749
3221
  const document = markdown.document;
2750
3222
  const surface = Iterator.from(selectSectionBlocks(document, SURFACE)).filter(isTableNode).flatMap((table) => table.rows.keys().map((index) => ({
@@ -2761,12 +3233,12 @@ function replaceCell(guide, key, summary) {
2761
3233
  }))).find((row) => row.entry !== void 0 && `${row.owner}.${row.entry.name}` === key);
2762
3234
  if (selected === void 0) return void 0;
2763
3235
  const { table, index } = selected;
2764
- const column = findColumnIndex(table, SUMMARY);
2765
- if (column === void 0) return void 0;
2766
- if ((extractRowSummary(table, index) ?? "") === normalizeSummary(summary)) return guide;
3236
+ const position = findColumnIndex(table, column);
3237
+ if (position === void 0) return void 0;
3238
+ if (normalizeSummary(extractCellText(table.rows[index]?.[position] ?? [])) === normalizeSummary(extractCellText(cell))) return guide;
2767
3239
  const span = markdown.span(table);
2768
3240
  if (span === void 0) return void 0;
2769
- return spliceSpan(guide, span, renderMarkdown(buildTable(table, index, column, summary)));
3241
+ return spliceSpan(guide, span, renderMarkdown(buildTable(table, index, position, cell)));
2770
3242
  }
2771
3243
  /**
2772
3244
  * Replaces one titled fence in a guide's text and returns the whole guide back. The first fence
@@ -3075,7 +3547,7 @@ function parseManifest(markdown, directory) {
3075
3547
  // src/core/shapers.ts
3076
3548
  /**
3077
3549
  * Shapes a {@link SurfaceSymbol} — a documented / exported symbol's `name`
3078
- * paired with its {@link ExportKeyword} and its optional compared `summary`.
3550
+ * paired with its {@link ExportKeyword}, optional `signature`, and optional compared `summary`.
3079
3551
  *
3080
3552
  * @example
3081
3553
  * ```ts
@@ -3089,6 +3561,7 @@ function parseManifest(markdown, directory) {
3089
3561
  var surfaceSymbolShape = objectShape({
3090
3562
  name: stringShape(),
3091
3563
  keyword: literalShape(EXPORT_KEYWORDS),
3564
+ signature: optionalShape(stringShape()),
3092
3565
  summary: optionalShape(stringShape())
3093
3566
  });
3094
3567
  /**
@@ -3192,14 +3665,16 @@ var manifestEntryShape = objectShape({
3192
3665
  * Parses `source` once through `@orkestrel/markdown` and never touches the
3193
3666
  * filesystem — `Guide` reads only the markdown text it is given and records
3194
3667
  * nothing about where the guide came from. Every accessor returns the same
3195
- * cached, readonly array on every call.
3668
+ * cached, readonly array on every call. Before caching, refuses the first Surface table with
3669
+ * a header other than `Name | Kind | Signature | Summary` or a keyed empty Signature cell,
3670
+ * through {@link validateSurface}.
3196
3671
  *
3197
3672
  * @example
3198
3673
  * ```ts
3199
3674
  * import { Guide } from '@orkestrel/guide'
3200
3675
  *
3201
- * const guide = new Guide('## Surface\n\n| Name | Kind |\n| --- | --- |\n| `X` | class |')
3202
- * guide.surface() // [{ name: 'X', keyword: 'class' }]
3676
+ * const guide = new Guide('## Surface\n\n| Name | Kind | Signature | Summary |\n| --- | --- | --- | --- |\n| `X` | class | `new () => X` | |')
3677
+ * guide.surface() // [{ name: 'X', keyword: 'class', signature: '`new () => X`' }]
3203
3678
  * ```
3204
3679
  */
3205
3680
  var Guide = class {
@@ -3213,6 +3688,7 @@ var Guide = class {
3213
3688
  #fences;
3214
3689
  constructor(source) {
3215
3690
  const document = createMarkdown(source).document;
3691
+ validateSurface(document);
3216
3692
  this.#sections = document.children.filter(isHeadingNode).filter((heading) => heading.level === 2).map((heading) => flattenText(heading).trim());
3217
3693
  this.#tagline = extractTagline(document);
3218
3694
  this.#surface = extractSurface(document);
@@ -3313,12 +3789,15 @@ var Source = class {
3313
3789
  #hidden;
3314
3790
  #declarations;
3315
3791
  #origins = /* @__PURE__ */ new Map();
3792
+ #emitted;
3793
+ #signed = /* @__PURE__ */ new Map();
3316
3794
  constructor(options) {
3317
3795
  this.#files = options.files;
3318
3796
  this.#directories = normalizeDirectories(options.module);
3797
+ this.#emitted = options.declarations;
3319
3798
  }
3320
3799
  exports() {
3321
- if (this.#exports === void 0) this.#exports = this.#scanSymbols(extractExports);
3800
+ if (this.#exports === void 0) this.#exports = this.#scanSymbols((key, text) => this.#scanExports(key, text));
3322
3801
  return this.#exports;
3323
3802
  }
3324
3803
  surface() {
@@ -3336,7 +3815,7 @@ var Source = class {
3336
3815
  return Object.keys(this.#files).some((key) => key === relative || key.startsWith(`${relative}/`));
3337
3816
  }
3338
3817
  hidden() {
3339
- if (this.#hidden === void 0) this.#hidden = this.#scanSymbols(extractHidden);
3818
+ if (this.#hidden === void 0) this.#hidden = this.#scanSymbols((_key, text) => extractHidden(text));
3340
3819
  return this.#hidden;
3341
3820
  }
3342
3821
  examples(name) {
@@ -3402,7 +3881,7 @@ var Source = class {
3402
3881
  visited.add(path);
3403
3882
  const text = this.#files[path];
3404
3883
  if (text === void 0) continue;
3405
- for (const symbol of extractExports(text)) {
3884
+ for (const symbol of this.#scanExports(path, text)) {
3406
3885
  const identity = computeSymbolKey(symbol);
3407
3886
  if (seen.has(identity)) continue;
3408
3887
  seen.add(identity);
@@ -3425,7 +3904,7 @@ var Source = class {
3425
3904
  for (const key of selectModuleKeys(this.#files, this.#directories)) {
3426
3905
  const text = this.#files[key];
3427
3906
  if (text === void 0) continue;
3428
- for (const symbol of scan(text)) {
3907
+ for (const symbol of scan(key, text)) {
3429
3908
  const identity = computeSymbolKey(symbol);
3430
3909
  if (seen.has(identity)) continue;
3431
3910
  seen.add(identity);
@@ -3434,6 +3913,23 @@ var Source = class {
3434
3913
  }
3435
3914
  return symbols.sort((a, b) => a.name === b.name ? 0 : a.name < b.name ? -1 : 1);
3436
3915
  }
3916
+ #scanExports(key, text) {
3917
+ const cached = this.#signed.get(key);
3918
+ if (cached !== void 0) return cached;
3919
+ const declaration = this.#emitted?.[`${key.slice(0, -3)}.d.ts`];
3920
+ const signatures = new Map((declaration === void 0 ? [] : extractSignatures(declaration)).map((symbol) => [computeSymbolKey(symbol), symbol.signature]));
3921
+ const symbols = extractExports(text).map((symbol) => {
3922
+ const signature = signatures.get(computeSymbolKey(symbol));
3923
+ return signature === void 0 ? symbol : {
3924
+ name: symbol.name,
3925
+ keyword: symbol.keyword,
3926
+ signature,
3927
+ ...symbol.summary === void 0 ? {} : { summary: symbol.summary }
3928
+ };
3929
+ });
3930
+ this.#signed.set(key, symbols);
3931
+ return symbols;
3932
+ }
3437
3933
  #members(keyword, name, visited) {
3438
3934
  if (visited.has(name)) return [];
3439
3935
  visited.add(name);
@@ -3534,7 +4030,8 @@ var Parity = class Parity {
3534
4030
  modules: { ...options.modules },
3535
4031
  languages: [...options.languages],
3536
4032
  language: options.language,
3537
- ...options.pitch === void 0 ? {} : { pitch: { ...options.pitch } }
4033
+ ...options.pitch === void 0 ? {} : { pitch: { ...options.pitch } },
4034
+ ...options.declarations === void 0 ? {} : { declarations: { ...options.declarations } }
3538
4035
  };
3539
4036
  this.#rows = this.#createRows(this.#options.files);
3540
4037
  }
@@ -3635,17 +4132,31 @@ var Parity = class Parity {
3635
4132
  for (const entry of this.#options.entries) {
3636
4133
  const text = files[entry.spec];
3637
4134
  if (text === void 0) continue;
4135
+ const guide = this.#attribute(entry.spec, () => new Guide(text));
4136
+ this.#attribute(entry.spec, () => validateModules(files, entry.source));
3638
4137
  rows.push({
3639
4138
  entry,
3640
- guide: new Guide(text),
4139
+ guide,
3641
4140
  source: new Source({
3642
4141
  files,
3643
- module: entry.source
4142
+ module: entry.source,
4143
+ ...this.#options.declarations === void 0 ? {} : { declarations: this.#options.declarations }
3644
4144
  })
3645
4145
  });
3646
4146
  }
3647
4147
  return rows;
3648
4148
  }
4149
+ #attribute(spec, step) {
4150
+ try {
4151
+ return step();
4152
+ } catch (error) {
4153
+ if (!isGuideError(error)) throw error;
4154
+ throw new GuideError(`${JSON.stringify(spec.slice(0, 200))}: ${error.message}`, error.code, {
4155
+ cause: error,
4156
+ ...error.context === void 0 ? {} : { context: error.context }
4157
+ });
4158
+ }
4159
+ }
3649
4160
  #inspectInput(findings) {
3650
4161
  if (this.#options.entries.length === 0) findings.push({ text: "The manifest has no guide entries." });
3651
4162
  for (const entry of this.#options.entries) {
@@ -3862,8 +4373,8 @@ var Parity = class Parity {
3862
4373
  });
3863
4374
  return;
3864
4375
  }
3865
- const left = new Guide(readme).tagline();
3866
- const right = new Guide(spec).tagline();
4376
+ const left = this.#attribute(pitch.readme, () => new Guide(readme)).tagline();
4377
+ const right = this.#attribute(pitch.spec, () => new Guide(spec)).tagline();
3867
4378
  if (left !== void 0 && left === right) return;
3868
4379
  findings.push({
3869
4380
  spec: pitch.spec,
@@ -3875,11 +4386,22 @@ var Parity = class Parity {
3875
4386
  const current = files.get(row.entry.spec);
3876
4387
  if (current === void 0) return "the guide inventory text is absent";
3877
4388
  if (drift.category === "summary") {
3878
- const replacement = replaceCell(current, drift.key, drift.source);
4389
+ const replacement = replaceCell(current, drift.key, SUMMARY, buildCell(drift.source));
3879
4390
  if (replacement === void 0) return "the guide summary cell or its provenance is unavailable";
3880
4391
  files.set(row.entry.spec, replacement);
3881
4392
  return;
3882
4393
  }
4394
+ if (drift.category === "signature") {
4395
+ const signature = row.source.surface().find((symbol) => computeSymbolKey(symbol) === drift.key)?.signature;
4396
+ if (signature === void 0) return "the computed signature is unavailable";
4397
+ const replacement = replaceCell(current, drift.key, SIGNATURE, [{
4398
+ element: "codeSpan",
4399
+ value: signature
4400
+ }]);
4401
+ if (replacement === void 0) return "the guide signature cell or its provenance is unavailable";
4402
+ files.set(row.entry.spec, replacement);
4403
+ return;
4404
+ }
3883
4405
  const example = collectTitles(row.guide, row.source).get(drift.key);
3884
4406
  if (example === void 0) return "the paired source example is unavailable";
3885
4407
  const replacement = replaceFence(current, drift.key, example);
@@ -3887,6 +4409,7 @@ var Parity = class Parity {
3887
4409
  files.set(row.entry.spec, replacement);
3888
4410
  }
3889
4411
  #rewriteSource(row, drift, files) {
4412
+ if (drift.category === "signature") return "a signature is computed from the source declaration";
3890
4413
  if (drift.guide === void 0) return "guide authority is absent";
3891
4414
  if (drift.category === "summary") {
3892
4415
  const located = this.#locateSource(row.entry, drift.key, files);
@@ -3960,13 +4483,16 @@ var Parity = class Parity {
3960
4483
  *
3961
4484
  * @param source - The guide's markdown source text
3962
4485
  * @returns A working {@link GuideInterface}
4486
+ * @throws {@link GuideError} when a Surface header is nonuniform or a keyed Signature cell is empty.
3963
4487
  *
3964
4488
  * @example Construct a Guide from markdown text
3965
4489
  * ```ts
3966
4490
  * import { createGuide } from '@orkestrel/guide'
3967
4491
  *
3968
- * const guide = createGuide('## Surface\n\n| Name | Kind |\n| --- | --- |\n| `X` | class |')
3969
- * guide.surface() // [{ name: 'X', keyword: 'class' }]
4492
+ * const guide = createGuide(
4493
+ * '## Surface\n\n| Name | Kind | Signature | Summary |\n| --- | --- | --- | --- |\n| `X` | class | `new () => X` | |',
4494
+ * )
4495
+ * guide.surface() // [{ name: 'X', keyword: 'class', signature: '`new () => X`' }]
3970
4496
  * guide.sections() // ['Surface']
3971
4497
  * ```
3972
4498
  */
@@ -4138,6 +4664,6 @@ function createMethodGroupContract() {
4138
4664
  function createManifestEntryContract() {
4139
4665
  return createContract(manifestEntryShape);
4140
4666
  }
4141
- export { DRIFT_CATEGORIES, EXPORT_KEYWORDS, EXTERNAL_SCHEMES, Guide, KIND, MANIFEST, METHODS, Parity, SUMMARY, SURFACE, Source, SourceManager, TESTS, WRAP_WIDTH, buildCell, buildComment, buildFence, buildTable, collectDeclarations, collectExamples, collectFences, collectGroups, collectKeys, collectSummaries, collectTitles, compareMembership, computeDrift, computeModuleKey, computeSymbolKey, createDriftContract, createGuide, createManifestEntryContract, createMethodEntryContract, createMethodGroupContract, createSource, createSourceExampleContract, createSourceManager, createSurfaceSymbolContract, driftShape, escapeRegExp, extractBodyLines, extractCellLinks, extractCellText, extractDeclaration, extractExampleLines, extractExampleMethods, extractExamples, extractExports, extractFenceImports, extractFences, extractHidden, extractLinks, extractMemberMethods, extractMethods, extractRowEntry, extractRowSummary, extractRowSymbol, extractSourceComments, extractSourceLines, extractSurface, extractTagline, extractTests, extractUnnamed, findColumnIndex, findDrift, findFirstCode, findMissing, findMissingSymbols, findUnexampled, findUnlisted, formatDrift, formatSide, hasBehaviouralSurface, hasCanonicalSegments, identifyDrift, isDrift, isDriftCategory, isExportKeyword, isExternalLink, isManifestEntry, isMethodEntry, isMethodGroup, isSourceExample, isSurfaceSymbol, joinHead, locateComment, manifestEntryShape, maskFences, methodEntryShape, methodGroupShape, normalizeComment, normalizeDirectories, normalizeIdentifier, normalizeSummary, parseManifest, renderExample, renderMethods, renderSurface, replaceCell, replaceExample, replaceFence, replaceSummary, resolveLink, resolvePath, selectModuleKeys, selectSectionBlocks, sourceExampleShape, spliceSpan, surfaceSymbolShape, unwrapComment, wrapText };
4667
+ export { DRIFT_CATEGORIES, EXPORT_KEYWORDS, EXTERNAL_SCHEMES, GUIDE_CODES, GUIDE_ERROR_BRAND, Guide, GuideError, KIND, MANIFEST, METHODS, NAME, Parity, SIGNATURE, SUMMARY, SURFACE, SURFACE_HEADER, Source, SourceManager, TESTS, WRAP_WIDTH, buildCell, buildComment, buildFence, buildTable, collectDeclarations, collectExamples, collectFences, collectGroups, collectKeys, collectSummaries, collectTitles, compareMembership, computeDepths, computeDrift, computeModuleKey, computeSymbolKey, createDriftContract, createGuide, createManifestEntryContract, createMethodEntryContract, createMethodGroupContract, createSource, createSourceExampleContract, createSourceManager, createSurfaceSymbolContract, driftShape, escapeRegExp, extractBodyLines, extractCellLinks, extractCellText, extractDeclaration, extractExampleLines, extractExampleMethods, extractExamples, extractExports, extractFenceImports, extractFences, extractHidden, extractLinks, extractMemberMethods, extractMethods, extractRowEntry, extractRowSummary, extractRowSymbol, extractSignature, extractSignatures, extractSourceComments, extractSourceLines, extractSurface, extractTagline, extractTests, extractUnnamed, findClosing, findColumnIndex, findDrift, findFirstCode, findMissing, findMissingSymbols, findSeparators, findUnexampled, findUnlisted, formatDrift, formatSide, hasBehaviouralSurface, hasCanonicalSegments, identifyDrift, isDrift, isDriftCategory, isExportKeyword, isExternalLink, isGuideError, isManifestEntry, isMethodEntry, isMethodGroup, isSourceExample, isSurfaceSymbol, joinHead, locateComment, manifestEntryShape, maskFences, methodEntryShape, methodGroupShape, normalizeComment, normalizeDirectories, normalizeIdentifier, normalizeSummary, parseManifest, renderExample, renderMember, renderMethods, renderSurface, replaceCell, replaceExample, replaceFence, replaceSummary, resolveLink, resolvePath, selectModuleKeys, selectSectionBlocks, sourceExampleShape, spliceSpan, surfaceSymbolShape, unwrapComment, validateModules, validateSurface, wrapText };
4142
4668
 
4143
4669
  //# sourceMappingURL=index.js.map