@nowline/core 0.8.6 → 0.9.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 (174) hide show
  1. package/README.md +9 -0
  2. package/dist/convert/printer.d.ts.map +1 -1
  3. package/dist/convert/printer.js +20 -9
  4. package/dist/convert/printer.js.map +1 -1
  5. package/dist/convert/schema.d.ts +7 -0
  6. package/dist/convert/schema.d.ts.map +1 -1
  7. package/dist/convert/schema.js +1 -1
  8. package/dist/convert/schema.js.map +1 -1
  9. package/dist/generated/ast.d.ts +134 -24
  10. package/dist/generated/ast.d.ts.map +1 -1
  11. package/dist/generated/ast.js +95 -3
  12. package/dist/generated/ast.js.map +1 -1
  13. package/dist/generated/grammar.d.ts.map +1 -1
  14. package/dist/generated/grammar.js +434 -148
  15. package/dist/generated/grammar.js.map +1 -1
  16. package/dist/i18n/codes.d.ts +1 -1
  17. package/dist/i18n/codes.d.ts.map +1 -1
  18. package/dist/i18n/codes.js +44 -1
  19. package/dist/i18n/codes.js.map +1 -1
  20. package/dist/i18n/index.d.ts +1 -0
  21. package/dist/i18n/index.d.ts.map +1 -1
  22. package/dist/i18n/index.js.map +1 -1
  23. package/dist/i18n/messages.en.d.ts +107 -0
  24. package/dist/i18n/messages.en.d.ts.map +1 -1
  25. package/dist/i18n/messages.en.js +220 -1
  26. package/dist/i18n/messages.en.js.map +1 -1
  27. package/dist/i18n/messages.fr.d.ts.map +1 -1
  28. package/dist/i18n/messages.fr.js +250 -1
  29. package/dist/i18n/messages.fr.js.map +1 -1
  30. package/dist/i18n/wave-message-types.d.ts +238 -0
  31. package/dist/i18n/wave-message-types.d.ts.map +1 -0
  32. package/dist/i18n/wave-message-types.js +11 -0
  33. package/dist/i18n/wave-message-types.js.map +1 -0
  34. package/dist/index.d.ts +6 -1
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +5 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/internal.d.ts +6 -0
  39. package/dist/internal.d.ts.map +1 -0
  40. package/dist/internal.js +9 -0
  41. package/dist/internal.js.map +1 -0
  42. package/dist/language/ast-walk.d.ts +31 -0
  43. package/dist/language/ast-walk.d.ts.map +1 -0
  44. package/dist/language/ast-walk.js +109 -0
  45. package/dist/language/ast-walk.js.map +1 -0
  46. package/dist/language/calendar-declarations.d.ts +31 -0
  47. package/dist/language/calendar-declarations.d.ts.map +1 -0
  48. package/dist/language/calendar-declarations.js +99 -0
  49. package/dist/language/calendar-declarations.js.map +1 -0
  50. package/dist/language/include-references.d.ts +11 -0
  51. package/dist/language/include-references.d.ts.map +1 -0
  52. package/dist/language/include-references.js +45 -0
  53. package/dist/language/include-references.js.map +1 -0
  54. package/dist/language/include-resolver.d.ts +78 -1
  55. package/dist/language/include-resolver.d.ts.map +1 -1
  56. package/dist/language/include-resolver.js +190 -12
  57. package/dist/language/include-resolver.js.map +1 -1
  58. package/dist/language/include-waves.d.ts +73 -0
  59. package/dist/language/include-waves.d.ts.map +1 -0
  60. package/dist/language/include-waves.js +319 -0
  61. package/dist/language/include-waves.js.map +1 -0
  62. package/dist/language/nowline-validator.d.ts +6 -1
  63. package/dist/language/nowline-validator.d.ts.map +1 -1
  64. package/dist/language/nowline-validator.js +95 -1589
  65. package/dist/language/nowline-validator.js.map +1 -1
  66. package/dist/language/references.d.ts +14 -0
  67. package/dist/language/references.d.ts.map +1 -0
  68. package/dist/language/references.js +36 -0
  69. package/dist/language/references.js.map +1 -0
  70. package/dist/language/style-chain.d.ts +37 -0
  71. package/dist/language/style-chain.d.ts.map +1 -0
  72. package/dist/language/style-chain.js +55 -0
  73. package/dist/language/style-chain.js.map +1 -0
  74. package/dist/language/validator/calendar.d.ts +9 -0
  75. package/dist/language/validator/calendar.d.ts.map +1 -0
  76. package/dist/language/validator/calendar.js +250 -0
  77. package/dist/language/validator/calendar.js.map +1 -0
  78. package/dist/language/validator/entities.d.ts +23 -0
  79. package/dist/language/validator/entities.d.ts.map +1 -0
  80. package/dist/language/validator/entities.js +261 -0
  81. package/dist/language/validator/entities.js.map +1 -0
  82. package/dist/language/validator/properties.d.ts +18 -0
  83. package/dist/language/validator/properties.d.ts.map +1 -0
  84. package/dist/language/validator/properties.js +356 -0
  85. package/dist/language/validator/properties.js.map +1 -0
  86. package/dist/language/validator/references.d.ts +7 -0
  87. package/dist/language/validator/references.d.ts.map +1 -0
  88. package/dist/language/validator/references.js +261 -0
  89. package/dist/language/validator/references.js.map +1 -0
  90. package/dist/language/validator/structure.d.ts +16 -0
  91. package/dist/language/validator/structure.d.ts.map +1 -0
  92. package/dist/language/validator/structure.js +166 -0
  93. package/dist/language/validator/structure.js.map +1 -0
  94. package/dist/language/validator/style.d.ts +5 -0
  95. package/dist/language/validator/style.d.ts.map +1 -0
  96. package/dist/language/validator/style.js +126 -0
  97. package/dist/language/validator/style.js.map +1 -0
  98. package/dist/language/validator/support.d.ts +35 -0
  99. package/dist/language/validator/support.d.ts.map +1 -0
  100. package/dist/language/validator/support.js +49 -0
  101. package/dist/language/validator/support.js.map +1 -0
  102. package/dist/language/validator/symbols.d.ts +6 -0
  103. package/dist/language/validator/symbols.d.ts.map +1 -0
  104. package/dist/language/validator/symbols.js +131 -0
  105. package/dist/language/validator/symbols.js.map +1 -0
  106. package/dist/language/validator/tables.d.ts +34 -0
  107. package/dist/language/validator/tables.d.ts.map +1 -0
  108. package/dist/language/validator/tables.js +120 -0
  109. package/dist/language/validator/tables.js.map +1 -0
  110. package/dist/language/validator-utils.d.ts +32 -0
  111. package/dist/language/validator-utils.d.ts.map +1 -0
  112. package/dist/language/validator-utils.js +118 -0
  113. package/dist/language/validator-utils.js.map +1 -0
  114. package/dist/language/value-tables.d.ts +107 -0
  115. package/dist/language/value-tables.d.ts.map +1 -0
  116. package/dist/language/value-tables.js +240 -0
  117. package/dist/language/value-tables.js.map +1 -0
  118. package/dist/language/waves-order.d.ts +51 -0
  119. package/dist/language/waves-order.d.ts.map +1 -0
  120. package/dist/language/waves-order.js +787 -0
  121. package/dist/language/waves-order.js.map +1 -0
  122. package/dist/language/waves-plan.d.ts +45 -0
  123. package/dist/language/waves-plan.d.ts.map +1 -0
  124. package/dist/language/waves-plan.js +64 -0
  125. package/dist/language/waves-plan.js.map +1 -0
  126. package/dist/language/waves.d.ts +96 -0
  127. package/dist/language/waves.d.ts.map +1 -0
  128. package/dist/language/waves.js +575 -0
  129. package/dist/language/waves.js.map +1 -0
  130. package/dist/util/props.d.ts +27 -0
  131. package/dist/util/props.d.ts.map +1 -0
  132. package/dist/util/props.js +49 -0
  133. package/dist/util/props.js.map +1 -0
  134. package/dist/util/single-line.d.ts +14 -0
  135. package/dist/util/single-line.d.ts.map +1 -0
  136. package/dist/util/single-line.js +16 -0
  137. package/dist/util/single-line.js.map +1 -0
  138. package/package.json +7 -3
  139. package/src/convert/printer.ts +20 -10
  140. package/src/convert/schema.ts +8 -1
  141. package/src/generated/ast.ts +159 -27
  142. package/src/generated/grammar.ts +434 -148
  143. package/src/i18n/codes.ts +95 -2
  144. package/src/i18n/index.ts +1 -0
  145. package/src/i18n/messages.en.ts +300 -1
  146. package/src/i18n/messages.fr.ts +335 -1
  147. package/src/i18n/wave-message-types.ts +206 -0
  148. package/src/index.ts +33 -0
  149. package/src/internal.ts +9 -0
  150. package/src/language/ast-walk.ts +158 -0
  151. package/src/language/calendar-declarations.ts +141 -0
  152. package/src/language/include-references.ts +49 -0
  153. package/src/language/include-resolver.ts +284 -10
  154. package/src/language/include-waves.ts +419 -0
  155. package/src/language/nowline-validator.ts +98 -1835
  156. package/src/language/nowline.langium +56 -22
  157. package/src/language/references.ts +40 -0
  158. package/src/language/style-chain.ts +95 -0
  159. package/src/language/validator/calendar.ts +319 -0
  160. package/src/language/validator/entities.ts +366 -0
  161. package/src/language/validator/properties.ts +425 -0
  162. package/src/language/validator/references.ts +295 -0
  163. package/src/language/validator/structure.ts +206 -0
  164. package/src/language/validator/style.ts +149 -0
  165. package/src/language/validator/support.ts +84 -0
  166. package/src/language/validator/symbols.ts +141 -0
  167. package/src/language/validator/tables.ts +171 -0
  168. package/src/language/validator-utils.ts +123 -0
  169. package/src/language/value-tables.ts +260 -0
  170. package/src/language/waves-order.ts +879 -0
  171. package/src/language/waves-plan.ts +101 -0
  172. package/src/language/waves.ts +731 -0
  173. package/src/util/props.ts +59 -0
  174. package/src/util/single-line.ts +15 -0
