@orkestrel/guide 0.0.8 → 0.0.9

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.
@@ -31,25 +31,541 @@ var EXTERNAL_SCHEMES = Object.freeze([
31
31
  //#endregion
32
32
  //#region src/core/helpers.ts
33
33
  /**
34
- * A module scope normalized to its directory list — a single directory
35
- * becomes a one-element list so every scanner walks the same shape.
34
+ * Extract aligned physical source-line records in one character traversal.
35
+ * Real line and block comments and complete template tokens become spaces in
36
+ * {@link SourceLine.code}, while ordinary code, quoted strings, and recognized
37
+ * regex literals retain their columns. Genuine JSDoc opened from reflection
38
+ * code is retained span by span at its exact physical column in
39
+ * {@link SourceLine.jsdoc}; faux openers in comments and templates are
40
+ * excluded. Membership remains each consumer's separate anchored grammar.
41
+ *
42
+ * @remarks
43
+ * Regex recognition is a bounded lexical goal rather than TypeScript parser
44
+ * grammar. Literal ECMAScript Unicode identifiers participate in slash-state
45
+ * recognition, including private identifiers, without decoding escaped
46
+ * identifier spellings. Slash after bare `}` is division, and a post-brace
47
+ * regex statement requires an explicit `;`. General semicolonless
48
+ * declaration/ASI classification is outside this finite projector, so callers
49
+ * place an explicit `;` before a slash-leading statement after such a
50
+ * declaration.
51
+ *
52
+ * @param source - The TypeScript source text to project
53
+ * @returns One aligned terminator-free record per LF or CRLF physical line, including the final line
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * extractSourceLines('export const visible = true // note\n')
58
+ * // [{ source: 'export const visible = true // note', code: 'export const visible = true ', jsdoc: undefined }, ...]
59
+ * ```
60
+ */
61
+ function extractSourceLines(source) {
62
+ const lines = [];
63
+ let characters = [];
64
+ let jsdocCharacters = [];
65
+ const identifier = /#?[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}]*/uy;
66
+ const templates = [];
67
+ const parentheses = [];
68
+ let start = 0;
69
+ let mode = "code";
70
+ let escaped = false;
71
+ let regexClass = false;
72
+ let operandExpected = true;
73
+ let memberExpected = false;
74
+ let pendingRole;
75
+ let restricted;
76
+ let separated = false;
77
+ let blockTemplate = false;
78
+ let lineTemplate = false;
79
+ let jsdoc = false;
80
+ let jsdocPresent = false;
81
+ for (let offset = 0; offset < source.length; offset += 1) {
82
+ const character = source[offset];
83
+ if (character === void 0) continue;
84
+ const next = source[offset + 1];
85
+ const crlf = character === "\r" && next === "\n";
86
+ if (character === "\n" || crlf) {
87
+ const code = characters.join("");
88
+ const present = jsdocPresent || jsdoc;
89
+ lines.push({
90
+ source: source.slice(start, offset),
91
+ code,
92
+ jsdoc: present ? jsdocCharacters.join("").padEnd(code.length, " ") : void 0
93
+ });
94
+ characters = [];
95
+ jsdocCharacters = [];
96
+ jsdocPresent = jsdoc;
97
+ if (mode !== "template") separated = true;
98
+ if (restricted !== void 0) {
99
+ operandExpected = true;
100
+ memberExpected = false;
101
+ pendingRole = void 0;
102
+ restricted = void 0;
103
+ }
104
+ if (crlf) offset += 1;
105
+ start = offset + 1;
106
+ if (mode === "line") mode = lineTemplate ? "templateCode" : "code";
107
+ else if (mode === "regex") {
108
+ mode = "code";
109
+ operandExpected = true;
110
+ regexClass = false;
111
+ } else if (mode === "templateLine" || mode === "templateRegex") {
112
+ mode = "templateCode";
113
+ operandExpected = true;
114
+ regexClass = false;
115
+ } else if (mode === "single" || mode === "double") {
116
+ if (!escaped) {
117
+ mode = "code";
118
+ operandExpected = true;
119
+ }
120
+ } else if (mode === "templateSingle" || mode === "templateDouble") {
121
+ if (!escaped) {
122
+ mode = "templateCode";
123
+ operandExpected = true;
124
+ }
125
+ }
126
+ escaped = false;
127
+ continue;
128
+ }
129
+ if (mode === "line" || mode === "templateLine") {
130
+ characters.push(" ");
131
+ continue;
132
+ }
133
+ if (mode === "block" || mode === "templateBlock") {
134
+ characters.push(" ");
135
+ if (jsdoc) jsdocCharacters.push(character);
136
+ if (character === "*" && next === "/") {
137
+ characters.push(" ");
138
+ if (jsdoc) {
139
+ jsdocCharacters.push("/");
140
+ jsdoc = false;
141
+ }
142
+ offset += 1;
143
+ mode = blockTemplate ? "templateCode" : "code";
144
+ }
145
+ continue;
146
+ }
147
+ if (mode === "single" || mode === "double") {
148
+ characters.push(character);
149
+ if (escaped) {
150
+ escaped = false;
151
+ continue;
152
+ }
153
+ if (character === "\\") {
154
+ escaped = true;
155
+ continue;
156
+ }
157
+ if (mode === "single" && character === "'" || mode === "double" && character === "\"") {
158
+ mode = "code";
159
+ operandExpected = false;
160
+ }
161
+ continue;
162
+ }
163
+ if (mode === "regex") {
164
+ characters.push(character);
165
+ if (escaped) {
166
+ escaped = false;
167
+ continue;
168
+ }
169
+ if (character === "\\") {
170
+ escaped = true;
171
+ continue;
172
+ }
173
+ if (character === "[") regexClass = true;
174
+ else if (character === "]") regexClass = false;
175
+ else if (character === "/" && !regexClass) {
176
+ mode = "code";
177
+ operandExpected = false;
178
+ }
179
+ continue;
180
+ }
181
+ if (mode === "templateSingle" || mode === "templateDouble") {
182
+ characters.push(" ");
183
+ if (escaped) {
184
+ escaped = false;
185
+ continue;
186
+ }
187
+ if (character === "\\") {
188
+ escaped = true;
189
+ continue;
190
+ }
191
+ if (mode === "templateSingle" && character === "'" || mode === "templateDouble" && character === "\"") {
192
+ mode = "templateCode";
193
+ operandExpected = false;
194
+ }
195
+ continue;
196
+ }
197
+ if (mode === "templateRegex") {
198
+ characters.push(" ");
199
+ if (escaped) {
200
+ escaped = false;
201
+ continue;
202
+ }
203
+ if (character === "\\") {
204
+ escaped = true;
205
+ continue;
206
+ }
207
+ if (character === "[") regexClass = true;
208
+ else if (character === "]") regexClass = false;
209
+ else if (character === "/" && !regexClass) {
210
+ mode = "templateCode";
211
+ operandExpected = false;
212
+ }
213
+ continue;
214
+ }
215
+ if (mode === "template") {
216
+ characters.push(" ");
217
+ if (escaped) {
218
+ escaped = false;
219
+ continue;
220
+ }
221
+ if (character === "\\") {
222
+ escaped = true;
223
+ continue;
224
+ }
225
+ if (character === "$" && next === "{") {
226
+ characters.push(" ");
227
+ offset += 1;
228
+ const index = templates.length - 1;
229
+ if (index >= 0) templates[index] = 1;
230
+ mode = "templateCode";
231
+ operandExpected = true;
232
+ memberExpected = false;
233
+ pendingRole = void 0;
234
+ continue;
235
+ }
236
+ if (character === "`") {
237
+ templates.pop();
238
+ mode = templates.length === 0 ? "code" : "templateCode";
239
+ operandExpected = false;
240
+ }
241
+ continue;
242
+ }
243
+ const templateCode = mode === "templateCode";
244
+ if (character === "/" && next === "/") {
245
+ characters.push(" ", " ");
246
+ offset += 1;
247
+ lineTemplate = templateCode;
248
+ mode = templateCode ? "templateLine" : "line";
249
+ continue;
250
+ }
251
+ if (character === "/" && next === "*") {
252
+ characters.push(" ", " ");
253
+ if (!templateCode && source[offset + 2] === "*") {
254
+ const column = offset - start;
255
+ const width = jsdocCharacters.join("").length;
256
+ jsdocCharacters.push(" ".repeat(column - width), "/", "*");
257
+ jsdoc = true;
258
+ jsdocPresent = true;
259
+ }
260
+ offset += 1;
261
+ blockTemplate = templateCode;
262
+ mode = templateCode ? "templateBlock" : "block";
263
+ continue;
264
+ }
265
+ if (character === "'") {
266
+ characters.push(templateCode ? " " : character);
267
+ mode = templateCode ? "templateSingle" : "single";
268
+ escaped = false;
269
+ separated = false;
270
+ restricted = void 0;
271
+ continue;
272
+ }
273
+ if (character === "\"") {
274
+ characters.push(templateCode ? " " : character);
275
+ mode = templateCode ? "templateDouble" : "double";
276
+ escaped = false;
277
+ separated = false;
278
+ restricted = void 0;
279
+ continue;
280
+ }
281
+ if (character === "`") {
282
+ characters.push(" ");
283
+ templates.push(0);
284
+ mode = "template";
285
+ escaped = false;
286
+ separated = false;
287
+ restricted = void 0;
288
+ continue;
289
+ }
290
+ const visible = templateCode ? " " : character;
291
+ if (character === "/" && next === "=" && !operandExpected) {
292
+ characters.push(visible, templateCode ? " " : "=");
293
+ offset += 1;
294
+ operandExpected = true;
295
+ memberExpected = false;
296
+ pendingRole = void 0;
297
+ separated = false;
298
+ restricted = void 0;
299
+ continue;
300
+ }
301
+ if (character === "/") {
302
+ characters.push(visible);
303
+ if (operandExpected) {
304
+ mode = templateCode ? "templateRegex" : "regex";
305
+ escaped = false;
306
+ regexClass = false;
307
+ } else {
308
+ operandExpected = true;
309
+ memberExpected = false;
310
+ pendingRole = void 0;
311
+ }
312
+ separated = false;
313
+ restricted = void 0;
314
+ continue;
315
+ }
316
+ identifier.lastIndex = offset;
317
+ const identifierMatch = identifier.exec(source);
318
+ if (identifierMatch !== null) {
319
+ const token = identifierMatch[0];
320
+ characters.push(templateCode ? " ".repeat(token.length) : token);
321
+ if (token.startsWith("#")) {
322
+ operandExpected = false;
323
+ memberExpected = false;
324
+ pendingRole = void 0;
325
+ restricted = void 0;
326
+ separated = false;
327
+ offset += token.length - 1;
328
+ continue;
329
+ }
330
+ const frame = parentheses[parentheses.length - 1];
331
+ const label = restricted === "label";
332
+ restricted = void 0;
333
+ separated = false;
334
+ if (memberExpected) {
335
+ memberExpected = false;
336
+ operandExpected = false;
337
+ pendingRole = void 0;
338
+ } else if (label) {
339
+ operandExpected = false;
340
+ pendingRole = void 0;
341
+ restricted = "complete";
342
+ } else if (/^(?:if|while|with)$/.test(token)) {
343
+ pendingRole = "statement";
344
+ operandExpected = true;
345
+ } else if (token === "for") {
346
+ pendingRole = "for";
347
+ operandExpected = true;
348
+ } else if (token === "export") {
349
+ pendingRole = "export";
350
+ operandExpected = true;
351
+ } else if (token === "default" && pendingRole === "export") {
352
+ pendingRole = void 0;
353
+ operandExpected = true;
354
+ } else if (/^(?:switch|catch)$/.test(token)) {
355
+ pendingRole = "block";
356
+ operandExpected = true;
357
+ } else if (token === "await" && pendingRole === "for") operandExpected = true;
358
+ else if (/^(?:return|throw|case|delete|void|typeof|new|await|yield|else|do|extends)$/.test(token)) {
359
+ pendingRole = void 0;
360
+ operandExpected = true;
361
+ } else if (/^(?:in|instanceof)$/.test(token)) {
362
+ pendingRole = void 0;
363
+ operandExpected = true;
364
+ } else if (/^(?:break|continue)$/.test(token)) {
365
+ pendingRole = void 0;
366
+ operandExpected = false;
367
+ restricted = "label";
368
+ } else if (token === "debugger") {
369
+ pendingRole = void 0;
370
+ operandExpected = false;
371
+ restricted = "complete";
372
+ } else if (token === "of" && frame?.role === "for" && frame.phase === "left" && !frame.binding && !operandExpected) {
373
+ frame.phase = "right";
374
+ operandExpected = true;
375
+ pendingRole = void 0;
376
+ } else if (/^(?:const|let|var)$/.test(token) && frame?.role === "for" && frame.phase === "left") {
377
+ frame.binding = true;
378
+ operandExpected = true;
379
+ pendingRole = void 0;
380
+ } else {
381
+ if (frame?.binding === true) frame.binding = false;
382
+ operandExpected = false;
383
+ pendingRole = void 0;
384
+ }
385
+ offset += token.length - 1;
386
+ continue;
387
+ }
388
+ if (/[0-9]/.test(character)) {
389
+ let end = offset + 1;
390
+ while (end < source.length) {
391
+ const part = source[end];
392
+ if (part === void 0 || !/[A-Za-z0-9_$.]/.test(part)) break;
393
+ end += 1;
394
+ }
395
+ const token = source.slice(offset, end);
396
+ characters.push(templateCode ? " ".repeat(token.length) : token);
397
+ operandExpected = false;
398
+ memberExpected = false;
399
+ pendingRole = void 0;
400
+ restricted = void 0;
401
+ separated = false;
402
+ offset = end - 1;
403
+ continue;
404
+ }
405
+ if (character === "!" && next === "=" && source[offset + 2] === "=" || character === "=" && next === "=" && source[offset + 2] === "=") {
406
+ characters.push(visible, templateCode ? " " : source.slice(offset + 1, offset + 3));
407
+ offset += 2;
408
+ operandExpected = true;
409
+ memberExpected = false;
410
+ pendingRole = void 0;
411
+ restricted = void 0;
412
+ separated = false;
413
+ continue;
414
+ }
415
+ if ((character === "!" || character === "=") && next === "=") {
416
+ characters.push(visible, templateCode ? " " : "=");
417
+ offset += 1;
418
+ operandExpected = true;
419
+ memberExpected = false;
420
+ pendingRole = void 0;
421
+ restricted = void 0;
422
+ separated = false;
423
+ continue;
424
+ }
425
+ if (character === "+" && next === "+" || character === "-" && next === "-") {
426
+ characters.push(visible, templateCode ? " " : next);
427
+ offset += 1;
428
+ if (separated) operandExpected = true;
429
+ memberExpected = false;
430
+ pendingRole = void 0;
431
+ restricted = void 0;
432
+ separated = false;
433
+ continue;
434
+ }
435
+ if (character === "." && next === "." && source[offset + 2] === ".") {
436
+ characters.push(visible, templateCode ? " " : "..");
437
+ offset += 2;
438
+ operandExpected = true;
439
+ memberExpected = false;
440
+ pendingRole = void 0;
441
+ restricted = void 0;
442
+ separated = false;
443
+ continue;
444
+ }
445
+ if (character === "?" && next === ".") {
446
+ characters.push(visible, templateCode ? " " : ".");
447
+ offset += 1;
448
+ operandExpected = false;
449
+ memberExpected = true;
450
+ pendingRole = void 0;
451
+ restricted = void 0;
452
+ separated = false;
453
+ continue;
454
+ }
455
+ characters.push(visible);
456
+ if (/\s/.test(character)) continue;
457
+ separated = false;
458
+ restricted = void 0;
459
+ if (character === "(") {
460
+ parentheses.push({
461
+ role: pendingRole ?? "plain",
462
+ phase: "left",
463
+ binding: false
464
+ });
465
+ operandExpected = true;
466
+ memberExpected = false;
467
+ pendingRole = void 0;
468
+ continue;
469
+ }
470
+ if (character === ")") {
471
+ const frame = parentheses.pop();
472
+ operandExpected = frame?.role === "statement" || frame?.role === "for";
473
+ memberExpected = false;
474
+ pendingRole = void 0;
475
+ continue;
476
+ }
477
+ if (character === ";") {
478
+ const frame = parentheses[parentheses.length - 1];
479
+ if (frame?.role === "for" && frame.phase === "left") frame.phase = "classic";
480
+ operandExpected = true;
481
+ memberExpected = false;
482
+ pendingRole = void 0;
483
+ continue;
484
+ }
485
+ if (character === ".") {
486
+ operandExpected = false;
487
+ memberExpected = true;
488
+ pendingRole = void 0;
489
+ continue;
490
+ }
491
+ if (character === "]" || character === "}") {
492
+ const frame = parentheses[parentheses.length - 1];
493
+ if (frame?.role === "for" && frame.phase === "left" && frame.binding) frame.binding = false;
494
+ }
495
+ if (character === "]") operandExpected = false;
496
+ else if (character === "}") {
497
+ const index = templates.length - 1;
498
+ const depth = templates[index];
499
+ if (templateCode && index >= 0 && depth !== void 0) {
500
+ templates[index] = depth - 1;
501
+ if (depth === 1) mode = "template";
502
+ }
503
+ operandExpected = false;
504
+ } else if (character === "{") {
505
+ const index = templates.length - 1;
506
+ const depth = templates[index];
507
+ if (templateCode && index >= 0 && depth !== void 0) templates[index] = depth + 1;
508
+ operandExpected = true;
509
+ } else if (character !== "!") operandExpected = true;
510
+ memberExpected = false;
511
+ pendingRole = void 0;
512
+ }
513
+ const code = characters.join("");
514
+ const present = jsdocPresent || jsdoc;
515
+ lines.push({
516
+ source: source.slice(start),
517
+ code,
518
+ jsdoc: present ? jsdocCharacters.join("").padEnd(code.length, " ") : void 0
519
+ });
520
+ return lines;
521
+ }
522
+ /**
523
+ * Whether an opaque inventory key contains only canonical slash-separated
524
+ * segments. Empty, `.` and `..` segments are rejected without rewriting the
525
+ * key; ordinary dotfile segments remain valid.
526
+ *
527
+ * @param key - The opaque inventory key to inspect
528
+ * @returns `true` when every segment is canonical
529
+ *
530
+ * @example
531
+ * ```ts
532
+ * hasCanonicalSegments('src/.hidden.ts') // true
533
+ * hasCanonicalSegments('src/../alias.ts') // false
534
+ * ```
535
+ */
536
+ function hasCanonicalSegments(key) {
537
+ return key.split("/").every((segment) => segment !== "" && segment !== "." && segment !== "..");
538
+ }
539
+ /**
540
+ * A module scope normalized to its canonical directory list. `'.'` represents
541
+ * workspace root; empty, trailing, and dot-segment spellings reduce through
542
+ * {@link resolvePath}, and duplicates are removed in first-seen order.
36
543
  *
37
544
  * @param module - The module scope to normalize
38
545
  * @returns The directory list `module` denotes
39
546
  *
40
547
  * @example
41
548
  * ```ts
42
- * moduleDirs('src/core') // ['src/core']
43
- * moduleDirs(['src/core', 'src/browser']) // ['src/core', 'src/browser']
549
+ * normalizeDirectories('src/core') // ['src/core']
550
+ * normalizeDirectories(['src/core', 'src/browser']) // ['src/core', 'src/browser']
44
551
  * ```
45
552
  */
46
- function moduleDirs(module) {
47
- return typeof module === "string" ? [module] : module;
553
+ function normalizeDirectories(module) {
554
+ const directories = [];
555
+ const seen = /* @__PURE__ */ new Set();
556
+ for (const value of typeof module === "string" ? [module] : module) {
557
+ const directory = resolvePath(".", value);
558
+ if (seen.has(directory)) continue;
559
+ seen.add(directory);
560
+ directories.push(directory);
561
+ }
562
+ return directories;
48
563
  }
49
564
  /**
50
- * The file inventory's keys belonging to a {@link GuideModule} scope, sorted —
51
- * a key belongs when it starts with one of the scope's directories, ends in
52
- * `.ts`, and is neither that directory's `index.ts` nor a `.test.ts` file.
565
+ * The exact opaque file-inventory keys belonging under any canonical
566
+ * {@link GuideModule} directory, sorted. `'.'` selects canonical root-relative
567
+ * keys without accepting `/`, `./`, or `../` aliases. Every selected exact
568
+ * `index.ts` and every `.test.ts` key is excluded independent of scope order.
53
569
  *
54
570
  * @param files - The workspace file inventory, root-relative path → file text
55
571
  * @param module - The module scope to filter to
@@ -57,18 +573,18 @@ function moduleDirs(module) {
57
573
  *
58
574
  * @example
59
575
  * ```ts
60
- * moduleKeys({ 'src/core/Guide.ts': '', 'src/core/index.ts': '' }, 'src/core') // ['src/core/Guide.ts']
576
+ * selectModuleKeys({ 'src/core/Guide.ts': '', 'src/core/index.ts': '' }, 'src/core') // ['src/core/Guide.ts']
61
577
  * ```
62
578
  */
63
- function moduleKeys(files, module) {
64
- const dirs = moduleDirs(module);
579
+ function selectModuleKeys(files, module) {
580
+ const dirs = normalizeDirectories(module);
581
+ const indexes = new Set(dirs.map((directory) => resolvePath(directory, "index.ts")));
65
582
  const keys = [];
66
583
  for (const key of Object.keys(files)) {
584
+ if (!hasCanonicalSegments(key)) continue;
67
585
  if (!key.endsWith(".ts")) continue;
68
586
  if (key.endsWith(".test.ts")) continue;
69
- const dir = dirs.find((candidate) => key.startsWith(`${candidate}/`));
70
- if (dir === void 0) continue;
71
- if (key === `${dir}/index.ts`) continue;
587
+ if (!dirs.some((directory) => directory === "." || key.startsWith(`${directory}/`)) || indexes.has(key)) continue;
72
588
  keys.push(key);
73
589
  }
74
590
  return keys.sort();
@@ -150,7 +666,7 @@ function findUnexampled(names, fences, examples) {
150
666
  * Parse a fence's `import` statements into per-specifier imported identifier
151
667
  * names — handles `import type`, mixed multiline braces, and `x as y` aliases
152
668
  * (resolved to the local name `x`... the ORIGINAL exported name, since it is
153
- * the export that must exist in `source.exports()`).
669
+ * the export that must exist in the checked public/barrel surface).
154
670
  *
155
671
  * @param fence - A ```ts Patterns fence's verbatim body text
156
672
  * @returns One entry per `import ... from 'specifier'` statement, in fence order
@@ -196,36 +712,54 @@ function isExternalLink(href) {
196
712
  return EXTERNAL_SCHEMES.some((scheme) => href.startsWith(scheme));
197
713
  }
198
714
  /**
199
- * Resolve a relative link `target` against `from` and normalize the result — `from`
200
- * is treated as a file (its directory is everything before the last `/`) when it
201
- * carries a `/`, or as a bare directory itself when it does not; `.` segments drop
202
- * and `..` segments pop the preceding component, purely (no `node:path`).
715
+ * Resolve a relative `target` from a root-relative `directory`, normalizing
716
+ * forward-slash dot segments without filesystem or extension inference. A
717
+ * parent pops only a retained real component; every excess leading parent is
718
+ * preserved.
203
719
  *
204
- * @param from - The declaring guide path (a file) or manifest base (a directory)
205
- * @param target - The relative link destination to resolve
206
- * @returns The normalized, workspace-root-relative path
720
+ * @param directory - The root-relative directory to resolve from
721
+ * @param target - The relative target to resolve
722
+ * @returns The normalized path, or `'.'` when no segment remains, retaining every excess parent
207
723
  *
208
724
  * @example
209
725
  * ```ts
210
- * resolveLink('guides/src/markdown.md', '../../src/core/helpers.ts') // 'src/core/helpers.ts'
211
- * resolveLink('guides', '../src/core') // 'src/core'
726
+ * resolvePath('guides/src', '../../src/core/helpers.ts') // 'src/core/helpers.ts'
727
+ * resolvePath('.', '../../outside.ts') // '../../outside.ts'
212
728
  * ```
213
729
  */
214
- function resolveLink(from, target) {
215
- const index = from.lastIndexOf("/");
216
- const dir = index < 0 ? from : from.slice(0, index);
217
- const combined = dir === "" ? target : `${dir}/${target}`;
730
+ function resolvePath(directory, target) {
731
+ const combined = `${directory}/${target}`;
218
732
  const segments = [];
219
733
  for (const segment of combined.split("/")) {
220
734
  if (segment === "" || segment === ".") continue;
221
735
  if (segment === "..") {
222
- if (segments.length > 0) segments.pop();
736
+ const previous = segments[segments.length - 1];
737
+ if (previous !== void 0 && previous !== "..") segments.pop();
223
738
  else segments.push(segment);
224
739
  continue;
225
740
  }
226
741
  segments.push(segment);
227
742
  }
228
- return segments.join("/");
743
+ return segments.length === 0 ? "." : segments.join("/");
744
+ }
745
+ /**
746
+ * Resolve a relative `target` from the directory containing a root-relative
747
+ * declaring `file`. A slashless file belongs to the workspace root; path
748
+ * reduction is delegated to {@link resolvePath}.
749
+ *
750
+ * @param file - The root-relative declaring file
751
+ * @param target - The relative link destination to resolve
752
+ * @returns The normalized path, retaining every excess leading parent
753
+ *
754
+ * @example
755
+ * ```ts
756
+ * resolveLink('guides/src/guide.md', '../../src/core/helpers.ts') // 'src/core/helpers.ts'
757
+ * resolveLink('index.ts', './root.ts') // 'root.ts'
758
+ * ```
759
+ */
760
+ function resolveLink(file, target) {
761
+ const index = file.lastIndexOf("/");
762
+ return resolvePath(index < 0 ? "." : file.slice(0, index), target);
229
763
  }
230
764
  /**
231
765
  * The first code-span value found by descending an inline node list, following
@@ -386,6 +920,11 @@ var isManifestEntry = recordOf({
386
920
  * `export (async)? (function(\*)?|class|const|interface|type) Name`, deduped
387
921
  * by (kind, name). A generator export (`export function* walk`) scans as kind
388
922
  * `function` — its trailing `*` is stripped before the {@link ExportKind} check.
923
+ * Scanning uses {@link extractSourceLines}, so comment and template payload is
924
+ * excluded while its uninterrupted column-zero head remains required; preserved
925
+ * columns do not grant membership to leading/interrupted comment forms. The population is
926
+ * exactly `type`, `interface`, `const`, `function`, and `class`; `enum` is
927
+ * outside this reflection contract, not forbidden by general package policy.
389
928
  *
390
929
  * @param source - The file's source text
391
930
  * @returns The file's exported symbols, in file order
@@ -399,8 +938,8 @@ var isManifestEntry = recordOf({
399
938
  function exportsFrom(source) {
400
939
  const symbols = [];
401
940
  const seen = /* @__PURE__ */ new Set();
402
- for (const line of source.split(/\r?\n/)) {
403
- const match = line.match(/^export (?:async )?(function\*?|class|const|interface|type) (\w+)/);
941
+ for (const line of extractSourceLines(source)) {
942
+ const match = line.code.match(/^export (?:async )?(function\*?|class|const|interface|type) (\w+)/);
404
943
  const rawKind = match?.[1];
405
944
  const name = match?.[2];
406
945
  const kind = rawKind === void 0 ? void 0 : rawKind.replace(/\*$/, "");
@@ -423,7 +962,10 @@ function exportsFrom(source) {
423
962
  * `const` / `interface` / `type`) — a module-scope `let` or `var` is a
424
963
  * different violation class (AGENTS §1 bans `var`; a bare `let` is not a
425
964
  * declaration kind this scanner's five-kind grammar covers) and is out of
426
- * this check's contract.
965
+ * this check's contract. Scanning uses {@link extractSourceLines}, so comment
966
+ * and template payload is excluded while its uninterrupted column-zero head
967
+ * remains required; preserved columns do not widen membership. `enum` is likewise outside this reflection population, not
968
+ * forbidden by general package policy.
427
969
  *
428
970
  * @param source - The file's source text
429
971
  * @returns The file's hidden (non-exported) symbols, in file order
@@ -437,9 +979,9 @@ function exportsFrom(source) {
437
979
  function hiddenFrom(source) {
438
980
  const symbols = [];
439
981
  const seen = /* @__PURE__ */ new Set();
440
- for (const line of source.split(/\r?\n/)) {
441
- if (line.startsWith("export ")) continue;
442
- const match = line.match(/^(?:async )?(function\*?|class|const|interface|type) (\w+)/);
982
+ for (const line of extractSourceLines(source)) {
983
+ if (line.code.startsWith("export ")) continue;
984
+ const match = line.code.match(/^(?:async )?(function\*?|class|const|interface|type) (\w+)/);
443
985
  const rawKind = match?.[1];
444
986
  const name = match?.[2];
445
987
  const kind = rawKind === void 0 ? void 0 : rawKind.replace(/\*$/, "");
@@ -481,8 +1023,9 @@ function joinHead(lines, start) {
481
1023
  }
482
1024
  /**
483
1025
  * The body lines of the named `export class` / `export interface` declaration
484
- * within one file's source text — everything between the head's opening `{`
485
- * and the column-0 closing `}`.
1026
+ * within one file's source text — everything between a projected real head and
1027
+ * projected column-0 closing `}`. Structural eligibility is projected while the
1028
+ * corresponding returned body lines remain raw for JSDoc evidence.
486
1029
  *
487
1030
  * @param source - The file's source text to search
488
1031
  * @param keyword - Whether to look for a `class` or an `interface`
@@ -497,17 +1040,14 @@ function joinHead(lines, start) {
497
1040
  function declarationBody(source, keyword, name) {
498
1041
  const opener = `export ${keyword} ${name}`;
499
1042
  const declaration = new RegExp(`^export ${keyword} ${name}(?:<.*>)?(?: .*)? \\{$`);
500
- const lines = source.split(/\r?\n/);
501
- for (let index = 0; index < lines.length; index += 1) {
502
- const line = lines[index];
1043
+ const lines = extractSourceLines(source);
1044
+ const projected = lines.map((line) => line.code);
1045
+ for (let index = 0; index < projected.length; index += 1) {
1046
+ const line = projected[index];
503
1047
  if (line === void 0 || !line.startsWith(opener)) continue;
504
- const head = joinHead(lines, index);
1048
+ const head = joinHead(projected, index);
505
1049
  if (head === void 0 || !declaration.test(head.text)) continue;
506
- const body = [];
507
- for (const member of lines.slice(head.end + 1)) {
508
- if (member === "}") return body;
509
- body.push(member);
510
- }
1050
+ for (let close = head.end + 1; close < projected.length; close += 1) if (projected[close] === "}") return lines.slice(head.end + 1, close).map((record) => record.source);
511
1051
  }
512
1052
  return [];
513
1053
  }
@@ -515,7 +1055,8 @@ function declarationBody(source, keyword, name) {
515
1055
  * The member lines declaring a callable member: plain, `async`, generator
516
1056
  * (`*`), and optional (`records?(`) methods all count; getters, setters,
517
1057
  * `static` members, and `#` privates never do (their keyword or `#` breaks
518
- * the `name(` shape).
1058
+ * the `name(` shape). Matching runs once over projected lines so commented
1059
+ * method-like payload never becomes eligible.
519
1060
  *
520
1061
  * @param lines - A declaration's body lines
521
1062
  * @returns The declared method names, deduped and sorted
@@ -527,8 +1068,8 @@ function declarationBody(source, keyword, name) {
527
1068
  */
528
1069
  function memberMethods(lines) {
529
1070
  const methods = [];
530
- for (const line of lines) {
531
- const method = line.match(/^\t(?:async )?\*?(\w+)(<.*>)?\??\(/);
1071
+ for (const line of extractSourceLines(lines.join("\n"))) {
1072
+ const method = line.code.match(/^\t(?:async )?\*?(\w+)(<.*>)?\??\(/);
532
1073
  if (method?.[1] !== void 0) methods.push(method[1]);
533
1074
  }
534
1075
  return Array.from(new Set(methods)).sort();
@@ -695,10 +1236,91 @@ function extractTests(document) {
695
1236
  return links;
696
1237
  }
697
1238
  /**
1239
+ * Select the next physical record after an eligible genuine JSDoc whose final
1240
+ * authoritative span carries an exact block-position `@example` tag. Title
1241
+ * text is allowed. A leading whitespace-separated span chain is last-span
1242
+ * authoritative; intervening source material severs association, while a
1243
+ * leading JSDoc on the next record replaces pending state. Any other next
1244
+ * physical record is returned once and consumes it. This parser walks aligned
1245
+ * records without rescanning source syntax or applying declaration/member
1246
+ * grammar.
1247
+ *
1248
+ * @param lines - Aligned physical source-line records
1249
+ * @returns The immediately following candidate lines, in source order
1250
+ *
1251
+ * @example
1252
+ * ```ts
1253
+ * extractExampleLines(extractSourceLines('/** @example *' + '/\nexport function walk() {}'))
1254
+ * // the `export function walk() {}` SourceLine
1255
+ * ```
1256
+ */
1257
+ function extractExampleLines(lines) {
1258
+ const examples = [];
1259
+ let block = false;
1260
+ let eligible = false;
1261
+ let example = false;
1262
+ let pending = false;
1263
+ for (const line of lines) {
1264
+ const projection = line.jsdoc;
1265
+ const first = projection?.indexOf("/**") ?? -1;
1266
+ if (pending) {
1267
+ if (!block && first >= 0 && line.source.slice(0, first).trim() === "") pending = false;
1268
+ else {
1269
+ examples.push(line);
1270
+ pending = false;
1271
+ }
1272
+ }
1273
+ if (projection === void 0) continue;
1274
+ let cursor = 0;
1275
+ if (block) {
1276
+ const close = projection.indexOf("*/");
1277
+ const end = close < 0 ? projection.length : close + 2;
1278
+ if (eligible && /^\s*\*?\s*@example(?=\s|\*\/|$)/.test(projection.slice(0, end))) example = true;
1279
+ if (close < 0) continue;
1280
+ block = false;
1281
+ const opener = projection.indexOf("/**", close + 2);
1282
+ const endOfGap = opener < 0 ? line.source.length : opener;
1283
+ const whitespace = line.source.slice(close + 2, endOfGap).trim() === "";
1284
+ if (opener < 0) {
1285
+ pending = eligible && example && whitespace;
1286
+ continue;
1287
+ }
1288
+ eligible = eligible && whitespace;
1289
+ example = false;
1290
+ cursor = opener;
1291
+ } else {
1292
+ if (first < 0) continue;
1293
+ eligible = line.source.slice(0, first).trim() === "";
1294
+ example = false;
1295
+ cursor = first;
1296
+ }
1297
+ while (cursor < projection.length) {
1298
+ const close = projection.indexOf("*/", cursor + 2);
1299
+ const end = close < 0 ? projection.length : close + 2;
1300
+ if (eligible && /^\s*\*?\s*@example(?=\s|\*\/|$)/.test(projection.slice(cursor + 3, end))) example = true;
1301
+ if (close < 0) {
1302
+ block = true;
1303
+ break;
1304
+ }
1305
+ const opener = projection.indexOf("/**", close + 2);
1306
+ const endOfGap = opener < 0 ? line.source.length : opener;
1307
+ const whitespace = line.source.slice(close + 2, endOfGap).trim() === "";
1308
+ if (opener < 0) {
1309
+ pending = eligible && example && whitespace;
1310
+ break;
1311
+ }
1312
+ eligible = eligible && whitespace;
1313
+ example = false;
1314
+ cursor = opener;
1315
+ }
1316
+ }
1317
+ return examples;
1318
+ }
1319
+ /**
698
1320
  * The exported functions in one file's source text whose immediately preceding
699
- * JSDoc block carries `@example` — walked line by line, tracking the current
700
- * comment block; the block resets on any non-comment, non-export line so an
701
- * `@example` never attaches to a declaration it does not directly precede.
1321
+ * eligible genuine JSDoc block carries `@example`. Shared adjacency comes from
1322
+ * {@link extractExampleLines}; exported-function membership is matched against
1323
+ * the aligned code projection, so comment and template payload cannot qualify.
702
1324
  *
703
1325
  * @param source - The file's source text
704
1326
  * @returns The exported function names with an `@example`, in file order
@@ -713,42 +1335,21 @@ function extractTests(document) {
713
1335
  function examplesFrom(source) {
714
1336
  const names = [];
715
1337
  const seen = /* @__PURE__ */ new Set();
716
- let inBlock = false;
717
- let blockHasExample = false;
718
- let pending = false;
719
- for (const line of source.split(/\r?\n/)) {
720
- const trimmed = line.trim();
721
- if (!inBlock && trimmed.startsWith("/**")) {
722
- inBlock = true;
723
- blockHasExample = trimmed.includes("@example");
724
- pending = false;
725
- if (trimmed.length > 3 && trimmed.endsWith("*/")) {
726
- inBlock = false;
727
- pending = blockHasExample;
728
- }
729
- continue;
730
- }
731
- if (inBlock) {
732
- if (trimmed.includes("@example")) blockHasExample = true;
733
- if (trimmed.endsWith("*/")) {
734
- inBlock = false;
735
- pending = blockHasExample;
736
- }
737
- continue;
738
- }
739
- const name = line.match(/^export (?:async )?function\*? (\w+)/)?.[1];
740
- if (pending && isNonEmptyString(name) && !seen.has(name)) {
1338
+ for (const line of extractExampleLines(extractSourceLines(source))) {
1339
+ const name = line.code.match(/^export (?:async )?function\*? (\w+)/)?.[1];
1340
+ if (isNonEmptyString(name) && !seen.has(name)) {
741
1341
  seen.add(name);
742
1342
  names.push(name);
743
1343
  }
744
- pending = false;
745
1344
  }
746
1345
  return names;
747
1346
  }
748
1347
  /**
749
1348
  * The callable-member names in a declaration body (per {@link memberMethods}'
750
- * grammar) whose immediately preceding JSDoc block, within the same body,
751
- * carries `@example` — the member-level mirror of {@link examplesFrom}.
1349
+ * grammar) whose immediately preceding eligible genuine JSDoc block, within
1350
+ * the same body, carries `@example`. Shared adjacency comes from
1351
+ * {@link extractExampleLines}; member membership is matched against aligned
1352
+ * projected code.
752
1353
  *
753
1354
  * @param lines - A declaration's body lines
754
1355
  * @returns The exemplified member names, deduped and sorted
@@ -761,35 +1362,12 @@ function examplesFrom(source) {
761
1362
  function exampleMethods(lines) {
762
1363
  const methods = [];
763
1364
  const seen = /* @__PURE__ */ new Set();
764
- let inBlock = false;
765
- let blockHasExample = false;
766
- let pending = false;
767
- for (const line of lines) {
768
- const trimmed = line.trim();
769
- if (!inBlock && trimmed.startsWith("/**")) {
770
- inBlock = true;
771
- blockHasExample = trimmed.includes("@example");
772
- pending = false;
773
- if (trimmed.length > 3 && trimmed.endsWith("*/")) {
774
- inBlock = false;
775
- pending = blockHasExample;
776
- }
777
- continue;
778
- }
779
- if (inBlock) {
780
- if (trimmed.includes("@example")) blockHasExample = true;
781
- if (trimmed.endsWith("*/")) {
782
- inBlock = false;
783
- pending = blockHasExample;
784
- }
785
- continue;
786
- }
787
- const name = line.match(/^\t(?:async )?\*?(\w+)(<.*>)?\??\(/)?.[1];
788
- if (pending && isNonEmptyString(name) && !seen.has(name)) {
1365
+ for (const line of extractExampleLines(extractSourceLines(lines.join("\n")))) {
1366
+ const name = line.code.match(/^\t(?:async )?\*?(\w+)(<.*>)?\??\(/)?.[1];
1367
+ if (isNonEmptyString(name) && !seen.has(name)) {
789
1368
  seen.add(name);
790
1369
  methods.push(name);
791
1370
  }
792
- pending = false;
793
1371
  }
794
1372
  return Array.from(new Set(methods)).sort();
795
1373
  }
@@ -813,15 +1391,14 @@ function extractPatterns(document) {
813
1391
  /**
814
1392
  * Parse a `## By concept` manifest table into its {@link ManifestEntry} rows —
815
1393
  * each row's Concept cell (flattened text), Spec / Tests cells (a single link
816
- * href, resolved against `base`), and Source cell (every link href, resolved
817
- * against `base`; one directory collapses to a `string`, several become a
818
- * `readonly string[]`). A row missing a concept, spec link, tests link, or
1394
+ * href, resolved against `directory`), and Source cell (every link href,
1395
+ * resolved against `directory`; Source links canonicalize through
1396
+ * {@link normalizeDirectories}, one directory collapses to a `string`, and several become
1397
+ * a `readonly string[]`). A row missing a concept, spec link, tests link, or
819
1398
  * source link is skipped as malformed.
820
1399
  *
821
1400
  * @param markdown - The manifest markdown source (e.g. `guides/README.md`'s content)
822
- * @param base - A single directory name relative to the workspace root that the manifest's
823
- * links are resolved against (e.g. `'guides'`) — {@link resolveLink}'s arithmetic supports
824
- * only one path segment, so a deeper or nested base is not supported
1401
+ * @param directory - The root-relative directory containing the manifest
825
1402
  * @returns The manifest's entries, in row order
826
1403
  *
827
1404
  * @example
@@ -829,7 +1406,7 @@ function extractPatterns(document) {
829
1406
  * parseManifest(readme, 'guides') // [{ concept: 'Markdown', spec: 'guides/src/markdown.md', ... }]
830
1407
  * ```
831
1408
  */
832
- function parseManifest(markdown, base) {
1409
+ function parseManifest(markdown, directory) {
833
1410
  const document = createMarkdown(markdown).document;
834
1411
  const entries = [];
835
1412
  for (const block of sectionBlocks(document, MANIFEST)) {
@@ -848,15 +1425,15 @@ function parseManifest(markdown, base) {
848
1425
  const specHref = cellLinks(specCell)[0];
849
1426
  const testsHref = cellLinks(testsCell)[0];
850
1427
  if (specHref === void 0 || testsHref === void 0) continue;
851
- const sourceHrefs = cellLinks(sourceCell).map((href) => resolveLink(base, href));
1428
+ const sourceHrefs = normalizeDirectories(cellLinks(sourceCell).map((href) => resolvePath(directory, href)));
852
1429
  if (!isNonEmptyArray(sourceHrefs)) continue;
853
1430
  const [firstSource] = sourceHrefs;
854
1431
  const source = sourceHrefs.length === 1 ? firstSource : sourceHrefs;
855
1432
  entries.push({
856
1433
  concept,
857
- spec: resolveLink(base, specHref),
1434
+ spec: resolvePath(directory, specHref),
858
1435
  source,
859
- tests: resolveLink(base, testsHref)
1436
+ tests: resolvePath(directory, testsHref)
860
1437
  });
861
1438
  }
862
1439
  }
@@ -871,7 +1448,7 @@ function parseManifest(markdown, base) {
871
1448
  * @example
872
1449
  * ```ts
873
1450
  * import { createContract } from '@orkestrel/contract'
874
- * import { surfaceSymbolShape } from '@orkestrel/guide/core'
1451
+ * import { surfaceSymbolShape } from '@orkestrel/guide'
875
1452
  *
876
1453
  * const surfaceSymbol = createContract(surfaceSymbolShape)
877
1454
  * surfaceSymbol.is({ name: 'Markdown', kind: 'class' }) // true
@@ -894,7 +1471,7 @@ var surfaceSymbolShape = objectShape({
894
1471
  * @example
895
1472
  * ```ts
896
1473
  * import { createContract } from '@orkestrel/contract'
897
- * import { methodGroupShape } from '@orkestrel/guide/core'
1474
+ * import { methodGroupShape } from '@orkestrel/guide'
898
1475
  *
899
1476
  * const methodGroup = createContract(methodGroupShape)
900
1477
  * methodGroup.is({ interface: 'MarkdownInterface', methods: ['walk'] }) // true
@@ -911,7 +1488,7 @@ var methodGroupShape = objectShape({
911
1488
  * @example
912
1489
  * ```ts
913
1490
  * import { createContract } from '@orkestrel/contract'
914
- * import { manifestEntryShape } from '@orkestrel/guide/core'
1491
+ * import { manifestEntryShape } from '@orkestrel/guide'
915
1492
  *
916
1493
  * const manifestEntry = createContract(manifestEntryShape)
917
1494
  * manifestEntry.is({ concept: 'Markdown', spec: 'guides/src/markdown.md', source: 'src/core', tests: 'tests/src/core' }) // true
@@ -926,9 +1503,9 @@ var manifestEntryShape = objectShape({
926
1503
  //#endregion
927
1504
  //#region src/core/Guide.ts
928
1505
  /**
929
- * A stateful, structured view over one parsed guide — the five documented
930
- * projections (`sections` / `surface` / `methods` / `links` / `tests`) are
931
- * extracted once at construction and cached.
1506
+ * A stateful, structured view over one parsed guide — the six documented
1507
+ * projections (`sections` / `surface` / `methods` / `links` / `tests` /
1508
+ * `patterns`) are extracted once at construction and cached.
932
1509
  *
933
1510
  * @remarks
934
1511
  * Pure: parses `source` once via `@orkestrel/markdown` and never touches the
@@ -938,7 +1515,7 @@ var manifestEntryShape = objectShape({
938
1515
  *
939
1516
  * @example
940
1517
  * ```ts
941
- * import { Guide } from '@orkestrel/guide/core'
1518
+ * import { Guide } from '@orkestrel/guide'
942
1519
  *
943
1520
  * const guide = new Guide('## Surface\n\n| Name | Kind |\n| --- | --- |\n| `X` | class |')
944
1521
  * guide.surface() // [{ name: 'X', kind: 'class' }]
@@ -982,12 +1559,25 @@ var Guide = class {
982
1559
  //#endregion
983
1560
  //#region src/core/Source.ts
984
1561
  /**
985
- * A pure `SourceInterface` — reflects a module scope's exports and member
986
- * methods over a consumer-supplied file inventory (AGENTS §22, `PROPOSAL.md`
987
- * §7), using text-only line scanners rather than the TypeScript compiler API
988
- * or the filesystem. `Source` never touches disk: the consumer gathers the
989
- * inventory however their environment allows (`node:fs` in a Node script,
990
- * `import.meta.glob` in a browser/vitest run) and passes it in as `files`.
1562
+ * A pure `SourceInterface` — reflects a module scope's intentional direct
1563
+ * declarations, conventional barrel-reachable surface, and member methods over
1564
+ * a consumer-supplied file inventory, using text-only line scanners rather than
1565
+ * the TypeScript compiler API or the filesystem. `Source` never touches disk:
1566
+ * the consumer gathers the inventory however their environment allows
1567
+ * (`node:fs` in a Node script, `import.meta.glob` in a browser/vitest run) and
1568
+ * passes it in as `files`. Conventional barrel traversal recurses through both
1569
+ * exact workspace-root `index.ts` and nested `/index.ts` targets. `'.'` is the
1570
+ * canonical workspace-root module, module spellings normalize once at
1571
+ * construction, and exact opaque inventory keys are never rewritten; keys with
1572
+ * empty, `.` or `..` segments stay outside both initial and resolved barrel
1573
+ * inventory entrances after relative-row reduction; canonical parent hops
1574
+ * remain valid. Source projection preserves columns without widening
1575
+ * direct/hidden column-zero heads. Literal ECMAScript Unicode identifiers
1576
+ * participate in bounded slash-state recognition without escape decoding.
1577
+ * Regex recognition is bounded: slash after bare `}` is division, so a
1578
+ * post-brace regex statement requires an explicit `;`. General semicolonless
1579
+ * declaration/ASI classification is also outside the finite projector, so a
1580
+ * slash-leading statement after such a declaration requires an explicit `;`.
991
1581
  *
992
1582
  * @example
993
1583
  * ```ts
@@ -995,30 +1585,37 @@ var Guide = class {
995
1585
  *
996
1586
  * const source = new Source({
997
1587
  * files: {
1588
+ * 'src/core/index.ts': "export * from './Guide.js'\nexport * from './types.js'\n",
998
1589
  * 'src/core/Guide.ts': 'export class Guide {}\n',
999
1590
  * 'src/core/types.ts': 'export interface GuideInterface {\n\tsections(): void\n}\n',
1000
1591
  * },
1001
1592
  * module: 'src/core',
1002
1593
  * })
1003
1594
  * source.exports() // [{ name: 'Guide', kind: 'class' }, { name: 'GuideInterface', kind: 'interface' }]
1595
+ * source.surface() // [{ name: 'Guide', kind: 'class' }, { name: 'GuideInterface', kind: 'interface' }]
1004
1596
  * source.methods('GuideInterface') // ['sections']
1005
1597
  * source.exists('src/core/Guide.ts') // true
1006
1598
  * ```
1007
1599
  */
1008
1600
  var Source = class {
1009
1601
  #files;
1010
- #module;
1602
+ #directories;
1011
1603
  #exports;
1604
+ #surface;
1012
1605
  #hidden;
1013
1606
  #examples;
1014
1607
  constructor(options) {
1015
1608
  this.#files = options.files;
1016
- this.#module = options.module;
1609
+ this.#directories = normalizeDirectories(options.module);
1017
1610
  }
1018
1611
  exports() {
1019
1612
  if (this.#exports === void 0) this.#exports = this.#scanSymbols(exportsFrom);
1020
1613
  return this.#exports;
1021
1614
  }
1615
+ surface() {
1616
+ if (this.#surface === void 0) this.#surface = this.#scanSurface();
1617
+ return this.#surface;
1618
+ }
1022
1619
  methods(name) {
1023
1620
  const interfaceBody = this.#declarationBody("interface", name);
1024
1621
  if (interfaceBody.length > 0) return memberMethods(interfaceBody);
@@ -1041,7 +1638,7 @@ var Source = class {
1041
1638
  #scanExamples() {
1042
1639
  const names = [];
1043
1640
  const seen = /* @__PURE__ */ new Set();
1044
- for (const key of moduleKeys(this.#files, this.#module)) {
1641
+ for (const key of selectModuleKeys(this.#files, this.#directories)) {
1045
1642
  const text = this.#files[key];
1046
1643
  if (text === void 0) continue;
1047
1644
  for (const name of examplesFrom(text)) {
@@ -1052,6 +1649,41 @@ var Source = class {
1052
1649
  }
1053
1650
  return names;
1054
1651
  }
1652
+ #scanSurface() {
1653
+ const symbols = [];
1654
+ const seen = /* @__PURE__ */ new Set();
1655
+ const visited = /* @__PURE__ */ new Set();
1656
+ for (const directory of this.#directories) this.#collectSurface(resolvePath(directory, "index.ts"), visited, symbols, seen);
1657
+ return symbols.sort((a, b) => a.name === b.name ? 0 : a.name < b.name ? -1 : 1);
1658
+ }
1659
+ #collectSurface(index, visited, symbols, seen) {
1660
+ if (!hasCanonicalSegments(index)) return;
1661
+ if (visited.has(index)) return;
1662
+ visited.add(index);
1663
+ const source = this.#files[index];
1664
+ if (source === void 0) return;
1665
+ for (const line of extractSourceLines(source)) {
1666
+ const row = line.code.match(/^\s*export\s+\*\s+from\s+(?:'(\.\.?\/[^']+\.js)'|"(\.\.?\/[^"]+\.js)")\s*;?\s*(?:\/\/.*)?$/);
1667
+ const target = row?.[1] ?? row?.[2];
1668
+ if (target === void 0) continue;
1669
+ const path = resolveLink(index, `${target.slice(0, -3)}.ts`);
1670
+ if (!hasCanonicalSegments(path)) continue;
1671
+ if (path === "index.ts" || path.endsWith("/index.ts")) {
1672
+ this.#collectSurface(path, visited, symbols, seen);
1673
+ continue;
1674
+ }
1675
+ if (visited.has(path)) continue;
1676
+ visited.add(path);
1677
+ const text = this.#files[path];
1678
+ if (text === void 0) continue;
1679
+ for (const symbol of exportsFrom(text)) {
1680
+ const identity = symbolKey(symbol);
1681
+ if (seen.has(identity)) continue;
1682
+ seen.add(identity);
1683
+ symbols.push(symbol);
1684
+ }
1685
+ }
1686
+ }
1055
1687
  #exampleMembers(name) {
1056
1688
  const interfaceBody = this.#declarationBody("interface", name);
1057
1689
  const classBody = this.#declarationBody("class", name);
@@ -1061,7 +1693,7 @@ var Source = class {
1061
1693
  #scanSymbols(scan) {
1062
1694
  const symbols = [];
1063
1695
  const seen = /* @__PURE__ */ new Set();
1064
- for (const key of moduleKeys(this.#files, this.#module)) {
1696
+ for (const key of selectModuleKeys(this.#files, this.#directories)) {
1065
1697
  const text = this.#files[key];
1066
1698
  if (text === void 0) continue;
1067
1699
  for (const symbol of scan(text)) {
@@ -1074,7 +1706,7 @@ var Source = class {
1074
1706
  return symbols.sort((a, b) => a.name === b.name ? 0 : a.name < b.name ? -1 : 1);
1075
1707
  }
1076
1708
  #declarationBody(keyword, name) {
1077
- for (const key of moduleKeys(this.#files, this.#module)) {
1709
+ for (const key of selectModuleKeys(this.#files, this.#directories)) {
1078
1710
  const text = this.#files[key];
1079
1711
  if (text === void 0) continue;
1080
1712
  const body = declarationBody(text, keyword, name);
@@ -1088,7 +1720,7 @@ var Source = class {
1088
1720
  /**
1089
1721
  * Create a structured {@link GuideInterface} view over one guide's markdown
1090
1722
  * source — parses once and caches its `sections` / `surface` / `methods` /
1091
- * `links` / `tests` projections.
1723
+ * `links` / `tests` / `patterns` projections.
1092
1724
  *
1093
1725
  * @param source - The guide's markdown source text
1094
1726
  * @returns A working {@link GuideInterface}
@@ -1134,7 +1766,7 @@ function createSource(options) {
1134
1766
  *
1135
1767
  * @example
1136
1768
  * ```ts
1137
- * import { createSurfaceSymbolContract } from '@orkestrel/guide/core'
1769
+ * import { createSurfaceSymbolContract } from '@orkestrel/guide'
1138
1770
  *
1139
1771
  * const surfaceSymbol = createSurfaceSymbolContract()
1140
1772
  * surfaceSymbol.is({ name: 'Markdown', kind: 'class' }) // true
@@ -1152,7 +1784,7 @@ function createSurfaceSymbolContract() {
1152
1784
  *
1153
1785
  * @example
1154
1786
  * ```ts
1155
- * import { createMethodGroupContract } from '@orkestrel/guide/core'
1787
+ * import { createMethodGroupContract } from '@orkestrel/guide'
1156
1788
  *
1157
1789
  * const methodGroup = createMethodGroupContract()
1158
1790
  * methodGroup.is({ interface: 'MarkdownInterface', methods: ['walk'] }) // true
@@ -1170,7 +1802,7 @@ function createMethodGroupContract() {
1170
1802
  *
1171
1803
  * @example
1172
1804
  * ```ts
1173
- * import { createManifestEntryContract } from '@orkestrel/guide/core'
1805
+ * import { createManifestEntryContract } from '@orkestrel/guide'
1174
1806
  *
1175
1807
  * const manifestEntry = createManifestEntryContract()
1176
1808
  * manifestEntry.is({ concept: 'Markdown', spec: 'guides/src/markdown.md', source: 'src/core', tests: 'tests/src/core' }) // true
@@ -1180,6 +1812,6 @@ function createManifestEntryContract() {
1180
1812
  return createContract(manifestEntryShape);
1181
1813
  }
1182
1814
  //#endregion
1183
- export { EXTERNAL_SCHEMES, Guide, MANIFEST, METHODS, SURFACE, Source, TESTS, cellLinks, createGuide, createManifestEntryContract, createMethodGroupContract, createSource, createSurfaceSymbolContract, declarationBody, exampleMethods, examplesFrom, exportsFrom, extractLinks, extractMethods, extractPatterns, extractSurface, extractTests, fenceImports, findMissing, findUnexampled, firstCode, hiddenFrom, identifierOf, isExportKind, isExternalLink, isManifestEntry, isMethodGroup, isSurfaceSymbol, joinHead, kindIndex, manifestEntryShape, memberMethods, methodGroupShape, missingSymbols, moduleDirs, moduleKeys, parseManifest, resolveLink, sectionBlocks, surfaceSymbolShape, symbolKey };
1815
+ export { EXTERNAL_SCHEMES, Guide, MANIFEST, METHODS, SURFACE, Source, TESTS, cellLinks, createGuide, createManifestEntryContract, createMethodGroupContract, createSource, createSurfaceSymbolContract, declarationBody, exampleMethods, examplesFrom, exportsFrom, extractExampleLines, extractLinks, extractMethods, extractPatterns, extractSourceLines, extractSurface, extractTests, fenceImports, findMissing, findUnexampled, firstCode, hasCanonicalSegments, hiddenFrom, identifierOf, isExportKind, isExternalLink, isManifestEntry, isMethodGroup, isSurfaceSymbol, joinHead, kindIndex, manifestEntryShape, memberMethods, methodGroupShape, missingSymbols, normalizeDirectories, parseManifest, resolveLink, resolvePath, sectionBlocks, selectModuleKeys, surfaceSymbolShape, symbolKey };
1184
1816
 
1185
1817
  //# sourceMappingURL=index.js.map