@orkestrel/guide 0.0.26 → 0.0.27

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