@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,355 +1,14 @@
1
- import { GrammarUtils } from 'langium';
2
- import { isAnchorDeclaration, isCalendarBlock, isDefaultDeclaration, isDescriptionDirective, isFootnoteDeclaration, isGroupBlock, isItemDeclaration, isLabelDeclaration, isMilestoneDeclaration, isParallelBlock, isPersonDeclaration, isPersonMemberRef, isSizeDeclaration, isStatusDeclaration, isStyleDeclaration, isSwimlaneDeclaration, isSymbolDeclaration, isTeamDeclaration, } from '../generated/ast.js';
3
- import { tr } from '../i18n/index.js';
4
- const SUPPORTED_VERSION = 'v1';
5
- // Built-in status vocabulary. `active` and `completed` are international-
6
- // friendly aliases for `in-progress` and `done` respectively — they
7
- // canonicalize at the layout boundary (see statusFromProp in layout.ts) so
8
- // downstream consumers see a single normalized form. Both spellings remain
9
- // valid input.
10
- const BUILTIN_STATUSES = new Set([
11
- 'planned',
12
- 'in-progress',
13
- 'active',
14
- 'done',
15
- 'completed',
16
- 'at-risk',
17
- 'blocked',
18
- ]);
19
- const STYLE_PROP_KEYS = new Set([
20
- 'bg',
21
- 'fg',
22
- 'text',
23
- 'border',
24
- 'icon',
25
- 'shadow',
26
- 'font',
27
- 'weight',
28
- 'italic',
29
- 'text-size',
30
- 'padding',
31
- 'spacing',
32
- 'header-height',
33
- 'corner-radius',
34
- 'bracket',
35
- 'header-position',
36
- 'capacity-icon',
37
- 'timeline-position',
38
- 'minor-grid',
39
- ]);
40
- // Built-in capacity-icon vocabulary. Renderer-curated SVG glyphs (plus 'multiplier'
41
- // which renders as the U+00D7 text character and 'none' which suppresses the glyph).
42
- const BUILTIN_CAPACITY_ICONS = new Set([
43
- 'none',
44
- 'multiplier',
45
- 'person',
46
- 'people',
47
- 'points',
48
- 'time',
49
- ]);
50
- // Built-in icon: vocabulary. Superset of capacity-icon names plus the entity-decoration
51
- // icons currently shipped by the renderer. `calendar` is the renderer-side glyph the
52
- // inline-date pin path (`after:DATE` / `before:DATE`) draws onto items, parallels, and
53
- // groups; reserving it here prevents a `symbol calendar` declaration from shadowing it.
54
- const BUILTIN_ICON_NAMES = new Set([
55
- ...BUILTIN_CAPACITY_ICONS,
56
- 'shield',
57
- 'warning',
58
- 'lock',
59
- 'calendar',
60
- ]);
61
- // `utilization-warn-at:` / `utilization-over-at:` accept the literal `none`
62
- // to opt out of that color band (per specs/dsl.md rule 17d). Numeric forms
63
- // (positive percent, decimal, integer) are validated separately via
64
- // POSITIVE_NUMBER_RE / POSITIVE_PERCENT_RE.
65
- const UTILIZATION_NONE = 'none';
66
- const STYLE_PROP_ENUMS = {
67
- border: new Set(['solid', 'dashed', 'dotted']),
68
- shadow: new Set(['none', 'subtle', 'soft', 'hard']),
69
- font: new Set(['sans', 'serif', 'mono']),
70
- weight: new Set(['thin', 'light', 'normal', 'bold']),
71
- italic: new Set(['true', 'false']),
72
- 'text-size': new Set(['none', 'xs', 'sm', 'md', 'lg', 'xl']),
73
- padding: new Set(['none', 'xs', 'sm', 'md', 'lg', 'xl']),
74
- spacing: new Set(['none', 'xs', 'sm', 'md', 'lg', 'xl']),
75
- 'header-height': new Set(['none', 'xs', 'sm', 'md', 'lg', 'xl']),
76
- 'corner-radius': new Set(['none', 'xs', 'sm', 'md', 'lg', 'xl', 'full']),
77
- bracket: new Set(['none', 'solid', 'dashed']),
78
- 'header-position': new Set(['beside', 'above']),
79
- 'timeline-position': new Set(['top', 'bottom', 'both']),
80
- 'minor-grid': new Set(['true', 'false']),
81
- };
82
- // Built-in color vocabulary. `grey` and `violet` are international-friendly
83
- // aliases for `gray` and `purple` — they canonicalize at the theme
84
- // boundary (resolveColor in packages/layout/src/themes/index.ts) so themes
85
- // don't grow new fields. Both spellings remain valid input.
86
- const COLOR_NAMES = new Set([
87
- 'red',
88
- 'blue',
89
- 'yellow',
90
- 'green',
91
- 'orange',
92
- 'purple',
93
- 'violet',
94
- 'gray',
95
- 'grey',
96
- 'navy',
97
- 'white',
98
- 'none',
99
- ]);
100
- const CALENDAR_MODES = new Set(['business', 'full', 'custom']);
101
- const CALENDAR_FIELDS = new Set([
102
- 'days-per-week',
103
- 'days-per-month',
104
- 'days-per-quarter',
105
- 'days-per-year',
106
- ]);
107
- const SCALE_FIELDS = new Set(['name', 'label-every', 'label']);
108
- const DEFAULT_ENTITY_TYPES = new Set([
109
- 'item',
110
- 'label',
111
- 'swimlane',
112
- 'roadmap',
113
- 'milestone',
114
- 'footnote',
115
- 'anchor',
116
- 'parallel',
117
- 'group',
118
- ]);
119
- // Banned properties per entity type on `default <entity>` lines.
120
- // `capacity` on `default swimlane` is banned because each lane's budget must be
121
- // explicit at its declaration site (per dsl.md). `capacity` on `default item` is
122
- // allowed (and a useful "every item consumes 1 unit by default" lever).
123
- const DEFAULT_BANNED = {
124
- item: new Set([
125
- 'size',
126
- 'duration',
127
- 'after',
128
- 'before',
129
- 'remaining',
130
- 'link',
131
- 'description',
132
- 'owner',
133
- ]),
134
- milestone: new Set(['date', 'after', 'link', 'description']),
135
- anchor: new Set(['date', 'link', 'description']),
136
- footnote: new Set(['on', 'link', 'description']),
137
- label: new Set(['link', 'description']),
138
- swimlane: new Set(['capacity']),
139
- roadmap: new Set(),
140
- parallel: new Set(),
141
- group: new Set(),
142
- };
143
- // Properties every entity declaration may carry (`specs/dsl.md` § Universal Properties).
144
- // `description` is technically a sub-directive (`description "text"` indented under the
145
- // entity), not an EntityProperty, but we accept it here too: authors who type
146
- // `description:"text"` as a property aren't doing anything meaningful, but the typo is
147
- // common enough that warning on it adds noise rather than signal — the value is at
148
- // least carried into the AST and could be surfaced later if we choose to.
149
- const UNIVERSAL_ENTITY_PROPS = new Set(['labels', 'link', 'style', 'description']);
150
- // Properties each entity declaration's `properties: EntityProperty[]` bag actually
151
- // consumes downstream. Sourced from (a) the property tables in `specs/dsl.md` and
152
- // (b) every `propValue(...)`/`propValues(...)` call site in `packages/layout/`. Keys
153
- // outside this set + `UNIVERSAL_ENTITY_PROPS` are silently dropped by the layout —
154
- // `checkUnknownEntityProperties` warns on them so authors notice typos like
155
- // `now:2026-01-25` on a `roadmap` line.
156
- //
157
- // Raw style props (`bg`, `fg`, ...) intentionally stay OUT of this map — they are
158
- // rejected as errors by `checkNoRawStyleProperties` and the unknown-property check
159
- // short-circuits on them so authors don't see a duplicate diagnostic.
160
- const ENTITY_KNOWN_PROPS = {
161
- RoadmapDeclaration: new Set([
162
- 'author',
163
- 'start',
164
- 'length',
165
- 'scale',
166
- 'calendar',
167
- 'logo',
168
- 'logo-size',
169
- ]),
170
- AnchorDeclaration: new Set(['date']),
171
- SwimlaneDeclaration: new Set([
172
- 'owner',
173
- 'capacity',
174
- 'utilization-warn-at',
175
- 'utilization-over-at',
176
- 'status',
177
- 'after',
178
- 'before',
179
- ]),
180
- // `date:` and `start:` on items are read by `packages/layout/src/layout.ts`
181
- // (`resolveChildStart`, `walkNode`) to pin an item to a fixed start date. Not
182
- // documented in `specs/dsl.md` yet — left allow-listed so authors don't see
183
- // a spurious warning for a working code path. See plan's out-of-scope note.
184
- ItemDeclaration: new Set([
185
- 'size',
186
- 'duration',
187
- 'status',
188
- 'owner',
189
- 'after',
190
- 'before',
191
- 'remaining',
192
- 'capacity',
193
- 'date',
194
- 'start',
195
- ]),
196
- // size/duration/remaining/capacity on parallel/group are already errors via
197
- // `checkNoComputedProperties`, so we don't list them here.
198
- ParallelBlock: new Set(['owner', 'after', 'before', 'status']),
199
- GroupBlock: new Set(['owner', 'after', 'before', 'status']),
200
- MilestoneDeclaration: new Set(['date', 'after']),
201
- FootnoteDeclaration: new Set(['on']),
202
- PersonDeclaration: new Set(),
203
- TeamDeclaration: new Set(),
204
- LabelDeclaration: new Set(),
205
- SizeDeclaration: new Set(['effort']),
206
- StatusDeclaration: new Set(),
207
- };
208
- // Levenshtein distance with an early-exit cap: returns `cap + 1` once the running
209
- // minimum exceeds the cap so we can short-circuit the matcher in the common case
210
- // where the typo is much further than 2 edits from any valid key. The helper is
211
- // only used by `checkUnknownEntityProperties` for the "did you mean?" suggestion.
212
- function levenshteinCapped(a, b, cap) {
213
- if (a === b)
214
- return 0;
215
- const an = a.length;
216
- const bn = b.length;
217
- if (Math.abs(an - bn) > cap)
218
- return cap + 1;
219
- if (an === 0)
220
- return bn;
221
- if (bn === 0)
222
- return an;
223
- let prev = new Array(bn + 1);
224
- let curr = new Array(bn + 1);
225
- for (let j = 0; j <= bn; j++)
226
- prev[j] = j;
227
- for (let i = 1; i <= an; i++) {
228
- curr[0] = i;
229
- let rowMin = i;
230
- for (let j = 1; j <= bn; j++) {
231
- const cost = a.charCodeAt(i - 1) === b.charCodeAt(j - 1) ? 0 : 1;
232
- curr[j] = Math.min(prev[j] + 1, // deletion
233
- curr[j - 1] + 1, // insertion
234
- prev[j - 1] + cost);
235
- if (curr[j] < rowMin)
236
- rowMin = curr[j];
237
- }
238
- if (rowMin > cap)
239
- return cap + 1;
240
- const tmp = prev;
241
- prev = curr;
242
- curr = tmp;
243
- }
244
- return prev[bn];
245
- }
246
- // Pick the closest known key within `cap` edits of `key`, or undefined. Ties are
247
- // broken by the order of `candidates`, so callers should pass entity-specific keys
248
- // first when both lists are searched.
249
- function suggestKey(key, candidates, cap = 2) {
250
- let best;
251
- let bestDist = cap + 1;
252
- for (const c of candidates) {
253
- const d = levenshteinCapped(key, c, cap);
254
- if (d < bestDist) {
255
- best = c;
256
- bestDist = d;
257
- if (d === 0)
258
- break;
259
- }
260
- }
261
- return best;
262
- }
263
- // Conceptual mistakes that aren't typos of a real key — e.g. `progress:60` is a
264
- // reasonable guess for "60% done", but Nowline models completion as
265
- // `status:` + `remaining:` (work *left*). Levenshtein can't bridge that gap, so
266
- // we map the concept directly. `requires` names a key the entity must support,
267
- // so the hint only fires where it's actionable (e.g. on an `item`, which has
268
- // `remaining`, not on a `roadmap` line).
269
- const CONCEPT_ALIASES = [
270
- {
271
- keys: new Set(['progress', 'percent', 'percentage', 'pct', 'complete', 'completion']),
272
- requires: 'remaining',
273
- suggest: 'status: + remaining:',
274
- },
275
- ];
276
- // Suggest the canonical property (or combination) for a known conceptual
277
- // mistake, gated to entities that actually support the target key. Returns
278
- // undefined when no concept matches so callers fall back to `suggestKey`.
279
- function suggestConcept(key, known) {
280
- const lower = key.toLowerCase();
281
- for (const alias of CONCEPT_ALIASES) {
282
- if (alias.keys.has(lower) && known.has(alias.requires))
283
- return alias.suggest;
284
- }
285
- return undefined;
286
- }
287
- function propKey(prop) {
288
- return prop.key.endsWith(':') ? prop.key.slice(0, -1) : prop.key;
289
- }
290
- // Matches duration literals including decimals, e.g. `2w`, `0.5d`, `1.5m`.
291
- const DURATION_RE = /^\d+(?:\.\d+)?[dwmqy]$/;
292
- const PERCENTAGE_RE = /^\d+%$/;
293
- const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
294
- const HEX_COLOR_RE = /^#[0-9a-fA-F]{3,8}$/;
295
- const VERSION_RE = /^v\d+$/;
296
- const INTEGER_RE = /^\d+$/;
297
- const BARE_DURATION_SUFFIX_RE = /^[dwmqy]$/;
298
- // Capacity numeric forms — the grammar already separates DECIMAL/INTEGER/PERCENTAGE
299
- // terminals, but the validator needs to enforce the spec's "positive number" rule
300
- // and to differentiate where percent is allowed (item) vs. banned (swimlane).
301
- const POSITIVE_NUMBER_RE = /^\d+(\.\d+)?$/;
302
- const POSITIVE_PERCENT_RE = /^\d+(\.\d+)?%$/;
303
- // Disambiguated forms used by `utilization-warn-at:` / `utilization-over-at:`.
304
- // A decimal-fraction MUST include the dot so its meaning is unambiguous; a
305
- // bare integer matches the integer regex and is rejected by the validator
306
- // with a hint to switch to either the percent or decimal-fraction form.
307
- const POSITIVE_DECIMAL_FRACTION_RE = /^\d+\.\d+$/;
308
- const POSITIVE_INTEGER_RE = /^\d+$/;
309
- // ASCII printable, length 1-3 — used by the glyph declaration validator for the
310
- // `ascii:"..."` fallback property after Langium has stripped the surrounding quotes.
311
- const ASCII_FALLBACK_RE = /^[\x20-\x7E]{1,3}$/;
312
- // BCP-47 language tag, simplified to the subset Nowline cares about: a 2- or 3-letter
313
- // primary language subtag followed by an optional region subtag (2 letters or 3 digits).
314
- // Permissive enough for `fr`, `fr-CA`, `zh-CN`, `es-419` while rejecting obvious typos.
315
- // The runtime resolver does the actual fallback work; this regex just gates input shape.
316
- const BCP47_RE = /^[a-zA-Z]{2,3}(-[a-zA-Z]{2}|-\d{3})?$/;
317
- const INCLUDE_MODES = new Set(['merge', 'ignore', 'isolate']);
318
- // Allow-listed property keys on the `nowline` directive line. The directive existed
319
- // historically as `nowline v1` only; properties are a forward-extension point but stay
320
- // restrictive so authors get an early error instead of typos rendering silently.
321
- const DIRECTIVE_FIELDS = new Set(['locale']);
322
- function resolveLocalStart(file) {
323
- const prop = file?.roadmapDecl?.properties.find((p) => propKey(p) === 'start');
324
- if (!prop)
325
- return { kind: 'missing' };
326
- const raw = prop.value;
327
- if (!raw || !DATE_RE.test(raw))
328
- return { kind: 'invalid' };
329
- const d = new Date(raw);
330
- if (Number.isNaN(d.getTime()))
331
- return { kind: 'invalid' };
332
- return { kind: 'valid', iso: raw, date: d };
333
- }
334
- function displayName(node) {
335
- return node.name ?? node.title ?? '<unnamed>';
336
- }
337
- /**
338
- * Returns the lowercase entity-type label for an AST node, suitable for
339
- * embedding inside a validator message (e.g. `"item"`, `"milestone"`,
340
- * `"swimlane"`). Mirrors `describeNode`'s normalization (strip
341
- * `Declaration` / `Block` suffix, lowercase) but returns just the type so
342
- * callers can compose their own message.
343
- */
344
- function entityTypeLabel(node) {
345
- return node.$type.replace(/Declaration$|Block$/, '').toLowerCase();
346
- }
347
- function acceptTr(accept, severity, info, code, ...args) {
348
- accept(severity, tr('en-US', code, ...args), {
349
- ...info,
350
- data: { code, args },
351
- });
352
- }
1
+ import { isSwimlaneDeclaration } from '../generated/ast.js';
2
+ import * as calendar from './validator/calendar.js';
3
+ import * as entities from './validator/entities.js';
4
+ import * as properties from './validator/properties.js';
5
+ import * as references from './validator/references.js';
6
+ import * as structure from './validator/structure.js';
7
+ import * as style from './validator/style.js';
8
+ import { acceptWaveFinding } from './validator/support.js';
9
+ import * as symbols from './validator/symbols.js';
10
+ import { checkWaveDeclarations, evaluateWaveProperties, fileRefLookup, ownWaves } from './waves.js';
11
+ import { evaluateWaveOrder } from './waves-order.js';
353
12
  export function registerValidationChecks(services) {
354
13
  const registry = services.validation.ValidationRegistry;
355
14
  const validator = services.validation.NowlineValidator;
@@ -364,11 +23,15 @@ export function registerValidationChecks(services) {
364
23
  validator.checkReferenceResolution,
365
24
  validator.checkInlineDatePins,
366
25
  validator.checkCircularDependencies,
26
+ validator.checkWaves,
367
27
  validator.checkDuplicateSizeIds,
368
28
  validator.checkCalendarBlockConsistency,
29
+ validator.checkHiddenTimelineStrip,
369
30
  validator.checkPersonDeclarations,
370
31
  validator.checkDuplicateSymbolIds,
371
32
  validator.checkSymbolReferences,
33
+ validator.checkCalendarWeek,
34
+ validator.checkDuplicateCalendarDeclarationIds,
372
35
  ],
373
36
  NowlineDirective: [validator.checkDirectiveVersion, validator.checkDirectiveProperties],
374
37
  IncludeOption: [validator.checkIncludeMode],
@@ -445,6 +108,10 @@ export function registerValidationChecks(services) {
445
108
  StyleDeclaration: [validator.checkEntityIdOrTitle],
446
109
  StyleProperty: [validator.checkStylePropertyEnum],
447
110
  SymbolDeclaration: [validator.checkEntityIdOrTitle, validator.checkSymbolDeclaration],
111
+ // No checkEntityIdOrTitle: an id-less, title-less declaration is valid. The own-key
112
+ // check replaces checkUnknownEntityProperties, which skips `wave:` and style keys.
113
+ NonWorkingDeclaration: [validator.checkCalendarDeclaration],
114
+ WorkingDeclaration: [validator.checkCalendarDeclaration],
448
115
  LabelDeclaration: [
449
116
  validator.checkEntityIdOrTitle,
450
117
  validator.checkNoRawStyleProperties,
@@ -462,6 +129,13 @@ export function registerValidationChecks(services) {
462
129
  validator.checkNoRawStyleProperties,
463
130
  validator.checkUnknownEntityProperties,
464
131
  ],
132
+ // No checkEntityIdOrTitle: a wave without an id is NL.E1100, not NL.E0301.
133
+ // The S rules run file-wide in checkWaves (one shared id lookup).
134
+ WaveDeclaration: [
135
+ validator.checkNoRawStyleProperties,
136
+ validator.checkNoFootnoteProperty,
137
+ validator.checkUnknownEntityProperties,
138
+ ],
465
139
  DefaultDeclaration: [validator.checkDefaultDeclaration, validator.checkUtilizationOrdering],
466
140
  CalendarBlock: [validator.checkCalendarBlock],
467
141
  ScaleBlock: [validator.checkScaleBlock],
@@ -469,1326 +143,158 @@ export function registerValidationChecks(services) {
469
143
  registry.register(checks, validator);
470
144
  }
471
145
  export class NowlineValidator {
472
- // --- Structural Rule 4: Section order ---
473
146
  checkFileStructure(file, accept) {
474
- // Use CST-aware lookup so the `config:` / `roadmap:` substrings inside
475
- // INCLUDE_OPTION_KEY tokens (e.g. `config:isolate`) aren't mistaken for
476
- // the top-level `config` section marker. See issue #1.
477
- const configOffset = file.hasConfig
478
- ? GrammarUtils.findNodeForKeyword(file.$cstNode, 'config')?.offset
479
- : undefined;
480
- const roadmapOffset = file.roadmapDecl?.$cstNode?.offset;
481
- if (configOffset !== undefined &&
482
- roadmapOffset !== undefined &&
483
- configOffset > roadmapOffset) {
484
- acceptTr(accept, 'error', { node: file, property: 'hasConfig' }, 'NL.E0001');
485
- }
486
- for (const inc of file.includes) {
487
- const incOffset = inc.$cstNode?.offset ?? 0;
488
- if (configOffset !== undefined && incOffset > configOffset) {
489
- acceptTr(accept, 'error', { node: inc }, 'NL.E0002');
490
- }
491
- if (roadmapOffset !== undefined && incOffset > roadmapOffset) {
492
- acceptTr(accept, 'error', { node: inc }, 'NL.E0003');
493
- }
494
- }
147
+ structure.checkFileStructure(file, accept);
495
148
  }
496
- // --- Structural Rules 8/9/10: label/duration/status must live in roadmap section ---
497
- // Parser enforces this by construction (these keywords are only valid as RoadmapEntry),
498
- // so we mainly need to forbid custom statuses referenced before their declaration (rule 15).
499
149
  checkRoadmapOnlyKeywordsPosition(_file, _accept) {
500
- // No-op: the grammar places label/duration/status under RoadmapEntry.
501
- // Any attempt to declare them before `roadmap` surfaces as a parse error.
150
+ structure.checkRoadmapOnlyKeywordsPosition(_file, _accept);
502
151
  }
503
- // --- Rule 5: Directive version ---
504
152
  checkDirectiveVersion(directive, accept) {
505
- if (!VERSION_RE.test(directive.version)) {
506
- acceptTr(accept, 'error', { node: directive, property: 'version' }, 'NL.E0100', {
507
- version: directive.version,
508
- });
509
- return;
510
- }
511
- const num = parseInt(directive.version.slice(1), 10);
512
- const supportedNum = parseInt(SUPPORTED_VERSION.slice(1), 10);
513
- if (num > supportedNum) {
514
- acceptTr(accept, 'error', { node: directive, property: 'version' }, 'NL.E0101', {
515
- version: directive.version,
516
- supported: SUPPORTED_VERSION,
517
- });
518
- }
153
+ structure.checkDirectiveVersion(directive, accept);
519
154
  }
520
- // --- Directive properties (locale) ---
521
- // Validates the optional key:value pairs on the `nowline` directive line. Today the
522
- // only allowed key is `locale:` (BCP-47 tag); unknown keys are rejected so typos
523
- // surface immediately. Duplicate keys are also rejected.
524
155
  checkDirectiveProperties(directive, accept) {
525
- const seen = new Set();
526
- for (const prop of directive.properties) {
527
- const key = propKey(prop);
528
- if (!DIRECTIVE_FIELDS.has(key)) {
529
- acceptTr(accept, 'error', { node: prop, property: 'key' }, 'NL.E0102', {
530
- key,
531
- allowed: [...DIRECTIVE_FIELDS].join(', '),
532
- });
533
- continue;
534
- }
535
- if (seen.has(key)) {
536
- acceptTr(accept, 'error', { node: prop, property: 'key' }, 'NL.E0103', { key });
537
- }
538
- seen.add(key);
539
- if (key === 'locale') {
540
- const raw = prop.value;
541
- if (!BCP47_RE.test(raw)) {
542
- acceptTr(accept, 'error', { node: prop, property: 'value' }, 'NL.E0104', {
543
- value: raw,
544
- });
545
- }
546
- }
547
- }
156
+ structure.checkDirectiveProperties(directive, accept);
548
157
  }
549
- // --- Rule 3: Id or title required ---
550
158
  checkEntityIdOrTitle(node, accept) {
551
- if (!node.name && !node.title) {
552
- acceptTr(accept, 'error', { node }, 'NL.E0301', { type: node.$type });
553
- }
159
+ structure.checkEntityIdOrTitle(node, accept);
554
160
  }
555
- // --- Rule 2: Unique identifiers ---
556
161
  checkUniqueIdentifiers(file, accept) {
557
- const seen = new Map();
558
- const register = (name, node) => {
559
- if (!name)
560
- return;
561
- const existing = seen.get(name);
562
- if (existing) {
563
- acceptTr(accept, 'error', { node }, 'NL.E0300', {
564
- name,
565
- location: locationOf(existing),
566
- });
567
- }
568
- else {
569
- seen.set(name, node);
570
- }
571
- };
572
- if (file.roadmapDecl?.name) {
573
- register(file.roadmapDecl.name, file.roadmapDecl);
574
- }
575
- for (const entry of file.roadmapEntries) {
576
- registerEntity(entry, register);
577
- }
578
- for (const entry of file.configEntries) {
579
- if (isStyleDeclaration(entry) && entry.name) {
580
- register(entry.name, entry);
581
- }
582
- }
162
+ structure.checkUniqueIdentifiers(file, accept);
583
163
  }
584
- // --- Rule 7: Mixed tabs and spaces in indentation ---
585
164
  checkIndentationConsistency(file, accept) {
586
- const text = file.$document?.textDocument.getText() ?? file.$cstNode?.text;
587
- if (!text)
588
- return;
589
- const lines = text.split(/\r?\n/);
590
- for (let i = 0; i < lines.length; i++) {
591
- const line = lines[i];
592
- if (line.length === 0)
593
- continue;
594
- const match = line.match(/^([\t ]+)/);
595
- if (!match)
596
- continue;
597
- const indent = match[1];
598
- if (indent.includes('\t') && indent.includes(' ')) {
599
- acceptTr(accept, 'error', { node: file }, 'NL.E0005', { line: i + 1 });
600
- return;
601
- }
602
- }
165
+ structure.checkIndentationConsistency(file, accept);
603
166
  }
604
- // --- Rule 6: At least one swimlane ---
605
167
  checkSwimlaneRequired(file, accept) {
606
- const hasSwimlane = file.roadmapEntries.some(isSwimlaneDeclaration);
607
- if (file.roadmapDecl && !hasSwimlane) {
608
- acceptTr(accept, 'error', { node: file.roadmapDecl }, 'NL.E0004');
609
- }
168
+ structure.checkSwimlaneRequired(file, accept);
610
169
  }
611
- // --- Include rules 5/6: mode values ---
612
170
  checkIncludeMode(option, accept) {
613
- if (!INCLUDE_MODES.has(option.value)) {
614
- acceptTr(accept, 'error', { node: option, property: 'value' }, 'NL.E0200', {
615
- value: option.value,
616
- });
617
- }
171
+ structure.checkIncludeMode(option, accept);
618
172
  }
619
- // --- Include rule 4 (partial): Duplicate include options ---
620
173
  checkIncludeDuplicateOptions(inc, accept) {
621
- const keys = new Set();
622
- for (const opt of inc.options) {
623
- const normalized = opt.key.replace(/:$/, '');
624
- if (keys.has(normalized)) {
625
- acceptTr(accept, 'error', { node: opt }, 'NL.E0201', { key: normalized });
626
- }
627
- keys.add(normalized);
628
- }
174
+ structure.checkIncludeDuplicateOptions(inc, accept);
629
175
  }
630
- // --- Property value validation (general) ---
631
176
  checkPropertyValues(prop, accept) {
632
- const key = propKey(prop);
633
- const val = prop.value;
634
- const vals = prop.values;
635
- const allValues = val ? [val] : vals;
636
- switch (key) {
637
- case 'status':
638
- // Forward/resolution validated at file scope (checkForwardReferences).
639
- break;
640
- case 'duration':
641
- // `duration:` is literal-only — no alias lookup. Authors who
642
- // want a named alias use `size:NAME` instead, which resolves
643
- // to the size's `effort:` (and divides by `capacity:` at
644
- // layout time, m5).
645
- if (val && !DURATION_RE.test(val)) {
646
- acceptTr(accept, 'error', { node: prop, property: 'value' }, 'NL.E0400', {
647
- value: val,
648
- });
649
- }
650
- break;
651
- case 'size':
652
- if (val && !isIdentifier(val)) {
653
- acceptTr(accept, 'error', { node: prop, property: 'value' }, 'NL.E0401', {
654
- value: val,
655
- });
656
- }
657
- break;
658
- case 'effort':
659
- if (val && !DURATION_RE.test(val)) {
660
- acceptTr(accept, 'error', { node: prop, property: 'value' }, 'NL.E0402', {
661
- value: val,
662
- });
663
- }
664
- break;
665
- case 'remaining': {
666
- // Accepts either a percent (`30%`, validated 0-100) or a
667
- // single-engineer effort literal (`1w`, `0.5d`). The literal
668
- // form is normalized to a percent at layout time using the
669
- // item's resolved total effort (m5); overflow there emits a
670
- // soft warning and clamps the rendered bar to 100%.
671
- if (val) {
672
- if (PERCENTAGE_RE.test(val)) {
673
- const pct = parseFloat(val);
674
- if (pct < 0 || pct > 100) {
675
- acceptTr(accept, 'error', { node: prop, property: 'value' }, 'NL.E0404', { value: val });
676
- }
677
- }
678
- else if (!DURATION_RE.test(val)) {
679
- acceptTr(accept, 'error', { node: prop, property: 'value' }, 'NL.E0403', {
680
- value: val,
681
- });
682
- }
683
- }
684
- break;
685
- }
686
- case 'date':
687
- case 'start':
688
- if (val && (!DATE_RE.test(val) || Number.isNaN(new Date(val).getTime()))) {
689
- acceptTr(accept, 'error', { node: prop, property: 'value' }, 'NL.E0405', {
690
- key,
691
- value: val,
692
- });
693
- }
694
- break;
695
- case 'scale':
696
- if (val && !DURATION_RE.test(val)) {
697
- acceptTr(accept, 'error', { node: prop, property: 'value' }, 'NL.E0406', {
698
- value: val,
699
- });
700
- }
701
- break;
702
- case 'calendar':
703
- if (val && !CALENDAR_MODES.has(val)) {
704
- acceptTr(accept, 'error', { node: prop, property: 'value' }, 'NL.E0407', {
705
- value: val,
706
- });
707
- }
708
- break;
709
- case 'on':
710
- case 'after':
711
- case 'before':
712
- if (allValues.length === 0) {
713
- acceptTr(accept, 'error', { node: prop }, 'NL.E0408', { key });
714
- }
715
- break;
716
- case 'capacity': {
717
- if (!val)
718
- break;
719
- const parent = prop.$container;
720
- const parentKind = capacityParentKind(parent);
721
- // Parallel/group ban is reported by checkNoComputedProperties; skip here.
722
- if (parentKind === 'invalid')
723
- break;
724
- if (parentKind === 'lane') {
725
- if (!POSITIVE_NUMBER_RE.test(val) || parseFloat(val) <= 0) {
726
- accept('error', `Invalid swimlane capacity "${val}". Use a positive integer (e.g. capacity:5) or decimal (e.g. capacity:1.5). Percent literals are not allowed on swimlanes.`, { node: prop, property: 'value' });
727
- }
728
- }
729
- else {
730
- if (POSITIVE_PERCENT_RE.test(val)) {
731
- const pct = parseFloat(val);
732
- if (pct <= 0) {
733
- accept('error', `Item capacity "${val}" must be positive.`, {
734
- node: prop,
735
- property: 'value',
736
- });
737
- }
738
- }
739
- else if (POSITIVE_NUMBER_RE.test(val)) {
740
- if (parseFloat(val) <= 0) {
741
- accept('error', `Item capacity "${val}" must be positive.`, {
742
- node: prop,
743
- property: 'value',
744
- });
745
- }
746
- }
747
- else {
748
- accept('error', `Invalid item capacity "${val}". Use a positive integer (capacity:2), decimal (capacity:0.5), or percent literal (capacity:50%).`, { node: prop, property: 'value' });
749
- }
750
- }
751
- break;
752
- }
753
- case 'overcapacity': {
754
- // Removed in m9. Suppression is now expressed via
755
- // `utilization-warn-at:none` / `utilization-over-at:none`
756
- // (see specs/dsl.md § Capacity → Utilization thresholds).
757
- accept('error', `"overcapacity:" was removed. Use "utilization-over-at:none" (and/or "utilization-warn-at:none") to suppress the lane utilization underline.`, { node: prop });
758
- break;
759
- }
760
- case 'utilization-warn-at':
761
- case 'utilization-over-at': {
762
- if (!val)
763
- break;
764
- if (!isUtilizationAllowedHere(prop.$container)) {
765
- accept('error', `"${key}:" is only valid on "swimlane" or "default swimlane".`, { node: prop });
766
- break;
767
- }
768
- if (val === UTILIZATION_NONE)
769
- break;
770
- if (POSITIVE_PERCENT_RE.test(val)) {
771
- if (parseFloat(val) <= 0) {
772
- accept('error', `${key} value "${val}" must be positive.`, {
773
- node: prop,
774
- property: 'value',
775
- });
776
- }
777
- break;
778
- }
779
- // Decimals must include the dot to read as fractions; bare
780
- // integers are ambiguous (`80` could mean 80% or 8000% as a
781
- // fraction) so we reject them with a hint to disambiguate.
782
- if (POSITIVE_DECIMAL_FRACTION_RE.test(val)) {
783
- if (parseFloat(val) <= 0) {
784
- accept('error', `${key} value "${val}" must be positive.`, {
785
- node: prop,
786
- property: 'value',
787
- });
788
- }
789
- break;
790
- }
791
- if (POSITIVE_INTEGER_RE.test(val)) {
792
- accept('error', `Ambiguous ${key} value "${val}". Use the percent form ("${val}%") or the decimal-fraction form ("0.${val}") to make the intent explicit.`, { node: prop, property: 'value' });
793
- break;
794
- }
795
- accept('error', `Invalid ${key} value "${val}". Use a positive percent (e.g. 80%), a positive decimal fraction (e.g. 0.8), or "none" to opt out.`, { node: prop, property: 'value' });
796
- break;
797
- }
798
- case 'capacity-icon':
799
- // Value-form rule (built-in / symbol id / string literal) and
800
- // forward-reference rule are enforced together by
801
- // checkSymbolReferences at file scope so style blocks and
802
- // default-declaration property positions share one code path.
803
- break;
804
- case 'icon':
805
- // Same handling as capacity-icon.
806
- break;
807
- default:
808
- if (STYLE_PROP_KEYS.has(key)) {
809
- if (key === 'bg' || key === 'fg' || key === 'text') {
810
- if (val && !isColorValue(val)) {
811
- accept('error', `Invalid color "${val}" for "${key}". Use a named color, hex value, or "none".`, {
812
- node: prop,
813
- property: 'value',
814
- });
815
- }
816
- }
817
- else if (key in STYLE_PROP_ENUMS) {
818
- const allowed = STYLE_PROP_ENUMS[key];
819
- if (val && !allowed.has(val) && !isColorValue(val)) {
820
- accept('error', `Invalid value "${val}" for "${key}". Allowed: ${[...allowed].join(', ')}.`, {
821
- node: prop,
822
- property: 'value',
823
- });
824
- }
825
- }
826
- }
827
- break;
828
- }
177
+ properties.checkPropertyValues(prop, accept);
829
178
  }
830
- // --- Rule 11: Anchor requires date: ---
831
179
  checkAnchorRequiredDate(anchor, accept) {
832
- const dateProp = anchor.properties.find((p) => propKey(p) === 'date');
833
- if (!dateProp) {
834
- acceptTr(accept, 'error', { node: anchor }, 'NL.E0500', { name: displayName(anchor) });
835
- }
180
+ entities.checkAnchorRequiredDate(anchor, accept);
836
181
  }
837
- // --- R2 + R3: anchor must not precede roadmap start; dated roadmap requires start: ---
838
182
  checkAnchorAgainstStart(anchor, accept) {
839
- const dateProp = anchor.properties.find((p) => propKey(p) === 'date');
840
- if (!dateProp?.value)
841
- return;
842
- const raw = dateProp.value;
843
- if (!DATE_RE.test(raw))
844
- return;
845
- const anchorDate = new Date(raw);
846
- if (Number.isNaN(anchorDate.getTime()))
847
- return;
848
- const start = resolveLocalStart(anchor.$container);
849
- switch (start.kind) {
850
- case 'invalid':
851
- return;
852
- case 'missing':
853
- acceptTr(accept, 'error', { node: dateProp, property: 'value' }, 'NL.E0501', {
854
- name: displayName(anchor),
855
- });
856
- return;
857
- case 'valid':
858
- if (anchorDate < start.date) {
859
- acceptTr(accept, 'error', { node: dateProp, property: 'value' }, 'NL.E0502', {
860
- name: displayName(anchor),
861
- date: raw,
862
- start: start.iso,
863
- });
864
- }
865
- return;
866
- }
183
+ entities.checkAnchorAgainstStart(anchor, accept);
867
184
  }
868
- // --- Rule 12: Milestone requires date: or after: ---
869
185
  checkMilestoneRequirement(milestone, accept) {
870
- const hasDate = milestone.properties.some((p) => propKey(p) === 'date');
871
- const hasAfter = milestone.properties.some((p) => propKey(p) === 'after');
872
- if (!hasDate && !hasAfter) {
873
- acceptTr(accept, 'error', { node: milestone }, 'NL.E0503', {
874
- name: displayName(milestone),
875
- });
876
- }
186
+ entities.checkMilestoneRequirement(milestone, accept);
877
187
  }
878
- // --- R2 + R3: dated milestone must not precede roadmap start ---
879
188
  checkMilestoneAgainstStart(milestone, accept) {
880
- const dateProp = milestone.properties.find((p) => propKey(p) === 'date');
881
- if (!dateProp?.value)
882
- return;
883
- const raw = dateProp.value;
884
- if (!DATE_RE.test(raw))
885
- return;
886
- const milestoneDate = new Date(raw);
887
- if (Number.isNaN(milestoneDate.getTime()))
888
- return;
889
- const start = resolveLocalStart(milestone.$container);
890
- switch (start.kind) {
891
- case 'invalid':
892
- return;
893
- case 'missing':
894
- accept('error', `Milestone "${displayName(milestone)}" has a date but the roadmap is missing "start:". Add start:YYYY-MM-DD to the roadmap.`, {
895
- node: dateProp,
896
- property: 'value',
897
- });
898
- return;
899
- case 'valid':
900
- if (milestoneDate < start.date) {
901
- acceptTr(accept, 'error', { node: dateProp, property: 'value' }, 'NL.E0504', {
902
- name: displayName(milestone),
903
- date: raw,
904
- start: start.iso,
905
- });
906
- }
907
- return;
908
- }
189
+ entities.checkMilestoneAgainstStart(milestone, accept);
909
190
  }
910
- // --- Rule 13: Footnote requires on ---
911
191
  checkFootnoteOn(footnote, accept) {
912
- const hasOn = footnote.properties.some((p) => propKey(p) === 'on');
913
- if (!hasOn) {
914
- acceptTr(accept, 'error', { node: footnote }, 'NL.E0505');
915
- }
192
+ entities.checkFootnoteOn(footnote, accept);
916
193
  }
917
- // --- Rule 13a: `footnote:` is not a valid property on host entities ---
918
- // The spec attaches footnotes via the `on:` property on the footnote
919
- // declaration only; there is no forward `footnote:` property on the
920
- // referenced item / swimlane / etc. Surface a fix-it style error so
921
- // authors who reach for the (legacy, undocumented) forward form get
922
- // a clear nudge toward the spec-mandated direction.
923
194
  checkNoFootnoteProperty(node, accept) {
924
- for (const prop of node.properties) {
925
- if (propKey(prop) === 'footnote') {
926
- accept('error', `Property "footnote:" is not valid on ${describeNode(node)}. ` +
927
- 'Footnotes attach via "on:" on the footnote declaration — ' +
928
- 'declare `footnote <id> on:<target-id>` instead.', { node: prop });
929
- }
930
- }
195
+ entities.checkNoFootnoteProperty(node, accept);
931
196
  }
932
- // --- Rule 10: Item requires either size: or duration: ---
933
197
  checkItemRequiredDuration(item, accept) {
934
- const hasDuration = item.properties.some((p) => propKey(p) === 'duration');
935
- const hasSize = item.properties.some((p) => propKey(p) === 'size');
936
- if (!hasDuration && !hasSize) {
937
- acceptTr(accept, 'error', { node: item }, 'NL.E0600', { name: displayName(item) });
938
- }
198
+ entities.checkItemRequiredDuration(item, accept);
939
199
  }
940
- // --- Parallel/group rule 3: size/duration/remaining/capacity not valid on parallel/group ---
941
200
  checkNoComputedProperties(node, accept) {
942
- for (const prop of node.properties) {
943
- const key = propKey(prop);
944
- if (key === 'size' || key === 'duration' || key === 'remaining' || key === 'capacity') {
945
- accept('error', `"${key}" is not valid on ${node.$type === 'ParallelBlock' ? 'parallel' : 'group'} (computed from children).`, {
946
- node: prop,
947
- });
948
- }
949
- }
201
+ entities.checkNoComputedProperties(node, accept);
950
202
  }
951
- // --- Parallel/group rule 1: Parallel requires >= 2 children ---
952
203
  checkParallelMinChildren(node, accept) {
953
- const children = node.content.filter((c) => !isDescriptionDirective(c));
954
- if (children.length === 0) {
955
- accept('error', 'Parallel block must contain at least 2 children.', { node });
956
- }
957
- else if (children.length === 1) {
958
- accept('warning', 'Parallel block has only 1 child. Use at least 2 for parallel execution.', { node });
959
- }
204
+ entities.checkParallelMinChildren(node, accept);
960
205
  }
961
- // --- Parallel/group rule 2: Group requires >= 1 child ---
962
206
  checkGroupMinChildren(node, accept) {
963
- const children = node.content.filter((c) => !isDescriptionDirective(c));
964
- if (children.length === 0) {
965
- accept('error', 'Group must contain at least 1 child.', { node });
966
- }
207
+ entities.checkGroupMinChildren(node, accept);
967
208
  }
968
- // --- Rule 20: Raw style properties banned on roadmap-section entities ---
969
209
  checkNoRawStyleProperties(node, accept) {
970
- for (const prop of node.properties) {
971
- const key = propKey(prop);
972
- if (STYLE_PROP_KEYS.has(key)) {
973
- accept('error', `Raw style property "${key}" is not allowed on ${describeNode(node)}. ` +
974
- `Declare a named style in config and reference it via "style:id".`, { node: prop });
975
- }
976
- }
210
+ properties.checkNoRawStyleProperties(node, accept);
977
211
  }
978
- // Warn on property keys the runtime never reads. Severity is `warning` so a
979
- // file that happened to render with a bogus key (e.g. `roadmap r now:2026-01-25`)
980
- // keeps parsing — promoting to error would break files that work today even
981
- // though the bogus key was a no-op all along.
982
- //
983
- // Skips:
984
- // - raw style keys (already an error from `checkNoRawStyleProperties`)
985
- // - `footnote` (already an error from `checkNoFootnoteProperty`)
986
- // - sizing keys on parallel/group (already an error from `checkNoComputedProperties`)
987
- //
988
- // Suggests the closest known key within 2 edits when one exists, so the
989
- // existing `DID_YOU_MEAN_RE` in `packages/cli/src/diagnostics/adapt.ts` picks
990
- // it up as a structured suggestion alongside the rendered message.
991
212
  checkUnknownEntityProperties(node, accept) {
992
- const known = ENTITY_KNOWN_PROPS[node.$type];
993
- if (!known)
994
- return;
995
- const computedBanned = node.$type === 'ParallelBlock' || node.$type === 'GroupBlock'
996
- ? new Set(['size', 'duration', 'remaining', 'capacity'])
997
- : null;
998
- for (const prop of node.properties) {
999
- const key = propKey(prop);
1000
- if (known.has(key))
1001
- continue;
1002
- if (UNIVERSAL_ENTITY_PROPS.has(key))
1003
- continue;
1004
- if (STYLE_PROP_KEYS.has(key))
1005
- continue;
1006
- if (key === 'footnote')
1007
- continue;
1008
- if (computedBanned?.has(key))
1009
- continue;
1010
- const candidates = [...known, ...UNIVERSAL_ENTITY_PROPS];
1011
- const suggested = suggestConcept(key, known) ?? suggestKey(key, candidates) ?? '';
1012
- acceptTr(accept, 'warning', { node: prop, property: 'key' }, 'NL.W0700', {
1013
- key,
1014
- entity: describeNode(node),
1015
- suggested,
1016
- });
1017
- }
213
+ properties.checkUnknownEntityProperties(node, accept);
1018
214
  }
1019
- // --- Roadmap declaration specific property checks ---
1020
- // Property-level validation of start:/date: lives in the generic EntityProperty check;
1021
- // this hook is kept for future roadmap-scoped rules (and to make registration symmetric).
1022
215
  checkRoadmapProperties(_roadmap, _accept) {
1023
- // intentionally empty
216
+ properties.checkRoadmapProperties(_roadmap, _accept);
1024
217
  }
1025
- // --- Rule 18: Style property enum values ---
1026
- // Value forms accepted by `icon:` and `capacity-icon:` (built-in identifier,
1027
- // symbol name, or inline string literal) plus forward-reference resolution are
1028
- // enforced by checkSymbolReferences at file scope so style blocks and
1029
- // `default <entity>` lines share a single code path.
1030
218
  checkStylePropertyEnum(prop, accept) {
1031
- const key = propKey(prop);
1032
- const val = prop.value;
1033
- if (key === 'bg' || key === 'fg' || key === 'text') {
1034
- if (!isColorValue(val)) {
1035
- accept('error', `Invalid color "${val}" for "${key}". Use a named color, hex value, or "none".`, {
1036
- node: prop,
1037
- property: 'value',
1038
- });
1039
- }
1040
- }
1041
- else if (key in STYLE_PROP_ENUMS) {
1042
- const allowed = STYLE_PROP_ENUMS[key];
1043
- if (!allowed.has(val)) {
1044
- accept('error', `Invalid value "${val}" for "${key}". Allowed: ${[...allowed].join(', ')}.`, {
1045
- node: prop,
1046
- property: 'value',
1047
- });
1048
- }
1049
- }
1050
- else if (!STYLE_PROP_KEYS.has(key)) {
1051
- accept('error', `Unknown style property "${key}".`, {
1052
- node: prop,
1053
- property: 'key',
1054
- });
1055
- }
219
+ properties.checkStylePropertyEnum(prop, accept);
1056
220
  }
1057
- // --- Size declaration: rule 5 (effort: required), rule 4 (id format) ---
1058
221
  checkSizeDeclaration(decl, accept) {
1059
- const effortProp = decl.properties.find((p) => propKey(p) === 'effort');
1060
- if (!effortProp) {
1061
- accept('error', `Size "${displayName(decl)}" requires an "effort:" property.`, {
1062
- node: decl,
1063
- });
1064
- }
1065
- if (decl.name) {
1066
- if (DURATION_RE.test(decl.name) || BARE_DURATION_SUFFIX_RE.test(decl.name)) {
1067
- accept('error', `Size id "${decl.name}" collides with the raw duration pattern. Choose a different name (e.g. "xs", "small", "quarter").`, { node: decl, property: 'name' });
1068
- }
1069
- }
222
+ entities.checkSizeDeclaration(decl, accept);
1070
223
  }
1071
- // --- Status declaration: id collision with built-ins ---
1072
224
  checkStatusDeclaration(decl, accept) {
1073
- if (decl.name) {
1074
- if (BUILTIN_STATUSES.has(decl.name)) {
1075
- accept('error', `Status id "${decl.name}" collides with the built-in status value. Built-ins: ${[...BUILTIN_STATUSES].join(', ')}.`, { node: decl, property: 'name' });
1076
- }
1077
- }
225
+ entities.checkStatusDeclaration(decl, accept);
226
+ }
227
+ // --- Waves (specs/waves.md §6.2): set S (WV1/WV3/WV4, wave declarations),
228
+ // set P (WV5-WV9, `wave:` properties) and, when the roadmap has waves,
229
+ // set G (WV10-WV12) over the file's own lanes in order ---
230
+ checkWaves(file, accept) {
231
+ for (const finding of checkWaveDeclarations(file))
232
+ acceptWaveFinding(accept, finding);
233
+ for (const finding of evaluateWaveProperties(file))
234
+ acceptWaveFinding(accept, finding);
235
+ const waves = ownWaves(file);
236
+ if (waves.length === 0)
237
+ return;
238
+ const scope = {
239
+ lanes: file.roadmapEntries.filter(isSwimlaneDeclaration),
240
+ lookup: fileRefLookup(file),
241
+ };
242
+ for (const finding of evaluateWaveOrder(scope, waves))
243
+ acceptWaveFinding(accept, finding);
1078
244
  }
1079
- // --- Rule 5: Duplicate size ids ---
1080
245
  checkDuplicateSizeIds(file, accept) {
1081
- const seen = new Map();
1082
- for (const entry of file.roadmapEntries) {
1083
- if (isSizeDeclaration(entry) && entry.name) {
1084
- const existing = seen.get(entry.name);
1085
- if (existing) {
1086
- accept('error', `Duplicate size id "${entry.name}". First declared at ${locationOf(existing)}.`, { node: entry, property: 'name' });
1087
- }
1088
- else {
1089
- seen.set(entry.name, entry);
1090
- }
1091
- }
1092
- }
246
+ entities.checkDuplicateSizeIds(file, accept);
1093
247
  }
1094
- // --- Rule 17d (ordering half): utilization-warn-at <= utilization-over-at ---
1095
- // Runs on both `SwimlaneDeclaration` and `DefaultDeclaration` (when its
1096
- // entityType is `swimlane`). The value-form check in checkPropertyValues
1097
- // has already run by the time this fires; this method only re-reads the
1098
- // values and compares fractions when both are numeric. `none` on either
1099
- // side opts that side out and skips the comparison (the spec treats the
1100
- // two thresholds as independent — see specs/dsl.md rule 17d).
1101
248
  checkUtilizationOrdering(decl, accept) {
1102
- if (isDefaultDeclaration(decl) && decl.entityType !== 'swimlane')
1103
- return;
1104
- const warnProp = decl.properties.find((p) => propKey(p) === 'utilization-warn-at');
1105
- const overProp = decl.properties.find((p) => propKey(p) === 'utilization-over-at');
1106
- if (!warnProp || !overProp)
1107
- return;
1108
- const warn = parseUtilizationFraction(warnProp.value);
1109
- const over = parseUtilizationFraction(overProp.value);
1110
- if (warn === null || over === null)
1111
- return;
1112
- if (warn > over) {
1113
- accept('error', `utilization-warn-at (${warnProp.value}) must be ≤ utilization-over-at (${overProp.value}). Warn fires below over; if both fire at the same point, the warn band collapses to zero.`, { node: warnProp, property: 'value' });
1114
- }
249
+ entities.checkUtilizationOrdering(decl, accept);
1115
250
  }
1116
- // --- Defaults rules 21-23: entity-type whitelist, duplicate-per-entity, banned props ---
1117
251
  checkDefaultDeclaration(decl, accept) {
1118
- if (!DEFAULT_ENTITY_TYPES.has(decl.entityType)) {
1119
- accept('error', `"${decl.entityType}" is not a supported entity type for default. Allowed: ${[...DEFAULT_ENTITY_TYPES].join(', ')}.`, { node: decl, property: 'entityType' });
1120
- return;
1121
- }
1122
- // Duplicate default <entity> within the same file.
1123
- const file = decl.$container;
1124
- let firstIdx = -1;
1125
- for (let i = 0; i < file.configEntries.length; i++) {
1126
- const other = file.configEntries[i];
1127
- if (isDefaultDeclaration(other) && other.entityType === decl.entityType) {
1128
- if (firstIdx < 0) {
1129
- firstIdx = i;
1130
- }
1131
- else if (other === decl) {
1132
- accept('error', `Duplicate "default ${decl.entityType}" declaration. Only one is allowed per entity type per file.`, { node: decl });
1133
- break;
1134
- }
1135
- }
1136
- }
1137
- const banned = DEFAULT_BANNED[decl.entityType];
1138
- if (banned) {
1139
- for (const prop of decl.properties) {
1140
- const key = propKey(prop);
1141
- if (banned.has(key)) {
1142
- accept('error', `"${key}" cannot be set on "default ${decl.entityType}". Identity-defining, sizing, sequencing, reference, and prose properties must be explicit on each entity.`, { node: prop });
1143
- }
1144
- }
1145
- }
252
+ style.checkDefaultDeclaration(decl, accept);
253
+ }
254
+ checkHiddenTimelineStrip(file, accept) {
255
+ style.checkHiddenTimelineStrip(file, accept);
1146
256
  }
1147
- // --- Rule 7 (calendar): calendar block only valid when roadmap calendar:custom ---
1148
- // Rule 8: custom calendar requires all four fields.
1149
257
  checkCalendarBlockConsistency(file, accept) {
1150
- const calendarBlocks = file.configEntries.filter(isCalendarBlock);
1151
- const calendarProp = file.roadmapDecl?.properties.find((p) => propKey(p) === 'calendar');
1152
- const calendarMode = calendarProp?.value;
1153
- if (calendarBlocks.length > 0 && calendarMode !== 'custom') {
1154
- for (const block of calendarBlocks) {
1155
- accept('error', `A "calendar" config block is only valid when the roadmap declares calendar:custom.`, { node: block });
1156
- }
1157
- }
1158
- if (calendarMode === 'custom' && calendarBlocks.length === 0) {
1159
- accept('error', `calendar:custom requires a "calendar" config block with days-per-week, days-per-month, days-per-quarter, and days-per-year.`, { node: file.roadmapDecl, property: 'properties' });
1160
- }
1161
- if (calendarMode === 'custom' && calendarBlocks.length > 0) {
1162
- for (const block of calendarBlocks) {
1163
- const presentKeys = new Set(block.properties.map((p) => propKey(p)));
1164
- for (const field of CALENDAR_FIELDS) {
1165
- if (!presentKeys.has(field)) {
1166
- accept('error', `calendar:custom requires "${field}" in the calendar config block.`, { node: block });
1167
- }
1168
- }
1169
- }
1170
- }
258
+ calendar.checkCalendarBlockConsistency(file, accept);
1171
259
  }
1172
- // --- Rule 9: calendar block property values must be positive integers ---
1173
260
  checkCalendarBlock(block, accept) {
1174
- const seen = new Set();
1175
- for (const prop of block.properties) {
1176
- const key = propKey(prop);
1177
- if (!CALENDAR_FIELDS.has(key)) {
1178
- accept('error', `Unknown calendar property "${key}". Allowed: ${[...CALENDAR_FIELDS].join(', ')}.`, { node: prop, property: 'key' });
1179
- continue;
1180
- }
1181
- if (seen.has(key)) {
1182
- accept('error', `Duplicate calendar property "${key}".`, {
1183
- node: prop,
1184
- property: 'key',
1185
- });
1186
- }
1187
- seen.add(key);
1188
- if (!INTEGER_RE.test(prop.value) || parseInt(prop.value, 10) <= 0) {
1189
- accept('error', `"${key}" must be a positive integer, got "${prop.value}".`, {
1190
- node: prop,
1191
- property: 'value',
1192
- });
1193
- }
1194
- }
261
+ calendar.checkCalendarBlock(block, accept);
1195
262
  }
1196
- // --- Scale block property validation ---
1197
263
  checkScaleBlock(block, accept) {
1198
- const seen = new Set();
1199
- for (const prop of block.properties) {
1200
- const key = propKey(prop);
1201
- if (!SCALE_FIELDS.has(key)) {
1202
- accept('error', `Unknown scale property "${key}". Allowed: ${[...SCALE_FIELDS].join(', ')}.`, { node: prop, property: 'key' });
1203
- continue;
1204
- }
1205
- if (seen.has(key)) {
1206
- accept('error', `Duplicate scale property "${key}".`, {
1207
- node: prop,
1208
- property: 'key',
1209
- });
1210
- }
1211
- seen.add(key);
1212
- if (key === 'label-every') {
1213
- if (!INTEGER_RE.test(prop.value) || parseInt(prop.value, 10) <= 0) {
1214
- accept('error', `"label-every" must be a positive integer, got "${prop.value}".`, { node: prop, property: 'value' });
1215
- }
1216
- }
1217
- }
264
+ calendar.checkScaleBlock(block, accept);
1218
265
  }
1219
- // --- Rule 15: size:/status: references resolve to earlier declarations ---
1220
266
  checkForwardReferences(file, accept) {
1221
- // Declarations in source order across the file.
1222
- const sizeOrder = new Map();
1223
- const statusOrder = new Map();
1224
- for (let i = 0; i < file.roadmapEntries.length; i++) {
1225
- const entry = file.roadmapEntries[i];
1226
- if (isSizeDeclaration(entry) && entry.name) {
1227
- if (!sizeOrder.has(entry.name))
1228
- sizeOrder.set(entry.name, i);
1229
- }
1230
- else if (isStatusDeclaration(entry) && entry.name) {
1231
- if (!statusOrder.has(entry.name))
1232
- statusOrder.set(entry.name, i);
1233
- }
1234
- }
1235
- for (let i = 0; i < file.roadmapEntries.length; i++) {
1236
- const entry = file.roadmapEntries[i];
1237
- visitPropertiesDeep(entry, (prop) => {
1238
- const key = propKey(prop);
1239
- if (key === 'size' && prop.value) {
1240
- const val = prop.value;
1241
- const declIdx = sizeOrder.get(val);
1242
- if (declIdx === undefined) {
1243
- accept('error', `Size "${val}" is not declared. Add "size ${val} effort:<literal>" earlier in the roadmap section.`, { node: prop, property: 'value' });
1244
- }
1245
- else if (declIdx >= i) {
1246
- accept('error', `Size "${val}" is referenced before its declaration. Move "size ${val}" above this entity.`, { node: prop, property: 'value' });
1247
- }
1248
- }
1249
- else if (key === 'status' && prop.value) {
1250
- const val = prop.value;
1251
- if (BUILTIN_STATUSES.has(val))
1252
- return;
1253
- const declIdx = statusOrder.get(val);
1254
- if (declIdx === undefined) {
1255
- accept('error', `Status "${val}" is not a built-in and has no declaration. Add "status ${val}" earlier in the roadmap section.`, { node: prop, property: 'value' });
1256
- }
1257
- else if (declIdx >= i) {
1258
- accept('error', `Status "${val}" is referenced before its declaration. Move "status ${val}" above this entity.`, { node: prop, property: 'value' });
1259
- }
1260
- }
1261
- });
1262
- }
267
+ references.checkForwardReferences(file, accept);
1263
268
  }
1264
- // --- Rules 24/1 (reference): after/before/on must resolve to declared ids ---
1265
- // `owner:` is intentionally NOT checked here. Per specs/dsl.md ("Declarations
1266
- // are optional"), `owner:sam` is valid even if no `person sam` declaration
1267
- // exists — it renders as the bare id. Sequencing properties (`after`,
1268
- // `before`, `on`) stay strict because a phantom dependency silently breaks
1269
- // the timeline / footnote target.
1270
- //
1271
- // Inline date literals in `after:` / `before:` (e.g. `after:2026-03-15`)
1272
- // are intentionally NOT id references — they pin the entity directly to a
1273
- // calendar date without a named anchor. The DATE_RE check below skips them
1274
- // here; their own validation (entity-type allowlist, multi-date-per-direction,
1275
- // roadmap-start: requirements) lives in `checkInlineDatePins` below.
1276
269
  checkReferenceResolution(file, accept) {
1277
- const declaredIds = collectReferenceableIds(file);
1278
- const visit = (entry) => {
1279
- visitPropertiesDeep(entry, (prop) => {
1280
- const key = propKey(prop);
1281
- if (key !== 'after' && key !== 'before' && key !== 'on')
1282
- return;
1283
- const vals = prop.value ? [prop.value] : prop.values;
1284
- for (const v of vals) {
1285
- if (!v)
1286
- continue;
1287
- if ((key === 'after' || key === 'before') && DATE_RE.test(v))
1288
- continue;
1289
- if (!declaredIds.has(v)) {
1290
- accept('error', `${key}: reference "${v}" does not resolve to any declared entity in this file.`, { node: prop });
1291
- }
1292
- }
1293
- });
1294
- };
1295
- for (const entry of file.roadmapEntries) {
1296
- visit(entry);
1297
- }
270
+ references.checkReferenceResolution(file, accept);
1298
271
  }
1299
- // --- Rules 24a/24b/27/28 (inline-date pins on after:/before:) ---
1300
- // An inline ISO date literal in `after:` or `before:` pins the entity
1301
- // directly to a calendar position without a named `anchor` declaration
1302
- // (see specs/dsl.md "Inline date pins"). This check enforces:
1303
- // - 24a: inline date allowed only on item / parallel / group
1304
- // - 24b: at most one inline date per direction (per `after:` / `before:`)
1305
- // - 27: file with any inline date requires roadmap `start:`
1306
- // - 28: every inline date must be on or after roadmap `start:`
1307
- //
1308
- // Cycle detection (`checkCircularDependencies`) skips dates entirely —
1309
- // they are not graph nodes — so this is the only validator that touches
1310
- // their date semantics. The grammar's DATE_LITERAL terminal already
1311
- // enforces the YYYY-MM-DD shape; we only need to verify calendar validity
1312
- // for the start: comparison.
1313
272
  checkInlineDatePins(file, accept) {
1314
- const start = resolveLocalStart(file);
1315
- const visit = (entry) => {
1316
- const props = entry.properties ?? [];
1317
- const allowed = isItemDeclaration(entry) || isParallelBlock(entry) || isGroupBlock(entry);
1318
- for (const prop of props) {
1319
- const key = propKey(prop);
1320
- if (key !== 'after' && key !== 'before')
1321
- continue;
1322
- const vals = prop.value ? [prop.value] : prop.values;
1323
- const dateVals = vals.filter((v) => !!v && DATE_RE.test(v));
1324
- if (dateVals.length === 0)
1325
- continue;
1326
- if (!allowed) {
1327
- acceptTr(accept, 'error', { node: prop }, 'NL.E0411', {
1328
- key,
1329
- type: entityTypeLabel(entry),
1330
- });
1331
- continue;
1332
- }
1333
- if (dateVals.length > 1) {
1334
- acceptTr(accept, 'error', { node: prop }, 'NL.E0410', { key });
1335
- }
1336
- for (const dateVal of dateVals) {
1337
- switch (start.kind) {
1338
- case 'invalid':
1339
- // Roadmap start: itself is malformed; the user
1340
- // already sees that error. Suppress this one to
1341
- // avoid noise (mirrors anchor / milestone behavior).
1342
- continue;
1343
- case 'missing':
1344
- acceptTr(accept, 'error', { node: prop }, 'NL.E0412', {
1345
- key,
1346
- date: dateVal,
1347
- });
1348
- continue;
1349
- case 'valid': {
1350
- const d = new Date(dateVal);
1351
- if (Number.isNaN(d.getTime()))
1352
- continue;
1353
- if (d < start.date) {
1354
- acceptTr(accept, 'error', { node: prop }, 'NL.E0413', {
1355
- key,
1356
- date: dateVal,
1357
- start: start.iso,
1358
- });
1359
- }
1360
- }
1361
- }
1362
- }
1363
- }
1364
- if (isSwimlaneDeclaration(entry)) {
1365
- for (const c of entry.content)
1366
- visit(c);
1367
- }
1368
- else if (isParallelBlock(entry) || isGroupBlock(entry)) {
1369
- for (const c of entry.content)
1370
- visit(c);
1371
- }
1372
- };
1373
- for (const entry of file.roadmapEntries)
1374
- visit(entry);
273
+ references.checkInlineDatePins(file, accept);
1375
274
  }
1376
- // --- Rule 25: circular dependencies in after/before graph ---
1377
275
  checkCircularDependencies(file, accept) {
1378
- // Build forward-edge graph: id -> set of ids that must finish before id can start.
1379
- // `after:x` on entity y means y depends on x (edge y -> x).
1380
- // `before:y` on entity x means x must finish before y starts, so y depends on x (edge y -> x).
1381
- const deps = new Map();
1382
- const addDep = (node, dep) => {
1383
- if (!deps.has(node))
1384
- deps.set(node, new Set());
1385
- deps.get(node).add(dep);
1386
- };
1387
- const indexDependents = (idName, props, file) => {
1388
- if (!idName)
1389
- return;
1390
- for (const prop of props) {
1391
- const key = propKey(prop);
1392
- if (key === 'after') {
1393
- const refs = prop.value ? [prop.value] : prop.values;
1394
- for (const r of refs) {
1395
- if (!r)
1396
- continue;
1397
- // Inline date literals are not graph nodes — they pin
1398
- // to a calendar position, not to another entity. Skip
1399
- // them so they never participate in a cycle (per
1400
- // specs/dsl.md rule 25).
1401
- if (DATE_RE.test(r))
1402
- continue;
1403
- addDep(idName, r);
1404
- }
1405
- }
1406
- else if (key === 'before') {
1407
- const refs = prop.value ? [prop.value] : prop.values;
1408
- for (const r of refs) {
1409
- if (!r)
1410
- continue;
1411
- if (DATE_RE.test(r))
1412
- continue;
1413
- addDep(r, idName);
1414
- }
1415
- }
1416
- }
1417
- void file;
1418
- };
1419
- const visitEntry = (entry) => {
1420
- const id = entry.name;
1421
- const props = entry.properties ?? [];
1422
- indexDependents(id, props, file);
1423
- if (isSwimlaneDeclaration(entry)) {
1424
- for (const c of entry.content)
1425
- visitEntry(c);
1426
- }
1427
- else if (isParallelBlock(entry) || isGroupBlock(entry)) {
1428
- for (const c of entry.content)
1429
- visitEntry(c);
1430
- }
1431
- };
1432
- for (const entry of file.roadmapEntries)
1433
- visitEntry(entry);
1434
- // DFS for cycles.
1435
- const WHITE = 0, GRAY = 1, BLACK = 2;
1436
- const color = new Map();
1437
- for (const id of deps.keys())
1438
- color.set(id, WHITE);
1439
- const reported = new Set();
1440
- const dfs = (node, path) => {
1441
- color.set(node, GRAY);
1442
- path.push(node);
1443
- for (const dep of deps.get(node) ?? []) {
1444
- const c = color.get(dep) ?? WHITE;
1445
- if (c === GRAY) {
1446
- const cycleStart = path.indexOf(dep);
1447
- const cycle = path.slice(cycleStart).concat(dep);
1448
- const key = [...cycle].sort().join('→');
1449
- if (!reported.has(key)) {
1450
- reported.add(key);
1451
- accept('error', `Circular dependency detected: ${cycle.join(' → ')}.`, {
1452
- node: file.roadmapDecl ?? file,
1453
- });
1454
- }
1455
- }
1456
- else if (c === WHITE) {
1457
- dfs(dep, path);
1458
- }
1459
- }
1460
- path.pop();
1461
- color.set(node, BLACK);
1462
- };
1463
- for (const node of deps.keys()) {
1464
- if ((color.get(node) ?? WHITE) === WHITE)
1465
- dfs(node, []);
1466
- }
276
+ references.checkCircularDependencies(file, accept);
1467
277
  }
1468
- // --- Rules 30-32: Person declare-once + bare top-level warning ---
1469
278
  checkPersonDeclarations(file, accept) {
1470
- const declarations = new Map();
1471
- const isRealDeclaration = (p) => {
1472
- return Boolean(p.title) || p.properties.length > 0 || p.description !== undefined;
1473
- };
1474
- const visitPerson = (p) => {
1475
- if (!p.name)
1476
- return;
1477
- const isDecl = isRealDeclaration(p);
1478
- if (!declarations.has(p.name))
1479
- declarations.set(p.name, []);
1480
- declarations.get(p.name).push({ node: p, isDeclaration: isDecl });
1481
- if (!isDecl && p.$container.$type === 'NowlineFile') {
1482
- accept('warning', `Bare "person ${p.name}" at roadmap top level has no declaration. Either add properties (title, link, etc.) or remove the line.`, { node: p });
1483
- }
1484
- };
1485
- const visitTeam = (t) => {
1486
- for (const c of t.content) {
1487
- if (isPersonDeclaration(c))
1488
- visitPerson(c);
1489
- else if (isTeamDeclaration(c))
1490
- visitTeam(c);
1491
- }
1492
- };
1493
- for (const entry of file.roadmapEntries) {
1494
- if (isPersonDeclaration(entry))
1495
- visitPerson(entry);
1496
- else if (isTeamDeclaration(entry))
1497
- visitTeam(entry);
1498
- }
1499
- for (const [name, sites] of declarations) {
1500
- const decls = sites.filter((s) => s.isDeclaration);
1501
- if (decls.length > 1) {
1502
- for (let i = 1; i < decls.length; i++) {
1503
- accept('error', `Person "${name}" is declared more than once. First declaration at ${locationOf(decls[0].node)}.`, { node: decls[i].node });
1504
- }
1505
- }
1506
- }
279
+ entities.checkPersonDeclarations(file, accept);
1507
280
  }
1508
- // --- Rules 17f / 17g / 17h / 17i: per-declaration symbol checks ---
1509
- // Note: Langium's default ValueConverter strips surrounding quotes from STRING
1510
- // tokens before they reach the AST, so unicode:"💰" arrives here as just "💰"
1511
- // — we validate the *content* (length / ASCII range) rather than presence of
1512
- // quotes. The grammar already restricts `unicode:` and `ascii:` to PropertyAtom,
1513
- // so the only quoteless form an author can pass is a bare identifier like
1514
- // `unicode:foo`, which we treat permissively (it's a single-grapheme literal).
1515
281
  checkSymbolDeclaration(decl, accept) {
1516
- if (decl.name && BUILTIN_ICON_NAMES.has(decl.name)) {
1517
- accept('error', `Symbol id "${decl.name}" collides with a built-in icon name. Reserved built-ins: ${[...BUILTIN_ICON_NAMES].sort().join(', ')}.`, { node: decl, property: 'name' });
1518
- }
1519
- const unicodeProp = decl.properties.find((p) => propKey(p) === 'unicode');
1520
- if (!unicodeProp) {
1521
- accept('error', `Symbol "${displayName(decl)}" requires a "unicode:" property (e.g. unicode:"💰" or unicode:"\\u{1F464}").`, { node: decl });
1522
- }
1523
- else if (!unicodeProp.value || unicodeProp.value.length === 0) {
1524
- accept('error', `Symbol "${displayName(decl)}" unicode: must be a non-empty value.`, {
1525
- node: unicodeProp,
1526
- property: 'value',
1527
- });
1528
- }
1529
- const asciiProp = decl.properties.find((p) => propKey(p) === 'ascii');
1530
- if (asciiProp) {
1531
- const raw = asciiProp.value ?? '';
1532
- if (!ASCII_FALLBACK_RE.test(raw)) {
1533
- accept('error', `Symbol "${displayName(decl)}" ascii: must be 1-3 ASCII characters (got ${raw.length} character${raw.length === 1 ? '' : 's'}).`, { node: asciiProp, property: 'value' });
1534
- }
1535
- }
1536
- for (const prop of decl.properties) {
1537
- const key = propKey(prop);
1538
- if (key !== 'unicode' && key !== 'ascii' && key !== 'link' && key !== 'description') {
1539
- accept('error', `Unknown symbol property "${key}". Allowed: unicode, ascii, link, description.`, { node: prop, property: 'key' });
1540
- }
1541
- }
282
+ symbols.checkSymbolDeclaration(decl, accept);
1542
283
  }
1543
- // --- Rule 17j: duplicate symbol ids in the same file ---
1544
284
  checkDuplicateSymbolIds(file, accept) {
1545
- const seen = new Map();
1546
- for (const entry of file.configEntries) {
1547
- if (isSymbolDeclaration(entry) && entry.name) {
1548
- const existing = seen.get(entry.name);
1549
- if (existing) {
1550
- accept('error', `Duplicate symbol id "${entry.name}". First declared at ${locationOf(existing)}.`, { node: entry, property: 'name' });
1551
- }
1552
- else {
1553
- seen.set(entry.name, entry);
1554
- }
1555
- }
1556
- }
1557
- }
1558
- // --- Rule 17k: icon: / capacity-icon: references resolve to a built-in,
1559
- // a quoted Unicode literal, or an earlier symbol declaration. Forward
1560
- // references are an error. Walks both StyleDeclaration.properties and
1561
- // DefaultDeclaration.properties so style blocks and default <entity>
1562
- // lines share one path.
1563
- checkSymbolReferences(file, accept) {
1564
- const symbolOrder = new Map();
1565
- for (let i = 0; i < file.configEntries.length; i++) {
1566
- const entry = file.configEntries[i];
1567
- if (isSymbolDeclaration(entry) && entry.name) {
1568
- if (!symbolOrder.has(entry.name))
1569
- symbolOrder.set(entry.name, i);
1570
- }
1571
- }
1572
- const checkRef = (entryIdx, key, val, propNode) => {
1573
- if (key !== 'icon' && key !== 'capacity-icon')
1574
- return;
1575
- if (!val)
1576
- return;
1577
- // Inline Unicode literals (`capacity-icon:"💰"`) reach the AST as their
1578
- // unquoted content — the only way to tell them from an identifier
1579
- // reference is by checking the character set. Anything that doesn't
1580
- // look like an identifier is treated as a literal and
1581
- // accepted as-is. Authors who genuinely want to write a literal that
1582
- // happens to spell a real identifier should declare a symbol instead.
1583
- if (!isIdentifier(val))
1584
- return;
1585
- if (key === 'capacity-icon' && BUILTIN_CAPACITY_ICONS.has(val))
1586
- return;
1587
- if (key === 'icon' && BUILTIN_ICON_NAMES.has(val))
1588
- return;
1589
- const declIdx = symbolOrder.get(val);
1590
- if (declIdx === undefined) {
1591
- const builtins = key === 'capacity-icon'
1592
- ? [...BUILTIN_CAPACITY_ICONS].sort().join(', ')
1593
- : [...BUILTIN_ICON_NAMES].sort().join(', ');
1594
- accept('error', `${key}: "${val}" is neither a built-in (${builtins}) nor a declared symbol. Add "symbol ${val} unicode:..." earlier in config or use a quoted Unicode literal.`, { node: propNode, property: 'value' });
1595
- }
1596
- else if (declIdx >= entryIdx) {
1597
- accept('error', `${key}: symbol "${val}" is referenced before its declaration. Move "symbol ${val}" above this entry.`, { node: propNode, property: 'value' });
1598
- }
1599
- };
1600
- for (let i = 0; i < file.configEntries.length; i++) {
1601
- const entry = file.configEntries[i];
1602
- if (isStyleDeclaration(entry)) {
1603
- for (const sp of entry.properties) {
1604
- checkRef(i, propKey(sp), sp.value, sp);
1605
- }
1606
- }
1607
- else if (isDefaultDeclaration(entry)) {
1608
- for (const ep of entry.properties) {
1609
- checkRef(i, propKey(ep), ep.value, ep);
1610
- }
1611
- }
1612
- }
1613
- }
1614
- }
1615
- // --- Helpers ---
1616
- function isColorValue(val) {
1617
- return COLOR_NAMES.has(val) || HEX_COLOR_RE.test(val);
1618
- }
1619
- function isIdentifier(val) {
1620
- return /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(val);
1621
- }
1622
- function capacityParentKind(parent) {
1623
- if (!parent)
1624
- return 'invalid';
1625
- if (isSwimlaneDeclaration(parent))
1626
- return 'lane';
1627
- if (isItemDeclaration(parent))
1628
- return 'item';
1629
- if (isDefaultDeclaration(parent)) {
1630
- return parent.entityType === 'swimlane' ? 'lane' : 'item';
1631
- }
1632
- return 'invalid';
1633
- }
1634
- function isUtilizationAllowedHere(parent) {
1635
- if (!parent)
1636
- return false;
1637
- if (isSwimlaneDeclaration(parent))
1638
- return true;
1639
- if (isDefaultDeclaration(parent) && parent.entityType === 'swimlane')
1640
- return true;
1641
- return false;
1642
- }
1643
- /**
1644
- * Parse a numeric utilization-threshold value into a fraction. Mirrors the
1645
- * accepted value forms in checkPropertyValues (case `utilization-warn-at` /
1646
- * `utilization-over-at`):
1647
- *
1648
- * - `'none'` → null (opt-out; ordering check skips this side).
1649
- * - positive percent (`80%`) → 0.8.
1650
- * - positive decimal fraction (`0.8`) → 0.8 (or `1.25` → 1.25 for the
1651
- * intentionally-stretched-over case `utilization-over-at:125%`).
1652
- * - bare integer or anything else → null. Bare integers are rejected with
1653
- * a disambiguation hint by the value-form check before this helper runs;
1654
- * returning null here makes the ordering check skip that side instead of
1655
- * double-reporting.
1656
- */
1657
- function parseUtilizationFraction(val) {
1658
- if (!val || val === UTILIZATION_NONE)
1659
- return null;
1660
- if (POSITIVE_PERCENT_RE.test(val)) {
1661
- const n = parseFloat(val);
1662
- return Number.isFinite(n) && n > 0 ? n / 100 : null;
1663
- }
1664
- if (POSITIVE_DECIMAL_FRACTION_RE.test(val)) {
1665
- const n = parseFloat(val);
1666
- return Number.isFinite(n) && n > 0 ? n : null;
1667
- }
1668
- return null;
1669
- }
1670
- function locationOf(node) {
1671
- const cst = node.$cstNode;
1672
- if (cst) {
1673
- return `line ${cst.range.start.line + 1}`;
285
+ symbols.checkDuplicateSymbolIds(file, accept);
1674
286
  }
1675
- return 'unknown location';
1676
- }
1677
- function describeNode(node) {
1678
- const kind = node.$type.replace(/Declaration$|Block$/, '').toLowerCase();
1679
- const label = node.name ?? node.title;
1680
- return label ? `${kind} "${label}"` : kind;
1681
- }
1682
- function registerEntity(entry, register) {
1683
- if (isSwimlaneDeclaration(entry)) {
1684
- register(entry.name, entry);
1685
- for (const child of entry.content) {
1686
- registerSwimlaneContent(child, register);
1687
- }
1688
- }
1689
- else if (isPersonDeclaration(entry)) {
1690
- register(entry.name, entry);
1691
- }
1692
- else if (isTeamDeclaration(entry)) {
1693
- registerTeam(entry, register);
1694
- }
1695
- else if (isAnchorDeclaration(entry)) {
1696
- register(entry.name, entry);
1697
- }
1698
- else if (isMilestoneDeclaration(entry)) {
1699
- register(entry.name, entry);
1700
- }
1701
- else if (isFootnoteDeclaration(entry)) {
1702
- register(entry.name, entry);
1703
- }
1704
- else if (isLabelDeclaration(entry)) {
1705
- register(entry.name, entry);
1706
- }
1707
- else if (isSizeDeclaration(entry)) {
1708
- register(entry.name, entry);
287
+ checkCalendarDeclaration(decl, accept) {
288
+ calendar.checkCalendarDeclaration(decl, accept);
1709
289
  }
1710
- else if (isStatusDeclaration(entry)) {
1711
- register(entry.name, entry);
290
+ checkCalendarWeek(file, accept) {
291
+ calendar.checkCalendarWeek(file, accept);
1712
292
  }
1713
- }
1714
- function registerTeam(team, register) {
1715
- register(team.name, team);
1716
- for (const member of team.content) {
1717
- if (isTeamDeclaration(member)) {
1718
- registerTeam(member, register);
1719
- }
1720
- // PersonMemberRef and bare person <id> are references, not declarations — skip.
1721
- }
1722
- }
1723
- function registerSwimlaneContent(child, register) {
1724
- if (isItemDeclaration(child)) {
1725
- register(child.name, child);
293
+ checkDuplicateCalendarDeclarationIds(file, accept) {
294
+ calendar.checkDuplicateCalendarDeclarationIds(file, accept);
1726
295
  }
1727
- else if (isParallelBlock(child)) {
1728
- register(child.name, child);
1729
- for (const pc of child.content) {
1730
- registerSwimlaneContent(pc, register);
1731
- }
1732
- }
1733
- else if (isGroupBlock(child)) {
1734
- register(child.name, child);
1735
- for (const gc of child.content) {
1736
- registerSwimlaneContent(gc, register);
1737
- }
296
+ checkSymbolReferences(file, accept) {
297
+ symbols.checkSymbolReferences(file, accept);
1738
298
  }
1739
299
  }
1740
- function visitPropertiesDeep(node, visit) {
1741
- const walk = (n) => {
1742
- const props = n.properties;
1743
- if (Array.isArray(props)) {
1744
- for (const p of props)
1745
- visit(p);
1746
- }
1747
- if (isSwimlaneDeclaration(n)) {
1748
- for (const c of n.content)
1749
- walk(c);
1750
- }
1751
- else if (isParallelBlock(n) || isGroupBlock(n)) {
1752
- for (const c of n.content)
1753
- walk(c);
1754
- }
1755
- else if (isTeamDeclaration(n)) {
1756
- for (const c of n.content) {
1757
- if (isTeamDeclaration(c) || isPersonDeclaration(c))
1758
- walk(c);
1759
- }
1760
- }
1761
- };
1762
- walk(node);
1763
- }
1764
- function collectReferenceableIds(file) {
1765
- const ids = new Set();
1766
- if (file.roadmapDecl?.name)
1767
- ids.add(file.roadmapDecl.name);
1768
- const addEntry = (entry) => {
1769
- const name = entry.name;
1770
- if (name)
1771
- ids.add(name);
1772
- if (isSwimlaneDeclaration(entry)) {
1773
- for (const c of entry.content)
1774
- addEntry(c);
1775
- }
1776
- else if (isParallelBlock(entry) || isGroupBlock(entry)) {
1777
- for (const c of entry.content)
1778
- addEntry(c);
1779
- }
1780
- else if (isTeamDeclaration(entry)) {
1781
- for (const c of entry.content) {
1782
- if (isTeamDeclaration(c) || isPersonDeclaration(c))
1783
- addEntry(c);
1784
- else if (isPersonMemberRef(c)) {
1785
- // Don't register member refs — they reference persons declared elsewhere.
1786
- }
1787
- }
1788
- }
1789
- };
1790
- for (const entry of file.roadmapEntries)
1791
- addEntry(entry);
1792
- return ids;
1793
- }
1794
300
  //# sourceMappingURL=nowline-validator.js.map