@nowline/core 0.10.0 → 0.12.0

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.
Files changed (66) hide show
  1. package/dist/diagnostics/index.d.ts +14 -1
  2. package/dist/diagnostics/index.d.ts.map +1 -1
  3. package/dist/diagnostics/index.js +35 -1
  4. package/dist/diagnostics/index.js.map +1 -1
  5. package/dist/i18n/codes.d.ts +1 -1
  6. package/dist/i18n/codes.d.ts.map +1 -1
  7. package/dist/i18n/codes.js +8 -0
  8. package/dist/i18n/codes.js.map +1 -1
  9. package/dist/i18n/include-message-types.d.ts +23 -0
  10. package/dist/i18n/include-message-types.d.ts.map +1 -0
  11. package/dist/i18n/include-message-types.js +5 -0
  12. package/dist/i18n/include-message-types.js.map +1 -0
  13. package/dist/i18n/index.d.ts +1 -0
  14. package/dist/i18n/index.d.ts.map +1 -1
  15. package/dist/i18n/index.js.map +1 -1
  16. package/dist/i18n/messages.en.d.ts +21 -0
  17. package/dist/i18n/messages.en.d.ts.map +1 -1
  18. package/dist/i18n/messages.en.js +40 -0
  19. package/dist/i18n/messages.en.js.map +1 -1
  20. package/dist/i18n/messages.fr.d.ts.map +1 -1
  21. package/dist/i18n/messages.fr.js +40 -0
  22. package/dist/i18n/messages.fr.js.map +1 -1
  23. package/dist/index.d.ts +3 -2
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +2 -2
  26. package/dist/index.js.map +1 -1
  27. package/dist/language/include-resolver.d.ts +36 -6
  28. package/dist/language/include-resolver.d.ts.map +1 -1
  29. package/dist/language/include-resolver.js +123 -51
  30. package/dist/language/include-resolver.js.map +1 -1
  31. package/dist/language/include-swimlanes.d.ts +16 -0
  32. package/dist/language/include-swimlanes.d.ts.map +1 -0
  33. package/dist/language/include-swimlanes.js +48 -0
  34. package/dist/language/include-swimlanes.js.map +1 -0
  35. package/dist/language/include-waves.d.ts +2 -2
  36. package/dist/language/include-waves.d.ts.map +1 -1
  37. package/dist/language/include-waves.js +3 -3
  38. package/dist/language/include-waves.js.map +1 -1
  39. package/dist/language/validator/properties.js +3 -3
  40. package/dist/language/validator/properties.js.map +1 -1
  41. package/dist/language/validator/structure.d.ts.map +1 -1
  42. package/dist/language/validator/structure.js +5 -0
  43. package/dist/language/validator/structure.js.map +1 -1
  44. package/dist/util/node-read-file.d.ts +1 -0
  45. package/dist/util/node-read-file.d.ts.map +1 -1
  46. package/dist/util/node-read-file.js +4 -0
  47. package/dist/util/node-read-file.js.map +1 -1
  48. package/dist/util/posix-path.d.ts +5 -0
  49. package/dist/util/posix-path.d.ts.map +1 -1
  50. package/dist/util/posix-path.js +27 -3
  51. package/dist/util/posix-path.js.map +1 -1
  52. package/package.json +1 -1
  53. package/src/diagnostics/index.ts +42 -1
  54. package/src/i18n/codes.ts +16 -0
  55. package/src/i18n/include-message-types.ts +22 -0
  56. package/src/i18n/index.ts +1 -0
  57. package/src/i18n/messages.en.ts +45 -0
  58. package/src/i18n/messages.fr.ts +46 -0
  59. package/src/index.ts +4 -0
  60. package/src/language/include-resolver.ts +171 -60
  61. package/src/language/include-swimlanes.ts +59 -0
  62. package/src/language/include-waves.ts +3 -7
  63. package/src/language/validator/properties.ts +3 -3
  64. package/src/language/validator/structure.ts +4 -0
  65. package/src/util/node-read-file.ts +5 -0
  66. package/src/util/posix-path.ts +28 -3
@@ -44,12 +44,23 @@ import {
44
44
  isWorkingDeclaration,
45
45
  } from '../generated/ast.js';
46
46
  import type { MessageCode } from '../i18n/codes.js';
