@orkestrel/guide 0.0.8 → 0.0.10

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