@dxos/deus 0.0.0-stage → 0.0.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 (201) hide show
  1. package/LICENSE +105 -0
  2. package/README.md +24 -2
  3. package/bin/deus.ts +42 -0
  4. package/dist/lib/chunk-blocks.mjs +151 -0
  5. package/dist/lib/chunk-blocks.mjs.map +1 -0
  6. package/dist/lib/chunk-check.mjs +452 -0
  7. package/dist/lib/chunk-check.mjs.map +1 -0
  8. package/dist/lib/chunk-completion.mjs +112 -0
  9. package/dist/lib/chunk-completion.mjs.map +1 -0
  10. package/dist/lib/chunk-extension.mjs +396 -0
  11. package/dist/lib/chunk-extension.mjs.map +1 -0
  12. package/dist/lib/chunk-parse.mjs +21 -0
  13. package/dist/lib/chunk-parse.mjs.map +1 -0
  14. package/dist/lib/cli.mjs +946 -0
  15. package/dist/lib/cli.mjs.map +1 -0
  16. package/dist/lib/extension.mjs +4 -0
  17. package/dist/lib/index.mjs +6 -0
  18. package/dist/lib/parse.mjs +4 -0
  19. package/dist/lib/review.mjs +260 -0
  20. package/dist/lib/review.mjs.map +1 -0
  21. package/dist/lib/spec-index.mjs +28 -0
  22. package/dist/lib/spec-index.mjs.map +1 -0
  23. package/dist/types/bin/deus.d.ts +3 -0
  24. package/dist/types/bin/deus.d.ts.map +1 -0
  25. package/dist/types/src/cli/__fixtures__/review/plugin-deps/dx.config.d.ts +8 -0
  26. package/dist/types/src/cli/__fixtures__/review/plugin-deps/dx.config.d.ts.map +1 -0
  27. package/dist/types/src/cli/__fixtures__/review/plugin-deps-diverged/dx.config.d.ts +8 -0
  28. package/dist/types/src/cli/__fixtures__/review/plugin-deps-diverged/dx.config.d.ts.map +1 -0
  29. package/dist/types/src/cli/__fixtures__/review/plugin-deps-empty/dx.config.d.ts +7 -0
  30. package/dist/types/src/cli/__fixtures__/review/plugin-deps-empty/dx.config.d.ts.map +1 -0
  31. package/dist/types/src/cli/__fixtures__/review/plugin-deps-mismatch/dx.config.d.ts +8 -0
  32. package/dist/types/src/cli/__fixtures__/review/plugin-deps-mismatch/dx.config.d.ts.map +1 -0
  33. package/dist/types/src/cli/__fixtures__/review/plugin-deps-noplugin/dx.config.d.ts +5 -0
  34. package/dist/types/src/cli/__fixtures__/review/plugin-deps-noplugin/dx.config.d.ts.map +1 -0
  35. package/dist/types/src/cli/changelog.d.ts +25 -0
  36. package/dist/types/src/cli/changelog.d.ts.map +1 -0
  37. package/dist/types/src/cli/cli.test.d.ts +2 -0
  38. package/dist/types/src/cli/cli.test.d.ts.map +1 -0
  39. package/dist/types/src/cli/errors.d.ts +183 -0
  40. package/dist/types/src/cli/errors.d.ts.map +1 -0
  41. package/dist/types/src/cli/features.d.ts +58 -0
  42. package/dist/types/src/cli/features.d.ts.map +1 -0
  43. package/dist/types/src/cli/git.d.ts +8 -0
  44. package/dist/types/src/cli/git.d.ts.map +1 -0
  45. package/dist/types/src/cli/index.d.ts +12 -0
  46. package/dist/types/src/cli/index.d.ts.map +1 -0
  47. package/dist/types/src/cli/lint.d.ts +17 -0
  48. package/dist/types/src/cli/lint.d.ts.map +1 -0
  49. package/dist/types/src/cli/qa-lint.d.ts +40 -0
  50. package/dist/types/src/cli/qa-lint.d.ts.map +1 -0
  51. package/dist/types/src/cli/qa.d.ts +86 -0
  52. package/dist/types/src/cli/qa.d.ts.map +1 -0
  53. package/dist/types/src/cli/review.d.ts +38 -0
  54. package/dist/types/src/cli/review.d.ts.map +1 -0
  55. package/dist/types/src/cli/spec-index.d.ts +17 -0
  56. package/dist/types/src/cli/spec-index.d.ts.map +1 -0
  57. package/dist/types/src/extension/blocks.d.ts +65 -0
  58. package/dist/types/src/extension/blocks.d.ts.map +1 -0
  59. package/dist/types/src/extension/check.d.ts +99 -0
  60. package/dist/types/src/extension/check.d.ts.map +1 -0
  61. package/dist/types/src/extension/check.test.d.ts +2 -0
  62. package/dist/types/src/extension/check.test.d.ts.map +1 -0
  63. package/dist/types/src/extension/code.d.ts +7 -0
  64. package/dist/types/src/extension/code.d.ts.map +1 -0
  65. package/dist/types/src/extension/complete.d.ts +6 -0
  66. package/dist/types/src/extension/complete.d.ts.map +1 -0
  67. package/dist/types/src/extension/completion.d.ts +10 -0
  68. package/dist/types/src/extension/completion.d.ts.map +1 -0
  69. package/dist/types/src/extension/constants.d.ts +6 -0
  70. package/dist/types/src/extension/constants.d.ts.map +1 -0
  71. package/dist/types/src/extension/fences.d.ts +10 -0
  72. package/dist/types/src/extension/fences.d.ts.map +1 -0
  73. package/dist/types/src/extension/gen/mdl.d.ts +3 -0
  74. package/dist/types/src/extension/gen/mdl.d.ts.map +1 -0
  75. package/dist/types/src/extension/gen/mdl.terms.d.ts +2 -0
  76. package/dist/types/src/extension/gen/mdl.terms.d.ts.map +1 -0
  77. package/dist/types/src/extension/index.d.ts +8 -0
  78. package/dist/types/src/extension/index.d.ts.map +1 -0
  79. package/dist/types/src/extension/language.d.ts +20 -0
  80. package/dist/types/src/extension/language.d.ts.map +1 -0
  81. package/dist/types/src/extension/lint.d.ts +8 -0
  82. package/dist/types/src/extension/lint.d.ts.map +1 -0
  83. package/dist/types/src/extension/parse.d.ts +6 -0
  84. package/dist/types/src/extension/parse.d.ts.map +1 -0
  85. package/dist/types/src/extension/parser.test.d.ts +2 -0
  86. package/dist/types/src/extension/parser.test.d.ts.map +1 -0
  87. package/dist/types/src/extension/refs.d.ts +32 -0
  88. package/dist/types/src/extension/refs.d.ts.map +1 -0
  89. package/dist/types/src/extension/refs.test.d.ts +2 -0
  90. package/dist/types/src/extension/refs.test.d.ts.map +1 -0
  91. package/dist/types/src/extension/syntax.d.ts +12 -0
  92. package/dist/types/src/extension/syntax.d.ts.map +1 -0
  93. package/dist/types/src/index.d.ts +3 -0
  94. package/dist/types/src/index.d.ts.map +1 -0
  95. package/dist/types/src/review/fields.d.ts +9 -0
  96. package/dist/types/src/review/fields.d.ts.map +1 -0
  97. package/dist/types/src/review/index.d.ts +5 -0
  98. package/dist/types/src/review/index.d.ts.map +1 -0
  99. package/dist/types/src/review/review.d.ts +70 -0
  100. package/dist/types/src/review/review.d.ts.map +1 -0
  101. package/dist/types/src/review/review.test.d.ts +2 -0
  102. package/dist/types/src/review/review.test.d.ts.map +1 -0
  103. package/dist/types/src/review/source-key.d.ts +35 -0
  104. package/dist/types/src/review/source-key.d.ts.map +1 -0
  105. package/dist/types/src/review/symbol.d.ts +17 -0
  106. package/dist/types/src/review/symbol.d.ts.map +1 -0
  107. package/dist/types/src/review/symbol.test.d.ts +2 -0
  108. package/dist/types/src/review/symbol.test.d.ts.map +1 -0
  109. package/dist/types/src/spec-index/index.d.ts +3 -0
  110. package/dist/types/src/spec-index/index.d.ts.map +1 -0
  111. package/dist/types/src/spec-index/parse.d.ts +11 -0
  112. package/dist/types/src/spec-index/parse.d.ts.map +1 -0
  113. package/dist/types/src/spec-index/spec-index.d.ts +21 -0
  114. package/dist/types/src/spec-index/spec-index.d.ts.map +1 -0
  115. package/dist/types/src/spec-index/spec-index.test.d.ts +2 -0
  116. package/dist/types/src/spec-index/spec-index.test.d.ts.map +1 -0
  117. package/dist/types/tsconfig.tsbuildinfo +1 -0
  118. package/docs/DESIGN.md +561 -0
  119. package/docs/IDIOMS.md +265 -0
  120. package/lang/PLUGIN-.template.mdl +115 -0
  121. package/lang/app.mdl +200 -0
  122. package/lang/changelog.mdl +184 -0
  123. package/lang/core.mdl +203 -0
  124. package/lang/examples/chess-1.mdl +149 -0
  125. package/lang/examples/chess-2.mdl +203 -0
  126. package/lang/examples/chess-3.mdl +231 -0
  127. package/lang/features.mdl +92 -0
  128. package/lang/plugin.mdl +59 -0
  129. package/lang/qa.mdl +383 -0
  130. package/lang/review.mdl +103 -0
  131. package/lang/sql.mdl +72 -0
  132. package/package.json +74 -3
  133. package/src/cli/__fixtures__/bad-decision.mdl +13 -0
  134. package/src/cli/__fixtures__/features/CYCLE.mdl +25 -0
  135. package/src/cli/__fixtures__/features/FEATURES.mdl +47 -0
  136. package/src/cli/__fixtures__/features/SPEC.mdl +22 -0
  137. package/src/cli/__fixtures__/features/SPEC.review.mdl +32 -0
  138. package/src/cli/__fixtures__/features/TASKS.md +5 -0
  139. package/src/cli/__fixtures__/lint-refs/SPEC.mdl +7 -0
  140. package/src/cli/__fixtures__/lint-refs/SPEC.review.mdl +7 -0
  141. package/src/cli/__fixtures__/qa-lint/packages/plugins/plugin-risky/PLUGIN.mdl +29 -0
  142. package/src/cli/__fixtures__/qa-list/plugin-sample/spec/PLUGIN.mdl +51 -0
  143. package/src/cli/__fixtures__/review/SPEC.mdl +23 -0
  144. package/src/cli/__fixtures__/review/SPEC.review.mdl +26 -0
  145. package/src/cli/__fixtures__/review/plugin-deps/PLUGIN.mdl +9 -0
  146. package/src/cli/__fixtures__/review/plugin-deps/PLUGIN.review.mdl +13 -0
  147. package/src/cli/__fixtures__/review/plugin-deps/dx.config.ts +10 -0
  148. package/src/cli/__fixtures__/review/plugin-deps-diverged/PLUGIN.mdl +9 -0
  149. package/src/cli/__fixtures__/review/plugin-deps-diverged/PLUGIN.review.mdl +14 -0
  150. package/src/cli/__fixtures__/review/plugin-deps-diverged/dx.config.ts +10 -0
  151. package/src/cli/__fixtures__/review/plugin-deps-empty/PLUGIN.mdl +9 -0
  152. package/src/cli/__fixtures__/review/plugin-deps-empty/PLUGIN.review.mdl +13 -0
  153. package/src/cli/__fixtures__/review/plugin-deps-empty/dx.config.ts +9 -0
  154. package/src/cli/__fixtures__/review/plugin-deps-mismatch/PLUGIN.mdl +9 -0
  155. package/src/cli/__fixtures__/review/plugin-deps-mismatch/PLUGIN.review.mdl +13 -0
  156. package/src/cli/__fixtures__/review/plugin-deps-mismatch/dx.config.ts +10 -0
  157. package/src/cli/__fixtures__/review/plugin-deps-noplugin/PLUGIN.mdl +9 -0
  158. package/src/cli/__fixtures__/review/plugin-deps-noplugin/PLUGIN.review.mdl +13 -0
  159. package/src/cli/__fixtures__/review/plugin-deps-noplugin/dx.config.ts +7 -0
  160. package/src/cli/changelog.ts +122 -0
  161. package/src/cli/cli.test.ts +359 -0
  162. package/src/cli/errors.ts +23 -0
  163. package/src/cli/features.ts +320 -0
  164. package/src/cli/git.ts +35 -0
  165. package/src/cli/index.ts +27 -0
  166. package/src/cli/lint.ts +75 -0
  167. package/src/cli/qa-lint.ts +206 -0
  168. package/src/cli/qa.ts +300 -0
  169. package/src/cli/review.ts +359 -0
  170. package/src/cli/spec-index.ts +54 -0
  171. package/src/extension/blocks.ts +169 -0
  172. package/src/extension/check.test.ts +629 -0
  173. package/src/extension/check.ts +552 -0
  174. package/src/extension/code.ts +99 -0
  175. package/src/extension/complete.ts +34 -0
  176. package/src/extension/completion.ts +64 -0
  177. package/src/extension/constants.ts +28 -0
  178. package/src/extension/fences.ts +270 -0
  179. package/src/extension/gen/mdl.terms.ts +16 -0
  180. package/src/extension/gen/mdl.ts +16 -0
  181. package/src/extension/index.ts +25 -0
  182. package/src/extension/language.ts +33 -0
  183. package/src/extension/lint.ts +19 -0
  184. package/src/extension/mdl.grammar +60 -0
  185. package/src/extension/parse.ts +31 -0
  186. package/src/extension/parser.test.ts +248 -0
  187. package/src/extension/refs.test.ts +95 -0
  188. package/src/extension/refs.ts +94 -0
  189. package/src/extension/syntax.ts +25 -0
  190. package/src/index.ts +6 -0
  191. package/src/review/fields.ts +31 -0
  192. package/src/review/index.ts +8 -0
  193. package/src/review/review.test.ts +111 -0
  194. package/src/review/review.ts +184 -0
  195. package/src/review/source-key.ts +63 -0
  196. package/src/review/symbol.test.ts +47 -0
  197. package/src/review/symbol.ts +96 -0
  198. package/src/spec-index/index.ts +6 -0
  199. package/src/spec-index/parse.ts +22 -0
  200. package/src/spec-index/spec-index.test.ts +56 -0
  201. package/src/spec-index/spec-index.ts +49 -0