47
- import { basename, dirname, resolve as resolvePath } from '../util/posix-path.js';
47
+ import type { E0203Args, E0208Args } from '../i18n/include-message-types.js';
48
+ import { type MessageArgs, tr } from '../i18n/index.js';
49
+ import {
50
+ basename,
51
+ dirname,
52
+ isAbsolute,
53
+ isWithin,
54
+ relative,
55
+ resolve as resolvePath,
56
+ } from '../util/posix-path.js';
48
57
  import { isRealIsoDate } from '../util/props.js';
49
58
  import { checkIncludedReferences } from './include-references.js';
59
+ import { checkMergedSwimlanes } from './include-swimlanes.js';
50
60
  import {
51
61
  checkWaveAgreement,
52
62
  hasParseErrors,
63
+ nodeLocation,
53
64
  participates,
54
65
  runResolverWaveChecks,
55
66
  type WaveIncludeEdge,
@@ -68,20 +79,6 @@ function readStartProp(decl: RoadmapDeclaration | undefined): string | undefined
68
79
  return prop.value;
69
80
  }
70
81
 
71
- function formatStartMismatch(
72
- childRelPath: string,
73
- parentStart: string | undefined,
74
- childStart: string | undefined,
75
- ): string {
76
- if (parentStart && childStart) {
77
- return `Included "${childRelPath}" declares start:${childStart}, which doesn't match this file's start:${parentStart}. Both files must declare the same start date, or neither should.`;
78
- }
79
- if (parentStart) {
80
- return `Included "${childRelPath}" has no start:, but this file declares start:${parentStart}. Both files must declare the same start date, or neither should.`;
81
- }
82
- return `Included "${childRelPath}" declares start:${childStart}, but this file has no start:. Both files must declare the same start date, or neither should.`;
83
- }
84
-
85
82
  export interface ResolvedConfig {
86
83
  scale?: ScaleBlock;
87
84
  calendar?: CalendarBlock;
@@ -160,9 +157,11 @@ export interface ResolveDiagnostic {
160
157
  */
161
158
  range?: ResolveRange;
162
159
  /**
163
- * Stable code of a coded diagnostic (the wave rules, specs/waves.md
164
- * §7.4, and an included file's unresolved reference, NL.E0302). Absent
165
- * on every other resolver diagnostic.
160
+ * Stable code of a coded diagnostic: every include error (NL.E0203 to
161
+ * NL.E0210), the wave rules (specs/waves.md §7.4), an included
162
+ * file's unresolved reference (NL.E0302), and a root whose merged result
163
+ * has no swimlane (NL.E0004). Absent on the shadow
164
+ * warnings, an included file's syntax error, and WV8.
166
165
  */
167
166
  code?: MessageCode;
168
167
  /** The message arguments as a rest tuple, as `acceptTr` stores them. */
@@ -188,9 +187,9 @@ export type IncludedSyntaxError = Extract<RawDiagnostic, { origin: 'lexer' | 'pa
188
187
 
189
188
  /**
190
189
  * True for a resolver diagnostic that consumers report like a validator
191
- * diagnostic (file, line, localized, exit 1): a coded one (the wave rules and
192
- * NL.E0302), one from the wave checks, or an included file's syntax error.
193
- * Every other resolver diagnostic keeps the include-error path
190
+ * diagnostic (file, line, localized, exit 1): a coded one (every include
191
+ * error, the wave rules, NL.E0302 and NL.E0004), one from the wave checks, or an
192
+ * included file's syntax error. What is left is the uncoded shadow warnings
194
193
  * (specs/waves.md §6.1).
195
194
  */
196
195
  export function isRoutedResolveDiagnostic(d: ResolveDiagnostic): boolean {
@@ -208,6 +207,11 @@ interface ResolveContext {
208
207
  services: NowlineServices;
209
208
  /** Absolute path of the root file, whose syntax errors the validator reports. */
210
209
  rootAbs: string;
210
+ policy?: IncludePolicy;
211
+ /** Resolves symlinks under a `rooted` policy. */
212
+ realPath: (absPath: string) => Promise<string>;
213
+ /** What a circular include's chain is shown relative to. */
214
+ displayBase: string;
211
215
  diagnostics: ResolveDiagnostic[];
212
216
  resolving: string[];
213
217
  processed: Map<string, { config: ResolvedConfig; content: ResolvedContent }>;
@@ -216,8 +220,6 @@ interface ResolveContext {
216
220
  files: Map<NowlineFile, string>;
217
221
  /** Include edges whose child was read, per including file, in include order. */
218
222
  edges: Map<string, WaveIncludeEdge[]>;
219
- /** Contents returned for a circular include (they never participate). */
220
- stubs: Set<ResolvedContent>;
221
223
  /** Children that failed include rule 12 (NL.E0202). */
222
224
  failedWaves: Set<string>;
223
225
  }
@@ -246,9 +248,33 @@ function emptyContent(): ResolvedContent {
246
248
  };
247
249
  }
248
250
 
251
+ /**
252
+ * How deep an include chain may go: the root's includes are depth 1. A
253
+ * deeper include is NL.E0210 and is not read, so a chain the cycle check
254
+ * cannot see (a symlinked directory that contains itself) still ends.
255
+ */
256
+ export const MAX_INCLUDE_DEPTH = 16;
257
+
258
+ /**
259
+ * Where includes may be read from (specs/dsl.md, Include rules 14 and 15).
260
+ * Omitted: anywhere the reader reaches, relative to the including file.
261
+ */
262
+ export type IncludePolicy =
263
+ /** Every include is NL.E0209 on its line, and nothing is read. */
264
+ | { kind: 'disabled' }
265
+ /**
266
+ * Every include, at any depth, must be a relative path that resolves,
267
+ * symlinks followed, to a `.nowline` file inside `root`; anything else
268
+ * is NL.E0208 on its line and is not read. `root` and the root file's
269
+ * path must be absolute real paths (symlinks already resolved).
270
+ * `realPath` resolves symlinks; Node's `fs.realpath` by default.
271
+ */
272
+ | { kind: 'rooted'; root: string; realPath?: (absPath: string) => Promise<string> };
273
+
249
274
  export interface ResolveIncludesOptions {
250
275
  services: NowlineServices;
251
276
  readFile?: (absPath: string) => Promise<string>;
277
+ includePolicy?: IncludePolicy;
252
278
  }
253
279
 
254
280
  export async function resolveIncludes(
@@ -265,17 +291,26 @@ export async function resolveIncludes(
265
291
  const { nodeReadFile } = await import('../util/node-read-file.js');
266
292
  return nodeReadFile(p);
267
293
  });
294
+ const policy = options.includePolicy;
295
+ const realPath =
296
+ (policy?.kind === 'rooted' ? policy.realPath : undefined) ??
297
+ (async (p: string) => {
298
+ const { nodeRealPath } = await import('../util/node-read-file.js');
299
+ return nodeRealPath(p);
300
+ });
268
301
  const absPath = resolvePath('', filePath);
269
302
  const ctx: ResolveContext = {
270
303
  services: options.services,
271
304
  rootAbs: absPath,
305
+ policy,
306
+ realPath,
307
+ displayBase: policy?.kind === 'rooted' ? policy.root : dirname(absPath),
272
308
  diagnostics: [],
273
309
  resolving: [],
274
310
  processed: new Map(),
275
311
  readFile,
276
312
  files: new Map(),
277
313
  edges: new Map(),
278
- stubs: new Set(),
279
314
  failedWaves: new Set(),
280
315
  };
281
316
  const { config, content } = await resolveFile(file, absPath, ctx);
@@ -293,6 +328,9 @@ export async function resolveIncludes(
293
328
  // References never cross a file boundary; report each included file's
294
329
  // unresolved ones in that file (an included file is never validated).
295
330
  ctx.diagnostics.push(...checkIncludedReferences(absPath, ctx.edges));
331
+ // Structural rule 6 holds for the merged result, isolated regions included;
332
+ // the validator defers it here for a file whose includes can add a swimlane.
333
+ ctx.diagnostics.push(...checkMergedSwimlanes(file, absPath, content, ctx.diagnostics));
296
334
  return {
297
335
  config,
298
336
  content,
@@ -309,17 +347,6 @@ async function resolveFile(
309
347
  if (ctx.processed.has(absPath)) {
310
348
  return ctx.processed.get(absPath)!;
311
349
  }
312
- if (ctx.resolving.includes(absPath)) {
313
- ctx.diagnostics.push({
314
- severity: 'error',
315
- message: `Circular include detected: ${[...ctx.resolving, absPath].join(' → ')}`,
316
- sourcePath: absPath,
317
- });
318
- const empty = { config: emptyConfig(), content: emptyContent() };
319
- ctx.stubs.add(empty.content);
320
- ctx.processed.set(absPath, empty);
321
- return empty;
322
- }
323
350
 
324
351
  // Each included file once, in every include mode: a `roadmap:ignore`
325
352
  // child's config is still merged (Include rule 13).
@@ -347,19 +374,52 @@ async function resolveFile(
347
374
  const seenIncludes = new Set<string>();
348
375
  for (const inc of file.includes) {
349
376
  const childRelPath = inc.path;
350
- const childAbsPath = resolvePath(dirname(absPath), childRelPath);
377
+ // Every include error is coded, at the path on the include line.
378
+ const fail = <K extends MessageCode>(code: K, ...args: MessageArgs<K>): void => {
379
+ ctx.diagnostics.push(includeError(absPath, inc, code, ...args));
380
+ };
381
+
382
+ if (ctx.policy?.kind === 'disabled') {
383
+ fail('NL.E0209', { path: childRelPath });
384
+ continue;
385
+ }
386
+ const located = await locateInclude(absPath, childRelPath, ctx);
387
+ if ('refused' in located) {
388
+ fail('NL.E0208', located.refused);
389
+ continue;
390
+ }
391
+ if ('unreadable' in located) {
392
+ fail('NL.E0203', located.unreadable);
393
+ continue;
394
+ }
395
+ const childAbsPath = located.absPath;
351
396
 
352
397
  if (seenIncludes.has(childAbsPath)) {
353
- ctx.diagnostics.push({
354
- severity: 'error',
355
- message: `Duplicate include "${childRelPath}" in ${basename(absPath)}.`,
356
- sourcePath: absPath,
357
- line: inc.$cstNode?.range.start.line,
358
- });
398
+ fail('NL.E0205', { path: childRelPath });
359
399
  continue;
360
400
  }
361
401
  seenIncludes.add(childAbsPath);
362
402
 
403
+ // Caught before the child is read, so a cycle reads nothing twice.
404
+ const cycleStart = ctx.resolving.indexOf(childAbsPath);
405
+ if (cycleStart >= 0) {
406
+ const chain = [...ctx.resolving.slice(cycleStart), childAbsPath]
407
+ .map((p) => relative(ctx.displayBase, p))
408
+ .join(' → ');
409
+ fail('NL.E0204', { path: childRelPath, chain });
410
+ continue;
411
+ }
412
+ // `resolving` holds the chain down to this file, the root included,
413
+ // so its length is the child's depth.
414
+ if (ctx.resolving.length > MAX_INCLUDE_DEPTH) {
415
+ fail('NL.E0210', { path: childRelPath, max: MAX_INCLUDE_DEPTH });
416
+ continue;
417
+ }
418
+ if (!childAbsPath.endsWith('.nowline')) {
419
+ fail('NL.E0203', { reason: 'not-nowline', path: childRelPath });
420
+ continue;
421
+ }
422
+
363
423
  const configMode = getIncludeMode(inc, 'config') ?? 'merge';
364
424
  const roadmapMode = getIncludeMode(inc, 'roadmap') ?? 'merge';
365
425
 
@@ -368,12 +428,7 @@ async function resolveFile(
368
428
  const text = await ctx.readFile(childAbsPath);
369
429
  childFile = await parseString(ctx.services, text, childAbsPath);
370
430
  } catch (err) {
371
- ctx.diagnostics.push({
372
- severity: 'error',
373
- message: `Could not read include "${childRelPath}": ${(err as Error).message}`,
374
- sourcePath: absPath,
375
- line: inc.$cstNode?.range.start.line,
376
- });
431
+ fail('NL.E0203', unreadableArgs(childRelPath, err));
377
432
  continue;
378
433
  }
379
434
 
@@ -390,7 +445,7 @@ async function resolveFile(
390
445
  mode: roadmapMode,
391
446
  childFile,
392
447
  childContent,
393
- participates: participates(childFile, childContent, ctx.stubs.has(childContent)),
448
+ participates: participates(childFile, childContent),
394
449
  });
395
450
 
396
451
  applyConfigMode(config, childConfig, configMode, childAbsPath, ctx.diagnostics);
@@ -409,12 +464,7 @@ async function resolveFile(
409
464
  const isParsed = !hasParseErrors(childFile);
410
465
 
411
466
  if (isParsed && roadmapMode === 'isolate' && !childContent.roadmap) {
412
- ctx.diagnostics.push({
413
- severity: 'error',
414
- message: `Cannot isolate "${childRelPath}": it has no roadmap declaration.`,
415
- sourcePath: absPath,
416
- line: inc.$cstNode?.range.start.line,
417
- });
467
+ fail('NL.E0206', { path: childRelPath });
418
468
  }
419
469
 
420
470
  // Non-ignored includes with a child roadmap must agree on start: with the parent.
@@ -424,11 +474,10 @@ async function resolveFile(
424
474
  const parentStart = readStartProp(file.roadmapDecl);
425
475
  const childStart = readStartProp(childFile.roadmapDecl);
426
476
  if (parentStart !== childStart) {
427
- ctx.diagnostics.push({
428
- severity: 'error',
429
- message: formatStartMismatch(childRelPath, parentStart, childStart),
430
- sourcePath: absPath,
431
- line: inc.$cstNode?.range.start.line,
477
+ fail('NL.E0207', {
478
+ path: childRelPath,
479
+ ...(parentStart ? { parentStart } : {}),
480
+ ...(childStart ? { childStart } : {}),
432
481
  });
433
482
  }
434
483
  }
@@ -450,6 +499,68 @@ async function resolveFile(
450
499
  return result;
451
500
  }
452
501
 
502
+ /** A coded include error at `inc`'s path, in the including file. */
503
+ function includeError<K extends MessageCode>(
504
+ sourcePath: string,
505
+ inc: IncludeDeclaration,
506
+ code: K,
507
+ ...args: MessageArgs<K>
508
+ ): ResolveDiagnostic {
509
+ return {
510
+ severity: 'error',
511
+ message: tr('en-US', code, ...args),
512
+ sourcePath,
513
+ ...nodeLocation(inc, 'path'),
514
+ code,
515
+ args,
516
+ };
517
+ }
518
+
519
+ type IncludeLocation = { absPath: string } | { refused: E0208Args } | { unreadable: E0203Args };
520
+
521
+ /**
522
+ * Where `include "<path>"` in `parentAbs` reads from, under the policy.
523
+ * Unrooted: the path resolved against the parent's directory, as written.
524
+ * Rooted: an absolute path, or one that leaves the root before or after
525
+ * symlinks are resolved, is refused; otherwise the real path, so a file
526
+ * reached through two spellings is one file. Nothing is read here.
527
+ */
528
+ async function locateInclude(
529
+ parentAbs: string,
530
+ path: string,
531
+ ctx: ResolveContext,
532
+ ): Promise<IncludeLocation> {
533
+ const policy = ctx.policy;
534
+ if (policy?.kind !== 'rooted') return { absPath: resolvePath(dirname(parentAbs), path) };
535
+ if (isAbsolute(path)) return { refused: { reason: 'absolute', path } };
536
+ const lexical = resolvePath(dirname(parentAbs), path);
537
+ if (!isWithin(policy.root, lexical)) return { refused: { reason: 'parent', path } };
538
+ let real: string;
539
+ try {
540
+ real = await ctx.realPath(lexical);
541
+ } catch (err) {
542
+ return { unreadable: unreadableArgs(path, err) };
543
+ }
544
+ if (!isWithin(policy.root, real)) return { refused: { reason: 'symlink', path } };
545
+ return { absPath: real };
546
+ }
547
+
548
+ /** NL.E0203's reason for a failed read; the OS error's text only when no reason fits. */
549
+ function unreadableArgs(path: string, err: unknown): E0203Args {
550
+ switch ((err as { code?: unknown } | undefined)?.code) {
551
+ case 'ENOENT':
552
+ case 'ENOTDIR':
553
+ return { reason: 'not-found', path };
554
+ case 'EISDIR':
555
+ return { reason: 'is-directory', path };
556
+ case 'EACCES':
557
+ case 'EPERM':
558
+ return { reason: 'permission-denied', path };
559
+ }
560
+ const detail = err instanceof Error ? err.message : undefined;
561
+ return { reason: 'unreadable', path, ...(detail ? { detail } : {}) };
562
+ }
563
+
453
564
  /**
454
565
  * An included file's lexer and parser errors, at their line in that file.
455
566
  * An included file is parsed without validation, so nothing else reports
@@ -0,0 +1,59 @@
1
+ // At least one swimlane in the merged result (specs/dsl.md, Structural rule
2
+ // 6, NL.E0004). The validator reads only its own file, so it can decide the
3
+ // rule only for a file whose includes can't add a swimlane: one with none,
4
+ // or with only `roadmap:ignore` ones. For any other file it defers, and the
5
+ // include resolver calls `checkMergedSwimlanes` once per root pipeline,
6
+ // after every include is resolved.
7
+
8
+ import type { NowlineFile } from '../generated/ast.js';
9
+ import { tr } from '../i18n/index.js';
10
+ import type { ResolveDiagnostic, ResolvedContent } from './include-resolver.js';
11
+ import { nodeLocation } from './include-waves.js';
12
+
13
+ /**
14
+ * True when `file` has an include that can add a swimlane to what renders:
15
+ * any include not marked `roadmap:ignore`. An invalid `roadmap:` value is
16
+ * NL.E0200 and resolves as `merge`, so it counts.
17
+ */
18
+ export function swimlaneRuleNeedsIncludes(file: NowlineFile): boolean {
19
+ return file.includes.some(
20
+ (inc) => inc.options.find((o) => o.key === 'roadmap')?.value !== 'ignore',
21
+ );
22
+ }
23
+
24
+ /** A swimlane in the merged content or in any isolated region it renders. */
25
+ function rendersSwimlane(content: ResolvedContent): boolean {
26
+ return (
27
+ content.swimlanes.size > 0 ||
28
+ content.isolatedRegions.some((r) => rendersSwimlane(r.content))
29
+ );
30
+ }
31
+
32
+ /**
33
+ * NL.E0004 at the root's `roadmap` declaration when the validator deferred
34
+ * the rule and nothing resolved adds a swimlane, merged or isolated. Silent
35
+ * when the resolver already reported an error: an include that could not be
36
+ * read, or one that failed to parse, may be the one that holds the swimlane.
37
+ */
38
+ export function checkMergedSwimlanes(
39
+ rootFile: NowlineFile,
40
+ rootAbs: string,
41
+ rootContent: ResolvedContent,
42
+ diagnostics: readonly ResolveDiagnostic[],
43
+ ): ResolveDiagnostic[] {
44
+ const roadmap = rootFile.roadmapDecl;
45
+ if (!roadmap || !swimlaneRuleNeedsIncludes(rootFile)) return [];
46
+ if (diagnostics.some((d) => d.severity === 'error')) return [];
47
+ if (rendersSwimlane(rootContent)) return [];
48
+ return [
49
+ {
50
+ severity: 'error',
51
+ message: tr('en-US', 'NL.E0004'),
52
+ sourcePath: rootAbs,
53
+ // The validator reports NL.E0004 on the whole declaration.
54
+ ...nodeLocation(roadmap),
55
+ code: 'NL.E0004',
56
+ args: [],
57
+ },
58
+ ];
59
+ }
@@ -77,14 +77,10 @@ export function hasParseErrors(file: NowlineFile): boolean {
77
77
  /**
78
78
  * `participates(C)` from specs/waves.md §7.1: C declares a roadmap, its
79
79
  * resolved content has a swimlane, or it declares waves. A child that failed
80
- * to parse, or a circular-include stub, never participates.
80
+ * to parse never participates.
81
81
  */
82
- export function participates(
83
- childFile: NowlineFile,
84
- childContent: ResolvedContent,
85
- isStub: boolean,
86
- ): boolean {
87
- if (isStub || hasParseErrors(childFile)) return false;
82
+ export function participates(childFile: NowlineFile, childContent: ResolvedContent): boolean {
83
+ if (hasParseErrors(childFile)) return false;
88
84
  return (
89
85
  !!childFile.roadmapDecl || childContent.swimlanes.size > 0 || ownWaves(childFile).length > 0
90
86
  );
@@ -312,9 +312,9 @@ export function checkNoRawStyleProperties(
312
312
  // NL.E1104 / NL.E1105 where it is not allowed)
313
313
  // - the keys a wave may not take (already NL.E1105)
314
314
  //
315
- // Suggests the closest known key within 2 edits when one exists, so the
316
- // existing `DID_YOU_MEAN_RE` in `packages/cli/src/diagnostics/adapt.ts` picks
317
- // it up as a structured suggestion alongside the rendered message.
315
+ // Suggests the closest known key within 2 edits when one exists; the
316
+ // `suggested` arg is also the diagnostic's structured suggestion (see
317
+ // `resolveDiagnosticSuggestion` in `packages/core/src/diagnostics/index.ts`).
318
318
  export function checkUnknownEntityProperties(
319
319
  node: {
320
320
  $type: string;
@@ -13,6 +13,7 @@ import type {
13
13
  import { isStyleDeclaration, isSwimlaneDeclaration } from '../../generated/ast.js';
14
14
  import { propKey } from '../../util/props.js';
15
15
  import { forEachDeclaredId } from '../ast-walk.js';
16
+ import { swimlaneRuleNeedsIncludes } from '../include-swimlanes.js';
16
17
  import { acceptTr, locationOf } from './support.js';
17
18
  import {
18
19
  BCP47_RE,
@@ -174,7 +175,10 @@ export function checkIndentationConsistency(file: NowlineFile, accept: Validatio
174
175
  }
175
176
 
176
177
  // --- Rule 6: At least one swimlane ---
178
+ // The rule is about the merged result. A file with an include that can add a
179
+ // swimlane is left to the include resolver (`checkMergedSwimlanes`).
177
180
  export function checkSwimlaneRequired(file: NowlineFile, accept: ValidationAcceptor): void {
181
+ if (swimlaneRuleNeedsIncludes(file)) return;
178
182
  const hasSwimlane = file.roadmapEntries.some(isSwimlaneDeclaration);
179
183
  if (file.roadmapDecl && !hasSwimlane) {
180
184
  acceptTr(accept, 'error', { node: file.roadmapDecl }, 'NL.E0004');
@@ -9,3 +9,8 @@ export async function nodeReadFile(absPath: string): Promise<string> {
9
9
  const fs = await import('node:fs');
10
10
  return fs.promises.readFile(absPath, 'utf-8');
11
11
  }
12
+
13
+ export async function nodeRealPath(absPath: string): Promise<string> {
14
+ const fs = await import('node:fs');
15
+ return fs.promises.realpath(absPath);
16
+ }
@@ -1,6 +1,6 @@
1
1
  // Browser-safe path helpers used by the include resolver. The set is
2
- // deliberately narrow: dirname, basename, and resolve(parentDir, relative)
3
- // — exactly the operations the resolver performs. Keeping these in the
2
+ // deliberately narrow: dirname, basename, resolve(parentDir, relative),
3
+ // relative and isWithin — exactly the operations the resolver performs. Keeping these in the
4
4
  // `@nowline/core` source tree (instead of pulling in `pathe` or
5
5
  // `path-browserify`) avoids adding an embed-bundle dependency for
6
6
  // behaviour that is ~30 lines of code, and keeps Windows / POSIX
@@ -31,7 +31,7 @@ function dominantSep(...paths: string[]): '/' | '\\' {
31
31
  return '/';
32
32
  }
33
33
 
34
- function isAbsolute(p: string): boolean {
34
+ export function isAbsolute(p: string): boolean {
35
35
  if (!p) return false;
36
36
  if (p[0] === '/' || p[0] === '\\') return true;
37
37
  // Windows drive-letter form: `C:\\…` or `C:/…`.
@@ -92,3 +92,28 @@ function normalize(p: string, sep: '/' | '\\'): string {
92
92
  }
93
93
  return prefix + segments.join(sep);
94
94
  }
95
+
96
+ // Both paths absolute; drive letters compare case-insensitively.
97
+ function segmentsOf(p: string): string[] {
98
+ const normalized = resolve('', p).replace(/\\/g, '/');
99
+ const drive = /^[A-Za-z]:/.test(normalized) ? normalized.slice(0, 2).toLowerCase() : '';
100
+ const body = drive ? normalized.slice(2) : normalized;
101
+ return [drive, ...body.split('/').filter((s) => s !== '')];
102
+ }
103
+
104
+ /** True when absolute `p` is `dir` or lies below it. Lexical: symlinks are not followed. */
105
+ export function isWithin(dir: string, p: string): boolean {
106
+ const d = segmentsOf(dir);
107
+ const t = segmentsOf(p);
108
+ return d.length <= t.length && d.every((seg, i) => seg === t[i]);
109
+ }
110
+
111
+ /** The path from absolute `from` (a directory) to absolute `to`, with `/` separators. */
112
+ export function relative(from: string, to: string): string {
113
+ const f = segmentsOf(from);
114
+ const t = segmentsOf(to);
115
+ if (f[0] !== t[0]) return to;
116
+ let i = 0;
117
+ while (i < f.length && i < t.length && f[i] === t[i]) i++;
118
+ return [...f.slice(i).map(() => '..'), ...t.slice(i)].join('/') || '.';
119
+ }