@@ -1,4 +1,5 @@
1
1
  import { URI } from 'langium';
2
+ import { collectDocumentDiagnostics, type RawDiagnostic } from '../diagnostics/index.js';
2
3
  import type {
3
4
  AnchorDeclaration,
4
5
  CalendarBlock,
@@ -8,6 +9,7 @@ import type {
8
9
  IncludeDeclaration,
9
10
  LabelDeclaration,
10
11
  MilestoneDeclaration,
12
+ NonWorkingDeclaration,
11
13
  NowlineFile,
12
14
  PersonDeclaration,
13
15
  RoadmapDeclaration,
@@ -19,6 +21,8 @@ import type {
19
21
  SwimlaneDeclaration,
20
22
  SymbolDeclaration,
21
23
  TeamDeclaration,
24
+ WaveDeclaration,
25
+ WorkingDeclaration,
22
26
  } from '../generated/ast.js';
23
27
  import {
24
28
  isAnchorDeclaration,
@@ -27,6 +31,7 @@ import {
27
31
  isFootnoteDeclaration,
28
32
  isLabelDeclaration,
29
33
  isMilestoneDeclaration,
34
+ isNonWorkingDeclaration,
30
35
  isPersonDeclaration,
31
36
  isScaleBlock,
32
37
  isSizeDeclaration,
@@ -35,19 +40,31 @@ import {
35
40
  isSwimlaneDeclaration,
36
41
  isSymbolDeclaration,
37
42
  isTeamDeclaration,
43
+ isWaveDeclaration,
44
+ isWorkingDeclaration,
38
45
  } from '../generated/ast.js';
46
+ import type { MessageCode } from '../i18n/codes.js';
39
47
  import { basename, dirname, resolve as resolvePath } from '../util/posix-path.js';
48
+ import { isRealIsoDate } from '../util/props.js';
49
+ import { checkIncludedReferences } from './include-references.js';
50
+ import {
51
+ checkWaveAgreement,
52
+ hasParseErrors,
53
+ participates,
54
+ runResolverWaveChecks,
55
+ type WaveIncludeEdge,
56
+ } from './include-waves.js';
40
57
  import type { NowlineServices } from './nowline-module.js';
58
+ import { ownWaves } from './waves.js';
41
59
 
42
60
  export type IncludeMode = 'merge' | 'ignore' | 'isolate';
43
61
 
44
- const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
45
-
62
+ // An impossible `start:` (`2026-02-30`) reads as absent, as it does in layout;
63
+ // the validator reports it as NL.E0405. (`new Date` would roll it over to
64
+ // March 2, so a parent and child could disagree on a day neither names.)
46
65
  function readStartProp(decl: RoadmapDeclaration | undefined): string | undefined {
47
66
  const prop = decl?.properties.find((p) => p.key === 'start');
48
- if (!prop?.value) return undefined;
49
- if (!DATE_RE.test(prop.value)) return undefined;
50
- if (Number.isNaN(new Date(prop.value).getTime())) return undefined;
67
+ if (!prop?.value || !isRealIsoDate(prop.value)) return undefined;
51
68
  return prop.value;
52
69
  }
53
70
 
@@ -75,8 +92,19 @@ export interface ResolvedConfig {
75
92
  // a built-in identifier or an inline Unicode literal. See specs/dsl.md §
76
93
  // Symbol Declaration.
77
94
  symbols: Map<string, SymbolDeclaration>;
95
+ /**
96
+ * Every `non-working` and `working` declaration of the file and its merged
97
+ * includes (specs/working-calendar.md §4). Unnamed ones always merge; a
98
+ * child's named one is dropped, with a warning, when the parent already
99
+ * holds one with the same keyword and name. The order carries no meaning:
100
+ * the layout's calendar resolver sorts the rules it builds from them.
101
+ */
102
+ calendarDeclarations: CalendarDeclaration[];
78
103
  }
79
104
 
105
+ /** A `non-working` or `working` config declaration. */
106
+ type CalendarDeclaration = NonWorkingDeclaration | WorkingDeclaration;
107
+
80
108
  export interface ResolvedContent {
81
109
  roadmap?: RoadmapDeclaration;
82
110
  persons: Map<string, PersonDeclaration>;
@@ -89,6 +117,13 @@ export interface ResolvedContent {
89
117
  milestones: Map<string, MilestoneDeclaration>;
90
118
  footnotes: Map<string, FootnoteDeclaration>;
91
119
  isolatedRegions: IsolatedRegion[];
120
+ /**
121
+ * The file's own waves (specs/waves.md §7.4), by id; insertion order is
122
+ * the wave order. Absent when the file declares none. Children's waves
123
+ * are never merged in: include rule 12 makes every participating file
124
+ * declare the same waves. Consumers read `content.waves ?? EMPTY`.
125
+ */
126
+ waves?: Map<string, WaveDeclaration>;
92
127
  }
93
128
 
94
129
  export interface IsolatedRegion {
@@ -101,11 +136,65 @@ export interface IsolatedRegion {
101
136
  content: ResolvedContent;
102
137
  }
103
138
 
139
+ /** A 0-based, end-exclusive source range, the shape of an LSP `Range`. */
140
+ export interface ResolveRange {
141
+ start: { line: number; character: number };
142
+ end: { line: number; character: number };
143
+ }
144
+
104
145
  export interface ResolveDiagnostic {
105
146
  severity: 'error' | 'warning';
147
+ /** en-US text; `localizeResolveDiagnostic` renders a coded one in another locale. */
106
148
  message: string;
149
+ /** Absolute path of the file the diagnostic points into. */
107
150
  sourcePath: string;
151
+ /** 0-based line in `sourcePath`; `range.start.line` when `range` is set. */
108
152
  line?: number;
153
+ /**
154
+ * 0-based range in `sourcePath` of the node the diagnostic is about,
155
+ * narrowed to the property where the validator narrows its copy, so a
156
+ * consumer can point at the same column and span. Set on the routed
157
+ * diagnostics (see `isRoutedResolveDiagnostic`) whose node has a CST
158
+ * node; consumers fall back to the whole of `line` without it. An
159
+ * included file's syntax error has none: consumers adapt its `syntax`.
160
+ */
161
+ range?: ResolveRange;
162
+ /**
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.
166
+ */
167
+ code?: MessageCode;
168
+ /** The message arguments as a rest tuple, as `acceptTr` stores them. */
169
+ args?: unknown[];
170
+ /**
171
+ * `'wave'` on every diagnostic of the wave checks (specs/waves.md §6.1),
172
+ * coded or not (WV8 reuses an uncoded message). Absent on every other
173
+ * resolver diagnostic. See `isRoutedResolveDiagnostic`.
174
+ */
175
+ rule?: 'wave';
176
+ /**
177
+ * The lexer or parser error of an included file that failed to parse
178
+ * (specs/dsl.md, Include rule 13), as `collectDocumentDiagnostics`
179
+ * reports it. A surface adapts it with its own lexer/parser adapter, so it
180
+ * reads as it does when that file is checked on its own. Absent on every
181
+ * other resolver diagnostic.
182
+ */
183
+ syntax?: IncludedSyntaxError;
184
+ }
185
+
186
+ /** A lexer or parser error of an included file. */
187
+ export type IncludedSyntaxError = Extract<RawDiagnostic, { origin: 'lexer' | 'parser' }>;
188
+
189
+ /**
190
+ * 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
194
+ * (specs/waves.md §6.1).
195
+ */
196
+ export function isRoutedResolveDiagnostic(d: ResolveDiagnostic): boolean {
197
+ return d.code !== undefined || d.rule === 'wave' || d.syntax !== undefined;
109
198
  }
110
199
 
111
200
  export interface ResolveResult {
@@ -117,10 +206,20 @@ export interface ResolveResult {
117
206
 
118
207
  interface ResolveContext {
119
208
  services: NowlineServices;
209
+ /** Absolute path of the root file, whose syntax errors the validator reports. */
210
+ rootAbs: string;
120
211
  diagnostics: ResolveDiagnostic[];
121
212
  resolving: string[];
122
213
  processed: Map<string, { config: ResolvedConfig; content: ResolvedContent }>;
123
214
  readFile: (absPath: string) => Promise<string>;
215
+ /** Every parsed file, the root included, with its absolute path. */
216
+ files: Map<NowlineFile, string>;
217
+ /** Include edges whose child was read, per including file, in include order. */
218
+ edges: Map<string, WaveIncludeEdge[]>;
219
+ /** Contents returned for a circular include (they never participate). */
220
+ stubs: Set<ResolvedContent>;
221
+ /** Children that failed include rule 12 (NL.E0202). */
222
+ failedWaves: Set<string>;
124
223
  }
125
224
 
126
225
  function emptyConfig(): ResolvedConfig {
@@ -128,6 +227,7 @@ function emptyConfig(): ResolvedConfig {
128
227
  styles: new Map(),
129
228
  defaults: new Map(),
130
229
  symbols: new Map(),
230
+ calendarDeclarations: [],
131
231
  };
132
232
  }
133
233
 
@@ -165,15 +265,34 @@ export async function resolveIncludes(
165
265
  const { nodeReadFile } = await import('../util/node-read-file.js');
166
266
  return nodeReadFile(p);
167
267
  });
268
+ const absPath = resolvePath('', filePath);
168
269
  const ctx: ResolveContext = {
169
270
  services: options.services,
271
+ rootAbs: absPath,
170
272
  diagnostics: [],
171
273
  resolving: [],
172
274
  processed: new Map(),
173
275
  readFile,
276
+ files: new Map(),
277
+ edges: new Map(),
278
+ stubs: new Set(),
279
+ failedWaves: new Set(),
174
280
  };
175
- const absPath = resolvePath('', filePath);
176
281
  const { config, content } = await resolveFile(file, absPath, ctx);
282
+ // The wave S, P and G evaluations run once, over everything resolved.
283
+ ctx.diagnostics.push(
284
+ ...runResolverWaveChecks({
285
+ rootFile: file,
286
+ rootAbs: absPath,
287
+ rootContent: content,
288
+ files: ctx.files,
289
+ edges: ctx.edges,
290
+ failed: ctx.failedWaves,
291
+ }),
292
+ );
293
+ // References never cross a file boundary; report each included file's
294
+ // unresolved ones in that file (an included file is never validated).
295
+ ctx.diagnostics.push(...checkIncludedReferences(absPath, ctx.edges));
177
296
  return {
178
297
  config,
179
298
  content,
@@ -197,11 +316,19 @@ async function resolveFile(
197
316
  sourcePath: absPath,
198
317
  });
199
318
  const empty = { config: emptyConfig(), content: emptyContent() };
319
+ ctx.stubs.add(empty.content);
200
320
  ctx.processed.set(absPath, empty);
201
321
  return empty;
202
322
  }
203
323
 
324
+ // Each included file once, in every include mode: a `roadmap:ignore`
325
+ // child's config is still merged (Include rule 13).
326
+ if (absPath !== ctx.rootAbs) ctx.diagnostics.push(...syntaxDiagnostics(file, absPath));
327
+
204
328
  ctx.resolving.push(absPath);
329
+ // The root is parsed from a `memory:` URI by every surface, so files are
330
+ // mapped by object, never by `$document.uri`.
331
+ ctx.files.set(file, absPath);
205
332
 
206
333
  const config = emptyConfig();
207
334
  const content = emptyContent();
@@ -210,7 +337,13 @@ async function resolveFile(
210
337
  // files shadow to the parent (parent wins) and produce a warning pointing at the child.
211
338
  mergeLocalConfig(config, file);
212
339
  mergeLocalContent(content, file);
340
+ const waves = ownWaves(file);
341
+ if (waves.length > 0) {
342
+ content.waves = new Map(waves.map((w) => [w.name as string, w]));
343
+ }
213
344
 
345
+ const edges: WaveIncludeEdge[] = [];
346
+ ctx.edges.set(absPath, edges);
214
347
  const seenIncludes = new Set<string>();
215
348
  for (const inc of file.includes) {
216
349
  const childRelPath = inc.path;
@@ -249,6 +382,16 @@ async function resolveFile(
249
382
  childAbsPath,
250
383
  ctx,
251
384
  );
385
+ edges.push({
386
+ parentAbs: absPath,
387
+ inc,
388
+ childRelPath,
389
+ childAbs: childAbsPath,
390
+ mode: roadmapMode,
391
+ childFile,
392
+ childContent,
393
+ participates: participates(childFile, childContent, ctx.stubs.has(childContent)),
394
+ });
252
395
 
253
396
  applyConfigMode(config, childConfig, configMode, childAbsPath, ctx.diagnostics);
254
397
  applyRoadmapMode(
@@ -261,7 +404,11 @@ async function resolveFile(
261
404
  ctx.diagnostics,
262
405
  );
263
406
 
264
- if (roadmapMode === 'isolate' && !childContent.roadmap) {
407
+ // A partial AST would report a roadmap or start: the parser lost, as
408
+ // an include error that hides the syntax error (Include rule 13).
409
+ const isParsed = !hasParseErrors(childFile);
410
+
411
+ if (isParsed && roadmapMode === 'isolate' && !childContent.roadmap) {
265
412
  ctx.diagnostics.push({
266
413
  severity: 'error',
267
414
  message: `Cannot isolate "${childRelPath}": it has no roadmap declaration.`,
@@ -273,7 +420,7 @@ async function resolveFile(
273
420
  // Non-ignored includes with a child roadmap must agree on start: with the parent.
274
421
  // Deliberate divergence from the usual "parent wins with warning" merge behaviour
275
422
  // because start: defines the shared timeline baseline.
276
- if (roadmapMode !== 'ignore' && childFile.roadmapDecl) {
423
+ if (isParsed && roadmapMode !== 'ignore' && childFile.roadmapDecl) {
277
424
  const parentStart = readStartProp(file.roadmapDecl);
278
425
  const childStart = readStartProp(childFile.roadmapDecl);
279
426
  if (parentStart !== childStart) {
@@ -287,12 +434,46 @@ async function resolveFile(
287
434
  }
288
435
  }
289
436
 
437
+ if (content.waves) rekeyWaveSlugs(content, content.waves);
438
+
439
+ // Include rule 12 runs after the include loop, so its result does not
440
+ // depend on include order (specs/waves.md §7.4).
441
+ for (const edge of edges) {
442
+ const { diagnostics, failed } = checkWaveAgreement(file, content, edge);
443
+ ctx.diagnostics.push(...diagnostics);
444
+ if (failed) ctx.failedWaves.add(edge.childAbs);
445
+ }
446
+
290
447
  ctx.resolving.pop();
291
448
  const result = { config, content };
292
449
  ctx.processed.set(absPath, result);
293
450
  return result;
294
451
  }
295
452
 
453
+ /**
454
+ * An included file's lexer and parser errors, at their line in that file.
455
+ * An included file is parsed without validation, so nothing else reports
456
+ * them.
457
+ */
458
+ function syntaxDiagnostics(file: NowlineFile, absPath: string): ResolveDiagnostic[] {
459
+ const doc = file.$document;
460
+ if (!doc) return [];
461
+ const out: ResolveDiagnostic[] = [];
462
+ for (const raw of collectDocumentDiagnostics(doc)) {
463
+ if (raw.origin === 'validation') continue;
464
+ // Chevrotain lines are 1-based; an error at end of input has NaN.
465
+ const line = raw.origin === 'lexer' ? raw.error.line : raw.error.token?.startLine;
466
+ out.push({
467
+ severity: 'error',
468
+ message: raw.error.message,
469
+ sourcePath: absPath,
470
+ ...(line !== undefined && Number.isFinite(line) ? { line: line - 1 } : {}),
471
+ syntax: raw,
472
+ });
473
+ }
474
+ return out;
475
+ }
476
+
296
477
  function getIncludeMode(
297
478
  inc: IncludeDeclaration,
298
479
  key: 'config' | 'roadmap',
@@ -336,6 +517,9 @@ function applyConfigMode(
336
517
  mergeMap(target.styles, child.styles, (name) => warn(name, 'Style'));
337
518
  mergeMap(target.defaults, child.defaults, (name) => warn(name, 'Default'));
338
519
  mergeMap(target.symbols, child.symbols, (name) => warn(name, 'Symbol'));
520
+ mergeCalendarDeclarations(target.calendarDeclarations, child.calendarDeclarations, (decl) =>
521
+ warn(decl.name as string, calendarKeywordLabel(decl)),
522
+ );
339
523
  if (child.scale && !target.scale) {
340
524
  target.scale = child.scale;
341
525
  }
@@ -394,25 +578,69 @@ function mergeMap<V>(
394
578
  ): void {
395
579
  for (const [name, value] of source) {
396
580
  if (target.has(name)) {
397
- onConflict(name);
581
+ // The same declaration arriving again through a diamond include
582
+ // is not a collision.
583
+ if (target.get(name) !== value) onConflict(name);
398
584
  continue;
399
585
  }
400
586
  target.set(name, value);
401
587
  }
402
588
  }
403
589
 
590
+ /**
591
+ * Append a child's calendar declarations to the parent's list. An unnamed
592
+ * declaration always merges. A named one is dropped, and reported, when the
593
+ * list already holds one with the same keyword and name (parent wins); a
594
+ * `non-working h` and a `working h` never collide. A declaration already in
595
+ * the list (a diamond include delivers the shared file's cached config
596
+ * through every path) is skipped silently.
597
+ */
598
+ function mergeCalendarDeclarations(
599
+ target: CalendarDeclaration[],
600
+ source: readonly CalendarDeclaration[],
601
+ onConflict: (decl: CalendarDeclaration) => void,
602
+ ): void {
603
+ const merged = new Set(target);
604
+ // Names held before this merge: a child's own duplicate id is NL.E0907 in
605
+ // that file, not a shadowing by the parent, so both of its copies merge.
606
+ const held = new Set(target.filter((t) => t.name).map(calendarDeclarationKey));
607
+ for (const decl of source) {
608
+ if (merged.has(decl)) continue;
609
+ if (decl.name && held.has(calendarDeclarationKey(decl))) {
610
+ onConflict(decl);
611
+ continue;
612
+ }
613
+ target.push(decl);
614
+ merged.add(decl);
615
+ }
616
+ }
617
+
618
+ /** Keyword and id: the identity two named calendar declarations collide on. */
619
+ function calendarDeclarationKey(decl: CalendarDeclaration): string {
620
+ return `${decl.$type}:${decl.name}`;
621
+ }
622
+
623
+ /** The shadow-warning category of a calendar declaration: its keyword, capitalized. */
624
+ function calendarKeywordLabel(decl: CalendarDeclaration): string {
625
+ return isNonWorkingDeclaration(decl) ? 'Non-working' : 'Working';
626
+ }
627
+
404
628
  /**
405
629
  * Merge a child content map into the parent. Explicit-id entries keep the
406
630
  * parent-wins-on-collision behavior (and warn). Title-only (auto-slugged)
407
631
  * entries are internal and non-referenceable, so they never shadow and never
408
- * warn — each is re-keyed around the parent's entries and kept.
632
+ * warn — each is re-keyed around the parent's entries and kept. A declaration
633
+ * already in the parent (a diamond include delivers the shared file's cached
634
+ * content through every path) is skipped silently, whatever its key.
409
635
  */
410
636
  function mergeContentMap<V extends { name?: string; title?: string }>(
411
637
  target: Map<string, V>,
412
638
  source: Map<string, V>,
413
639
  onConflict: (name: string) => void,
414
640
  ): void {
641
+ const merged = new Set(target.values());
415
642
  for (const [name, value] of source) {
643
+ if (merged.has(value)) continue;
416
644
  if (!value.name && value.title) {
417
645
  target.set(
418
646
  uniqueMapKey(target as Map<string, unknown>, slugifyTitle(value.title)),
@@ -451,6 +679,10 @@ function addConfigEntry(config: ResolvedConfig, entry: ConfigEntry): void {
451
679
  if (!config.defaults.has(entry.entityType)) {
452
680
  config.defaults.set(entry.entityType, entry);
453
681
  }
682
+ } else if (isNonWorkingDeclaration(entry) || isWorkingDeclaration(entry)) {
683
+ // Every declaration of the file, named or not: a duplicate id in one
684
+ // file is the validator's NL.E0907, not a merge question.
685
+ config.calendarDeclarations.push(entry);
454
686
  }
455
687
  }
456
688
 
@@ -467,6 +699,8 @@ interface ReservedRoadmapIds {
467
699
  footnotes: Set<string>;
468
700
  }
469
701
 
702
+ // Wave ids are reserved in every map: layout seeds its edge maps by key, so a
703
+ // title-only `milestone "Launch"` must not take the key of `wave launch`.
470
704
  function collectExplicitRoadmapIds(entries: RoadmapEntry[]): ReservedRoadmapIds {
471
705
  const reserved: ReservedRoadmapIds = {
472
706
  swimlanes: new Set(),
@@ -491,10 +725,50 @@ function collectExplicitRoadmapIds(entries: RoadmapEntry[]): ReservedRoadmapIds
491
725
  else if (isStatusDeclaration(entry)) reserved.statuses.add(name);
492
726
  else if (isMilestoneDeclaration(entry)) reserved.milestones.add(name);
493
727
  else if (isFootnoteDeclaration(entry)) reserved.footnotes.add(name);
728
+ else if (isWaveDeclaration(entry)) {
729
+ for (const set of Object.values(reserved)) set.add(name);
730
+ }
494
731
  }
495
732
  return reserved;
496
733
  }
497
734
 
735
+ /**
736
+ * Re-key every title-only entry whose slug key equals a wave id (merged in
737
+ * from a child, whose slugs are recomputed by `mergeContentMap`), keeping
738
+ * each map's insertion order. Layout seeds its edge maps by key.
739
+ */
740
+ function rekeyWaveSlugs(
741
+ content: ResolvedContent,
742
+ waves: ReadonlyMap<string, WaveDeclaration>,
743
+ ): void {
744
+ const maps: Array<Map<string, { name?: string; title?: string }>> = [
745
+ content.persons,
746
+ content.teams,
747
+ content.anchors,
748
+ content.labels,
749
+ content.sizes,
750
+ content.statuses,
751
+ content.swimlanes,
752
+ content.milestones,
753
+ content.footnotes,
754
+ ];
755
+ const titleOnlyOnWave = (key: string, v: { name?: string; title?: string }): boolean =>
756
+ waves.has(key) && !v.name && !!v.title;
757
+ for (const map of maps) {
758
+ const entries = [...map];
759
+ if (!entries.some(([k, v]) => titleOnlyOnWave(k, v))) continue;
760
+ const reserved = new Set<string>([...map.keys(), ...waves.keys()]);
761
+ map.clear();
762
+ for (const [k, v] of entries) {
763
+ const key = titleOnlyOnWave(k, v)
764
+ ? uniqueMapKey(map as Map<string, unknown>, k, reserved)
765
+ : k;
766
+ reserved.add(key);
767
+ map.set(key, v);
768
+ }
769
+ }
770
+ }
771
+
498
772
  function mergeLocalContent(content: ResolvedContent, file: NowlineFile): void {
499
773
  if (file.roadmapDecl && !content.roadmap) {
500
774
  content.roadmap = file.roadmapDecl;