@@ -0,0 +1,64 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { FENCE_REGEX } from './blocks.ts';
6
+
7
+ // Standard fields for each block type.
8
+ // In future this will be derived from resolved `ext` definitions.
9
+ export const BLOCK_FIELDS: Record<string, string[]> = {
10
+ ext: ['uri', 'desc', 'extends', 'fields', 'adds-fields', 'nesting', 'inline-prose', 'example'],
11
+ type: ['desc', 'fields', 'literals', 'extends'],
12
+ op: ['desc', 'input', 'output', 'errors', 'effects', 'requires', 'invariants', 'note'],
13
+ feat: ['desc', 'req'],
14
+ test: ['given', 'when', 'then', 'tags'],
15
+ component: ['desc', 'props', 'state', 'slots', 'actions', 'emits', 'layout'],
16
+ service: ['desc', 'loading', 'ops', 'errors', 'note'],
17
+ db: ['desc', 'backend', 'entities', 'queries', 'note'],
18
+ module: ['desc', 'api', 'styleguide'],
19
+ decision: ['date', 'by', 'for', 'affects', 'supersedes', 'answers', 'why', 'rejected', 'source'],
20
+ question: ['date', 'by', 'for', 'affects', 'context', 'options', 'source'],
21
+ };
22
+
23
+ /**
24
+ * The fields a cursor at `pos` may complete: inside an `mdl` fence, past its header line, before any `:` on the line.
25
+ * Undefined anywhere else, or in a block whose type has no known fields.
26
+ */
27
+ export const fieldCompletionContext = (
28
+ text: string,
29
+ pos: number,
30
+ ): { blockType: string; fields: string[] } | undefined => {
31
+ const before = text.slice(0, pos);
32
+
33
+ // Find the innermost open ```mdl fence above the cursor.
34
+ const openFences = [...before.matchAll(new RegExp(FENCE_REGEX.source, FENCE_REGEX.flags))];
35
+ const closeFences = [...before.matchAll(/^```\s*$/gm)];
36
+ if (openFences.length === 0 || openFences.length <= closeFences.length) {
37
+ return undefined;
38
+ }
39
+
40
+ const lastOpen = openFences[openFences.length - 1];
41
+ const fenceEnd = lastOpen.index + lastOpen[0].length;
42
+
43
+ // Read block type from the first body line (immediately after the fence header).
44
+ const newlineAfterFence = text.indexOf('\n', fenceEnd);
45
+ if (newlineAfterFence === -1) {
46
+ return undefined;
47
+ }
48
+ const firstBodyStart = newlineAfterFence + 1;
49
+ const firstBodyEnd = text.indexOf('\n', firstBodyStart);
50
+ const firstBodyLine = (
51
+ firstBodyEnd === -1 ? text.slice(firstBodyStart) : text.slice(firstBodyStart, firstBodyEnd)
52
+ ).trim();
53
+ const blockType = firstBodyLine.match(/^(\w+)/)?.[1] ?? '';
54
+
55
+ const fields = BLOCK_FIELDS[blockType];
56
+ // The header line names the block type itself, so it takes no field.
57
+ if (!fields || firstBodyEnd === -1 || pos <= firstBodyEnd) {
58
+ return undefined;
59
+ }
60
+
61
+ // Only complete at the start of a line (field name position).
62
+ const partial = before.slice(before.lastIndexOf('\n') + 1);
63
+ return partial.includes(':') ? undefined : { blockType, fields };
64
+ };
@@ -0,0 +1,28 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ /**
6
+ * Known Spec block types from the core + standard dialect.
7
+ * In future this will be derived from the Extensions table in the document.
8
+ */
9
+ export const BLOCK_TYPES = [
10
+ 'ext',
11
+ 'type',
12
+ 'op',
13
+ 'feat',
14
+ 'feature',
15
+ 'scenario',
16
+ 'test',
17
+ 'component',
18
+ 'service',
19
+ 'db',
20
+ 'module',
21
+ 'suite',
22
+ 'decision',
23
+ 'question',
24
+ 'verdict',
25
+ 'plugin',
26
+ 'uses',
27
+ 'table',
28
+ ] as const;
@@ -0,0 +1,270 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { syntaxTree } from '@codemirror/language';
6
+ import { type Extension, RangeSetBuilder } from '@codemirror/state';
7
+ import { Decoration, type DecorationSet, EditorView, ViewPlugin, type ViewUpdate } from '@codemirror/view';
8
+
9
+ import { BLOCK_TYPES } from './constants.ts';
10
+
11
+ // Per-type hue palette for block type keyword.
12
+ const BLOCK_TYPE_COLORS: Record<(typeof BLOCK_TYPES)[number], string> = {
13
+ ext: 'var(--color-violet-400)',
14
+ type: 'var(--color-blue-400)',
15
+ op: 'var(--color-orange-400)',
16
+ feat: 'var(--color-emerald-400)',
17
+ feature: 'var(--color-sky-400)',
18
+ scenario: 'var(--color-cyan-400)',
19
+ test: 'var(--color-teal-400)',
20
+ component: 'var(--color-pink-400)',
21
+ service: 'var(--color-yellow-400)',
22
+ db: 'var(--color-red-400)',
23
+ module: 'var(--color-indigo-400)',
24
+ suite: 'var(--color-lime-400)',
25
+ decision: 'var(--color-amber-400)',
26
+ question: 'var(--color-orange-300)',
27
+ verdict: 'var(--color-green-400)',
28
+ plugin: 'var(--color-fuchsia-400)',
29
+ uses: 'var(--color-rose-400)',
30
+ table: 'var(--color-red-400)',
31
+ };
32
+
33
+ const theme = EditorView.baseTheme({
34
+ '.cm-mdl-fence-tick': { color: 'var(--color-slate-400)' },
35
+ '.cm-mdl-block-id': { color: 'var(--color-orange-400)' },
36
+ '.cm-mdl-block-header': { color: 'var(--color-pink-400)' },
37
+ '.cm-mdl-field': { color: 'var(--color-blue-400)' },
38
+ '.cm-mdl-punct': { color: 'var(--color-slate-400)' },
39
+ '.cm-mdl-comment': { color: 'var(--color-green-400)', fontStyle: 'italic' },
40
+ ...Object.fromEntries(
41
+ Object.entries(BLOCK_TYPE_COLORS).map(([type, color]) => [`& .cm-mdl-block-${type}`, { color }]),
42
+ ),
43
+ });
44
+
45
+ /** Color a single line of the block body using regex matching. */
46
+ const decorateLine = (builder: RangeSetBuilder<Decoration>, lineText: string, lineFrom: number): void => {
47
+ const trimmed = lineText.trimStart();
48
+ const indent = lineText.length - trimmed.length;
49
+ const abs = (offset: number) => lineFrom + offset;
50
+
51
+ // Standalone comment line.
52
+ if (trimmed.startsWith('#')) {
53
+ builder.add(abs(indent), abs(lineText.length), Decoration.mark({ class: 'cm-mdl-comment' }));
54
+ return;
55
+ }
56
+
57
+ // Field name line: "<fieldName> [id][?]: value"
58
+ // e.g. "req F-1.1: prose", "kind: PieceKind", "piece?: Piece"
59
+ const lineMatch = trimmed.match(/^([\w][\w-]*)(?:\s+([\w][\w.-]*))?(\??)(\s*:)(.*)/s);
60
+ if (!lineMatch) {
61
+ // No field pattern — still color any trailing " #" comment.
62
+ const commentIdx = lineText.indexOf(' #', indent);
63
+ if (commentIdx >= 0) {
64
+ builder.add(abs(commentIdx + 1), abs(lineText.length), Decoration.mark({ class: 'cm-mdl-comment' }));
65
+ }
66
+ return;
67
+ }
68
+
69
+ const [, fieldName, id, optMarker, colonPart] = lineMatch;
70
+
71
+ // Field name.
72
+ const fieldFrom = abs(indent);
73
+ const fieldTo = fieldFrom + fieldName.length;
74
+ builder.add(fieldFrom, fieldTo, Decoration.mark({ class: 'cm-mdl-field' }));
75
+
76
+ let pos = indent + fieldName.length;
77
+
78
+ // Optional id between field name and colon (e.g. F-1.1).
79
+ if (id) {
80
+ const idFrom = abs(pos + 1); // +1 for the space
81
+ const idTo = idFrom + id.length;
82
+ builder.add(idFrom, idTo, Decoration.mark({ class: 'cm-mdl-block-id' }));
83
+ pos += 1 + id.length;
84
+ }
85
+
86
+ // Optional ? marker.
87
+ if (optMarker) {
88
+ builder.add(abs(pos), abs(pos + 1), Decoration.mark({ class: 'cm-mdl-punct' }));
89
+ pos += 1;
90
+ }
91
+
92
+ // Colon — last char of colonPart (colonPart matches \s*:).
93
+ const colonPos = pos + colonPart.length - 1;
94
+ builder.add(abs(colonPos), abs(colonPos + 1), Decoration.mark({ class: 'cm-mdl-punct' }));
95
+ pos += colonPart.length;
96
+
97
+ // Inline comment: first " #" after the colon.
98
+ const commentOffset = lineText.indexOf(' #', pos);
99
+ const valueEnd = commentOffset >= 0 ? commentOffset : lineText.length;
100
+
101
+ // Value expression highlighting (must come before comment to maintain ascending order).
102
+ const valueStart = pos;
103
+ const valuePart = lineText.slice(valueStart, valueEnd);
104
+
105
+ // Bracketed identifier list (e.g. "[InvalidMove, WrongTurn, GameOver]").
106
+ // RangeSetBuilder requires decorations in ascending order, so we scan left-to-right.
107
+ const bracketMatch = valuePart.match(/^\s*\[([^\]]*)\]/);
108
+ if (bracketMatch) {
109
+ const openIdx = valueStart + valuePart.indexOf('[');
110
+ const closeIdx = valueStart + valuePart.indexOf(']');
111
+ builder.add(abs(openIdx), abs(openIdx + 1), Decoration.mark({ class: 'cm-mdl-punct' }));
112
+
113
+ // Scan inner content left-to-right for identifiers and commas.
114
+ const inner = bracketMatch[1];
115
+ const tokenRe = /(\w[\w-]*)|,/g;
116
+ let token: RegExpExecArray | null;
117
+ while ((token = tokenRe.exec(inner)) !== null) {
118
+ const tokenFrom = openIdx + 1 + token.index;
119
+ if (token[1]) {
120
+ builder.add(abs(tokenFrom), abs(tokenFrom + token[0].length), Decoration.mark({ class: 'cm-mdl-block-id' }));
121
+ } else {
122
+ builder.add(abs(tokenFrom), abs(tokenFrom + 1), Decoration.mark({ class: 'cm-mdl-punct' }));
123
+ }
124
+ }
125
+
126
+ builder.add(abs(closeIdx), abs(closeIdx + 1), Decoration.mark({ class: 'cm-mdl-punct' }));
127
+ }
128
+
129
+ // Pipe separators in union types (e.g. "a | b | c").
130
+ let pipeIdx = valuePart.indexOf('|');
131
+ while (pipeIdx >= 0) {
132
+ const absIdx = valueStart + pipeIdx;
133
+ builder.add(abs(absIdx), abs(absIdx + 1), Decoration.mark({ class: 'cm-mdl-punct' }));
134
+ pipeIdx = valuePart.indexOf('|', pipeIdx + 1);
135
+ }
136
+
137
+ // Inline comment added last to keep RangeSetBuilder insertion monotonic.
138
+ if (commentOffset >= 0) {
139
+ builder.add(abs(commentOffset + 1), abs(lineText.length), Decoration.mark({ class: 'cm-mdl-comment' }));
140
+ }
141
+ };
142
+
143
+ const buildDecorations = (view: EditorView): DecorationSet => {
144
+ const builder = new RangeSetBuilder<Decoration>();
145
+ const { state } = view;
146
+
147
+ // Frontmatter: detect YAML block at document start, delimited by ---.
148
+ const docText = state.doc.toString();
149
+ const fmMatch = docText.match(/^---\n([\s\S]*?\n)---(?:\n|$)/);
150
+ if (fmMatch) {
151
+ // Opening ---.
152
+ builder.add(0, 3, Decoration.mark({ class: 'cm-mdl-fence-tick' }));
153
+
154
+ // Key-value lines inside frontmatter.
155
+ const fmContent = fmMatch[1];
156
+ let lineOffset = 4; // skip '---\n'
157
+ for (const line of fmContent.split('\n')) {
158
+ if (line.trim()) {
159
+ decorateLine(builder, line, lineOffset);
160
+ }
161
+ lineOffset += line.length + 1;
162
+ }
163
+
164
+ // Closing ---.
165
+ const closeFrom = 4 + fmMatch[1].length;
166
+ builder.add(closeFrom, closeFrom + 3, Decoration.mark({ class: 'cm-mdl-fence-tick' }));
167
+ }
168
+
169
+ syntaxTree(state).iterate({
170
+ enter(node) {
171
+ if (node.name !== 'CodeInfo') {
172
+ return;
173
+ }
174
+
175
+ // Only handle ```mdl fences.
176
+ if (state.doc.sliceString(node.from, node.to).trim() !== 'mdl') {
177
+ return;
178
+ }
179
+
180
+ // Color ``` ticks + "mdl" keyword in muted grey.
181
+ const tickFrom = node.from - 3;
182
+ if (tickFrom >= 0) {
183
+ builder.add(tickFrom, node.to, Decoration.mark({ class: 'cm-mdl-fence-tick' }));
184
+ }
185
+
186
+ // Find the CodeText sibling that holds the block body.
187
+ let child = node.node.parent?.firstChild ?? null;
188
+ while (child && child.name !== 'CodeText') {
189
+ child = child.nextSibling ?? null;
190
+ }
191
+ if (!child) {
192
+ return;
193
+ }
194
+
195
+ const bodyFrom = child.from;
196
+ const bodyText = state.doc.sliceString(bodyFrom, child.to);
197
+ const lines = bodyText.split('\n');
198
+ let lineOffset = 0;
199
+
200
+ for (let i = 0; i < lines.length; i++) {
201
+ const line = lines[i];
202
+ const lineFrom = bodyFrom + lineOffset;
203
+
204
+ if (i === 0) {
205
+ // First body line: "<blockType> [id][: label]"
206
+ // e.g. "type Color", "feat F-1: Start Game", "test T-1: description"
207
+ const headerMatch = line.match(/^(\s*)(\w+)(?:\s+([\w][\w.-]*))?(\s*:\s*)?(.*)?$/);
208
+ if (headerMatch) {
209
+ const [, leadingSpace, blockType, id, colon, label] = headerMatch;
210
+ const color = BLOCK_TYPE_COLORS[blockType as (typeof BLOCK_TYPES)[number]];
211
+ if (color) {
212
+ // Block type keyword.
213
+ const typeFrom = lineFrom + leadingSpace.length;
214
+ const typeTo = typeFrom + blockType.length;
215
+ builder.add(typeFrom, typeTo, Decoration.mark({ class: `cm-mdl-block-${blockType}` }));
216
+
217
+ // Identifier (e.g. F-1, T-1, Color) — white/bright so it stands out.
218
+ if (id) {
219
+ const idFrom = typeTo + 1; // +1 for the space
220
+ const idTo = idFrom + id.length;
221
+ builder.add(idFrom, idTo, Decoration.mark({ class: 'cm-mdl-block-id' }));
222
+
223
+ // Label after colon — muted.
224
+ if (colon && label) {
225
+ const labelFrom = idTo + colon.length;
226
+ builder.add(labelFrom, lineFrom + line.length, Decoration.mark({ class: 'cm-mdl-block-header' }));
227
+ }
228
+ }
229
+ }
230
+ }
231
+ } else {
232
+ decorateLine(builder, line, lineFrom);
233
+ }
234
+
235
+ lineOffset += line.length + 1; // +1 for '\n'
236
+ }
237
+ },
238
+ });
239
+
240
+ return builder.finish();
241
+ };
242
+
243
+ /**
244
+ * Decorates Spec mdl fenced blocks:
245
+ * - Mutes the ``` ticks and `mdl` keyword (slate-500)
246
+ * - Colors the block type keyword on the first body line (per-type hue)
247
+ * - Colors field names in block body lines (blue-400)
248
+ * - Colors comments in block body lines (green-400, italic)
249
+ */
250
+ export const mdlFenceHighlight: Extension = [
251
+ theme,
252
+ ViewPlugin.fromClass(
253
+ class {
254
+ decorations: DecorationSet;
255
+
256
+ constructor(view: EditorView) {
257
+ this.decorations = buildDecorations(view);
258
+ }
259
+
260
+ update(update: ViewUpdate) {
261
+ if (update.docChanged || update.viewportChanged) {
262
+ this.decorations = buildDecorations(update.view);
263
+ }
264
+ }
265
+ },
266
+ {
267
+ decorations: (instance) => instance.decorations,
268
+ },
269
+ ),
270
+ ];
@@ -0,0 +1,16 @@
1
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
2
+ export const
3
+ Block = 1,
4
+ KeyValue = 2,
5
+ FieldName = 3,
6
+ Optional = 4,
7
+ TypeExpr = 7,
8
+ TypeAtom = 8,
9
+ ListExpr = 9,
10
+ TypeName = 11,
11
+ Comma = 12,
12
+ ArrayExpr = 15,
13
+ NumberRange = 16,
14
+ Number = 17,
15
+ Pipe = 19,
16
+ Comment = 21
@@ -0,0 +1,16 @@
1
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
2
+ import {LRParser} from "@lezer/lr"
3
+ export const parser = LRParser.deserialize({
4
+ version: 14,
5
+ states: "&lQVQPOOOOQO'#C_'#C_OOQO'#Cq'#CqObQPO'#C^OjQPO'#CxOOQO'#Cx'#CxOOQO'#Cr'#CrQVQPOOOOQO'#C`'#C`OoQPO,58xO!QQPO,58xOOQO,59d,59dOOQO-E6p-E6pOOQO'#Cg'#CgO!VQPO'#CeO![QPO'#CdOOQO'#Cm'#CmO!jQPO'#ClOOQO'#Cd'#CdO!oQPO'#CcOOQO1G.d1G.dO!zQPO1G.dO#SQPO1G.dO#eQPO,59PO#mQPO,59VO#rQPO,59WOOQO'#Co'#CoO#wQPO'#CtO$SQPO,58}OOQO7+$O7+$OO$_QPO7+$OOOQO'#Ch'#ChO!VQPO'#CsO$gQPO1G.kOOQO1G.k1G.kOOQO1G.q1G.qOOQO1G.r1G.rOOQO,59`,59`OOQO-E6r-E6rOOQO<<Gj<<GjOOQO,59_,59_OOQO-E6q-E6qOOQO7+$V7+$V",
6
+ stateData: "$r~OkOS~OmPOoQOpTO~OTWOUXO~OpZO~OY^Om]On`OoQOpQa~OUfO~Om]O~OYhOdWXoWXpWX~ObiO~OdjOoVXpVX~OoQOpQi~OY^Om]On`OoQOpQi~O]oO^rO~O^sO~On`O~OY^Om]On`O~OdjOoVapVa~OoQOpQq~O]oO^zO~Oom~",
7
+ goto: "#nmPPnrvPPy!P!WP!]!hPP!W!W!lP!tP!x#W#^#dPPP#jTSOVTROVRYRQeXRnfScXfRukVbXfkU_XfkQg^RxpTpgqUaXfkRtiTkclSSOVQdXSmefRwnQVOR[VQqgRyqQlcRvlTUOV",
8
+ nodeNames: "⚠ Block KeyValue FieldName Optional ? : TypeExpr TypeAtom ListExpr [ TypeName Comma , ] ArrayExpr NumberRange Number .. Pipe | Comment",
9
+ maxTerm: 32,
10
+ skippedNodes: [0],
11
+ repeatNodeCount: 3,
12
+ tokenData: "$k~R`XY!TYZ!`]^!epq!Tst!k|}#S!O!P#X!Q![#d![!]#l!a!b#q!c!}#v!}#O$[#P#Q$a#R#S#v#T#o#v#p#q$f~!YQk~XY!Tpq!T~!eOp~~!hPYZ!`~!pSo~OY!kZ;'S!k;'S;=`!|<%lO!k~#PP;=`<%l!k~#XO]~~#[P!O!P#_~#dOb~~#iPn~!Q![#d~#qOU~~#vOT~~#{Tm~}!O#v!Q![#v!c!}#v#R#S#v#T#o#v~$aOY~~$fO^~~$kOd~",
13
+ tokenizers: [0],
14
+ topRules: {"Block":[0,1]},
15
+ tokenPrec: 169
16
+ })
@@ -0,0 +1,25 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ export { mdl, mdlBlockDescription } from './language.ts';
6
+ export { type MdlBlock, parseMdlBlocks } from './blocks.ts';
7
+ export {
8
+ type ChangelogEntry,
9
+ type ChangelogQuestion,
10
+ type LintOptions,
11
+ MISSING_DECISION,
12
+ type QuestionOption,
13
+ checkChangelogChange,
14
+ duplicateSpecMessage,
15
+ isTrivialEdit,
16
+ lintMdl,
17
+ missingItemMessage,
18
+ parseChangelog,
19
+ specReferenceFilter,
20
+ unknownSpecMessage,
21
+ } from './check.ts';
22
+ export { mdlLint } from './lint.ts';
23
+ export { mdlComplete } from './complete.ts';
24
+ export { mdlTerms } from './syntax.ts';
25
+ export { type Dependency, type SpecRef, findSpecRefs, specDependencies } from './refs.ts';
@@ -0,0 +1,33 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { LanguageDescription, LanguageSupport } from '@codemirror/language';
6
+ import { type Extension } from '@codemirror/state';
7
+
8
+ import { type SpecIndex } from '../spec-index/spec-index.ts';
9
+ import { codeFenceHighlight } from './code.ts';
10
+ import { mdlFenceHighlight } from './fences.ts';
11
+ import { mdlLint } from './lint.ts';
12
+ import { mdlBlockLanguage } from './syntax.ts';
13
+
14
+ /**
15
+ * LanguageDescription for MDL fenced block bodies.
16
+ * All Spec blocks use ```mdl fences; the block type is the first body line.
17
+ * Pass this to createMarkdownExtensions({ codeLanguages: [mdlBlockDescription] }).
18
+ */
19
+ export const mdlBlockDescription = LanguageDescription.of({
20
+ name: 'spec-block',
21
+ alias: ['mdl'],
22
+ support: new LanguageSupport(mdlBlockLanguage),
23
+ });
24
+
25
+ /**
26
+ * CodeMirror extensions for Spec .mdl block-body highlighting and fence decoration, and for the
27
+ * highlighting of fenced code in other languages.
28
+ * Given an `index`, it also lints spec references and dependencies against it.
29
+ * Does NOT include the Markdown language itself — pass mdlBlockDescription to
30
+ * createMarkdownExtensions() instead so it merges cleanly with the standard language set.
31
+ */
32
+ export const mdl = ({ index }: { index?: SpecIndex | (() => SpecIndex | undefined) } = {}): Extension =>
33
+ index ? [mdlFenceHighlight, codeFenceHighlight, mdlLint(index)] : [mdlFenceHighlight, codeFenceHighlight];
@@ -0,0 +1,19 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { type Diagnostic, linter } from '@codemirror/lint';
6
+ import { type Extension } from '@codemirror/state';
7
+ import { type EditorView } from '@codemirror/view';
8
+
9
+ import { type SpecIndex } from '../spec-index/spec-index.ts';
10
+ import { lintMdl } from './check.ts';
11
+
12
+ /**
13
+ * Lint extension for Spec .mdl documents; with an index (or a getter for one that loads late) it also
14
+ * checks spec references and dependencies.
15
+ */
16
+ export const mdlLint = (index?: SpecIndex | (() => SpecIndex | undefined)): Extension =>
17
+ linter((view: EditorView): Diagnostic[] =>
18
+ lintMdl(view.state.doc.toString(), { index: typeof index === 'function' ? index() : index }),
19
+ );
@@ -0,0 +1,60 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+ // Lezer grammar for the body of Deus fenced blocks (MDL).
5
+ // Generate: lezer-generator --typeScript src/extension/mdl.grammar -o src/extension/gen/mdl.ts
6
+ //
7
+ // Each entry is terminated by a newline so the parser can unambiguously
8
+ // distinguish "name after :" (TypeName in TypeExpr) from "name at line start"
9
+ // (FieldName of the next KeyValue).
10
+ //
11
+
12
+ @top Block { entry* }
13
+
14
+ @skip { space }
15
+
16
+ entry {
17
+ KeyValue newline |
18
+ Comment newline |
19
+ newline
20
+ }
21
+
22
+ // key[?]: value # inline comment
23
+ KeyValue { FieldName Optional? ":" TypeExpr? Comment? }
24
+
25
+ FieldName { name }
26
+ Optional { "?" }
27
+
28
+ // TypeExpr: one or more atoms separated by "|"
29
+ TypeExpr { TypeAtom (Pipe TypeAtom)* }
30
+
31
+ TypeAtom {
32
+ ListExpr |
33
+ ArrayExpr |
34
+ NumberRange |
35
+ TypeName
36
+ }
37
+
38
+ Pipe { "|" }
39
+ ListExpr { "[" TypeName (Comma TypeName)* "]" }
40
+ Comma { "," }
41
+ ArrayExpr { TypeName "[" "]" }
42
+ NumberRange { Number ".." Number }
43
+ TypeName { name }
44
+ Number { integer }
45
+
46
+ // Comment: "#" to end of line (no newline included)
47
+ Comment { lineComment }
48
+
49
+ @tokens {
50
+ name { $[a-zA-Z_] $[a-zA-Z0-9_\-]* }
51
+ integer { @digit+ }
52
+ lineComment { "#" ![\n]* }
53
+ space { $[ \t]+ }
54
+ newline { "\n" | "\r\n" }
55
+
56
+ ".."
57
+ "?" ":" "|" "[" "]" ","
58
+
59
+ @precedence { lineComment, name }
60
+ }
@@ -0,0 +1,31 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ // The parsing, lint and completion logic without CodeMirror, for tools that run outside an editor view (the language server).
6
+ export {
7
+ BLOCK_HEADER_LINE,
8
+ type BlockHeader,
9
+ type FenceLine,
10
+ type MdlBlock,
11
+ extensionTerms,
12
+ parseBlockHeaders,
13
+ parseMdlBlocks,
14
+ scanFenceLines,
15
+ } from './blocks.ts';
16
+ export {
17
+ type ChangelogEntry,
18
+ type LintOptions,
19
+ MISSING_DECISION,
20
+ checkChangelogChange,
21
+ duplicateSpecMessage,
22
+ isTrivialEdit,
23
+ lintMdl,
24
+ missingItemMessage,
25
+ parseChangelog,
26
+ specReferenceFilter,
27
+ unknownSpecMessage,
28
+ } from './check.ts';
29
+ export { BLOCK_FIELDS, fieldCompletionContext } from './completion.ts';
30
+ export { BLOCK_TYPES } from './constants.ts';
31
+ export { type Dependency, type SpecRef, findSpecKeys, findSpecRefs, scanSpecLines, specDependencies } from './refs.ts';