@manifesto-ai/compiler 1.6.2 → 1.8.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/README.md +67 -18
  2. package/dist/chunk-BH25NHMN.js +74 -0
  3. package/dist/chunk-BH25NHMN.js.map +1 -0
  4. package/dist/chunk-D62NIFP4.js +33 -0
  5. package/dist/chunk-D62NIFP4.js.map +1 -0
  6. package/dist/chunk-MKLDAZ2Z.js +6920 -0
  7. package/dist/chunk-MKLDAZ2Z.js.map +1 -0
  8. package/dist/esbuild.d.ts +8 -0
  9. package/dist/esbuild.js +14 -0
  10. package/dist/esbuild.js.map +1 -0
  11. package/dist/index.d.ts +2810 -11
  12. package/dist/index.js +2425 -43
  13. package/dist/index.js.map +1 -1
  14. package/dist/node-loader.d.ts +18 -0
  15. package/dist/node-loader.js +47 -0
  16. package/dist/node-loader.js.map +1 -0
  17. package/dist/rollup.d.ts +8 -0
  18. package/dist/rollup.js +14 -0
  19. package/dist/rollup.js.map +1 -0
  20. package/dist/rspack.d.ts +7 -0
  21. package/dist/rspack.js +14 -0
  22. package/dist/rspack.js.map +1 -0
  23. package/dist/unplugin-6wnvFiEo.d.ts +17 -0
  24. package/dist/vite.d.ts +8 -17
  25. package/dist/vite.js +13 -33
  26. package/dist/vite.js.map +1 -1
  27. package/dist/webpack.d.ts +8 -0
  28. package/dist/webpack.js +14 -0
  29. package/dist/webpack.js.map +1 -0
  30. package/package.json +40 -22
  31. package/dist/analyzer/index.d.ts +0 -6
  32. package/dist/analyzer/index.d.ts.map +0 -1
  33. package/dist/analyzer/index.js +0 -6
  34. package/dist/analyzer/index.js.map +0 -1
  35. package/dist/analyzer/scope.d.ts +0 -77
  36. package/dist/analyzer/scope.d.ts.map +0 -1
  37. package/dist/analyzer/scope.js +0 -296
  38. package/dist/analyzer/scope.js.map +0 -1
  39. package/dist/analyzer/validator.d.ts +0 -60
  40. package/dist/analyzer/validator.d.ts.map +0 -1
  41. package/dist/analyzer/validator.js +0 -439
  42. package/dist/analyzer/validator.js.map +0 -1
  43. package/dist/api/compile-mel-patch-collector.d.ts +0 -32
  44. package/dist/api/compile-mel-patch-collector.d.ts.map +0 -1
  45. package/dist/api/compile-mel-patch-collector.js +0 -425
  46. package/dist/api/compile-mel-patch-collector.js.map +0 -1
  47. package/dist/api/compile-mel-patch-expr.d.ts +0 -9
  48. package/dist/api/compile-mel-patch-expr.d.ts.map +0 -1
  49. package/dist/api/compile-mel-patch-expr.js +0 -179
  50. package/dist/api/compile-mel-patch-expr.js.map +0 -1
  51. package/dist/api/compile-mel-patch-location.d.ts +0 -10
  52. package/dist/api/compile-mel-patch-location.d.ts.map +0 -1
  53. package/dist/api/compile-mel-patch-location.js +0 -48
  54. package/dist/api/compile-mel-patch-location.js.map +0 -1
  55. package/dist/api/compile-mel-patch.d.ts +0 -6
  56. package/dist/api/compile-mel-patch.d.ts.map +0 -1
  57. package/dist/api/compile-mel-patch.js +0 -244
  58. package/dist/api/compile-mel-patch.js.map +0 -1
  59. package/dist/api/compile-mel.d.ts +0 -126
  60. package/dist/api/compile-mel.d.ts.map +0 -1
  61. package/dist/api/compile-mel.js +0 -114
  62. package/dist/api/compile-mel.js.map +0 -1
  63. package/dist/api/index.d.ts +0 -10
  64. package/dist/api/index.d.ts.map +0 -1
  65. package/dist/api/index.js +0 -9
  66. package/dist/api/index.js.map +0 -1
  67. package/dist/diagnostics/codes.d.ts +0 -25
  68. package/dist/diagnostics/codes.d.ts.map +0 -1
  69. package/dist/diagnostics/codes.js +0 -154
  70. package/dist/diagnostics/codes.js.map +0 -1
  71. package/dist/diagnostics/index.d.ts +0 -6
  72. package/dist/diagnostics/index.d.ts.map +0 -1
  73. package/dist/diagnostics/index.js +0 -6
  74. package/dist/diagnostics/index.js.map +0 -1
  75. package/dist/diagnostics/types.d.ts +0 -67
  76. package/dist/diagnostics/types.d.ts.map +0 -1
  77. package/dist/diagnostics/types.js +0 -58
  78. package/dist/diagnostics/types.js.map +0 -1
  79. package/dist/evaluation/context.d.ts +0 -91
  80. package/dist/evaluation/context.d.ts.map +0 -1
  81. package/dist/evaluation/context.js +0 -53
  82. package/dist/evaluation/context.js.map +0 -1
  83. package/dist/evaluation/evaluate-expr.d.ts +0 -24
  84. package/dist/evaluation/evaluate-expr.d.ts.map +0 -1
  85. package/dist/evaluation/evaluate-expr.js +0 -577
  86. package/dist/evaluation/evaluate-expr.js.map +0 -1
  87. package/dist/evaluation/evaluate-patch.d.ts +0 -123
  88. package/dist/evaluation/evaluate-patch.d.ts.map +0 -1
  89. package/dist/evaluation/evaluate-patch.js +0 -202
  90. package/dist/evaluation/evaluate-patch.js.map +0 -1
  91. package/dist/evaluation/evaluate-runtime-patch.d.ts +0 -86
  92. package/dist/evaluation/evaluate-runtime-patch.d.ts.map +0 -1
  93. package/dist/evaluation/evaluate-runtime-patch.js +0 -185
  94. package/dist/evaluation/evaluate-runtime-patch.js.map +0 -1
  95. package/dist/evaluation/index.d.ts +0 -15
  96. package/dist/evaluation/index.d.ts.map +0 -1
  97. package/dist/evaluation/index.js +0 -13
  98. package/dist/evaluation/index.js.map +0 -1
  99. package/dist/generator/index.d.ts +0 -7
  100. package/dist/generator/index.d.ts.map +0 -1
  101. package/dist/generator/index.js +0 -7
  102. package/dist/generator/index.js.map +0 -1
  103. package/dist/generator/ir.d.ts +0 -348
  104. package/dist/generator/ir.d.ts.map +0 -1
  105. package/dist/generator/ir.js +0 -715
  106. package/dist/generator/ir.js.map +0 -1
  107. package/dist/generator/lowering.d.ts +0 -11
  108. package/dist/generator/lowering.d.ts.map +0 -1
  109. package/dist/generator/lowering.js +0 -369
  110. package/dist/generator/lowering.js.map +0 -1
  111. package/dist/generator/normalizer.d.ts +0 -16
  112. package/dist/generator/normalizer.d.ts.map +0 -1
  113. package/dist/generator/normalizer.js +0 -181
  114. package/dist/generator/normalizer.js.map +0 -1
  115. package/dist/index.d.ts.map +0 -1
  116. package/dist/lexer/index.d.ts +0 -7
  117. package/dist/lexer/index.d.ts.map +0 -1
  118. package/dist/lexer/index.js +0 -7
  119. package/dist/lexer/index.js.map +0 -1
  120. package/dist/lexer/lexer.d.ts +0 -59
  121. package/dist/lexer/lexer.d.ts.map +0 -1
  122. package/dist/lexer/lexer.js +0 -433
  123. package/dist/lexer/lexer.js.map +0 -1
  124. package/dist/lexer/source-location.d.ts +0 -41
  125. package/dist/lexer/source-location.d.ts.map +0 -1
  126. package/dist/lexer/source-location.js +0 -33
  127. package/dist/lexer/source-location.js.map +0 -1
  128. package/dist/lexer/tokens.d.ts +0 -47
  129. package/dist/lexer/tokens.d.ts.map +0 -1
  130. package/dist/lexer/tokens.js +0 -73
  131. package/dist/lexer/tokens.js.map +0 -1
  132. package/dist/loader.d.ts +0 -23
  133. package/dist/loader.d.ts.map +0 -1
  134. package/dist/loader.js +0 -62
  135. package/dist/loader.js.map +0 -1
  136. package/dist/lowering/context.d.ts +0 -96
  137. package/dist/lowering/context.d.ts.map +0 -1
  138. package/dist/lowering/context.js +0 -42
  139. package/dist/lowering/context.js.map +0 -1
  140. package/dist/lowering/errors.d.ts +0 -84
  141. package/dist/lowering/errors.d.ts.map +0 -1
  142. package/dist/lowering/errors.js +0 -81
  143. package/dist/lowering/errors.js.map +0 -1
  144. package/dist/lowering/index.d.ts +0 -20
  145. package/dist/lowering/index.d.ts.map +0 -1
  146. package/dist/lowering/index.js +0 -13
  147. package/dist/lowering/index.js.map +0 -1
  148. package/dist/lowering/lower-expr.d.ts +0 -76
  149. package/dist/lowering/lower-expr.d.ts.map +0 -1
  150. package/dist/lowering/lower-expr.js +0 -366
  151. package/dist/lowering/lower-expr.js.map +0 -1
  152. package/dist/lowering/lower-patch.d.ts +0 -231
  153. package/dist/lowering/lower-patch.d.ts.map +0 -1
  154. package/dist/lowering/lower-patch.js +0 -146
  155. package/dist/lowering/lower-patch.js.map +0 -1
  156. package/dist/lowering/lower-runtime-patch.d.ts +0 -100
  157. package/dist/lowering/lower-runtime-patch.d.ts.map +0 -1
  158. package/dist/lowering/lower-runtime-patch.js +0 -49
  159. package/dist/lowering/lower-runtime-patch.js.map +0 -1
  160. package/dist/mel-module.d.ts +0 -13
  161. package/dist/mel-module.d.ts.map +0 -1
  162. package/dist/mel-module.js +0 -33
  163. package/dist/mel-module.js.map +0 -1
  164. package/dist/parser/ast.d.ts +0 -344
  165. package/dist/parser/ast.d.ts.map +0 -1
  166. package/dist/parser/ast.js +0 -24
  167. package/dist/parser/ast.js.map +0 -1
  168. package/dist/parser/index.d.ts +0 -7
  169. package/dist/parser/index.d.ts.map +0 -1
  170. package/dist/parser/index.js +0 -7
  171. package/dist/parser/index.js.map +0 -1
  172. package/dist/parser/parser.d.ts +0 -92
  173. package/dist/parser/parser.d.ts.map +0 -1
  174. package/dist/parser/parser.js +0 -892
  175. package/dist/parser/parser.js.map +0 -1
  176. package/dist/parser/precedence.d.ts +0 -44
  177. package/dist/parser/precedence.d.ts.map +0 -1
  178. package/dist/parser/precedence.js +0 -69
  179. package/dist/parser/precedence.js.map +0 -1
  180. package/dist/renderer/expr-node.d.ts +0 -172
  181. package/dist/renderer/expr-node.d.ts.map +0 -1
  182. package/dist/renderer/expr-node.js +0 -218
  183. package/dist/renderer/expr-node.js.map +0 -1
  184. package/dist/renderer/fragment.d.ts +0 -84
  185. package/dist/renderer/fragment.d.ts.map +0 -1
  186. package/dist/renderer/fragment.js +0 -172
  187. package/dist/renderer/fragment.js.map +0 -1
  188. package/dist/renderer/index.d.ts +0 -23
  189. package/dist/renderer/index.d.ts.map +0 -1
  190. package/dist/renderer/index.js +0 -27
  191. package/dist/renderer/index.js.map +0 -1
  192. package/dist/renderer/patch-op.d.ts +0 -82
  193. package/dist/renderer/patch-op.d.ts.map +0 -1
  194. package/dist/renderer/patch-op.js +0 -204
  195. package/dist/renderer/patch-op.js.map +0 -1
  196. package/dist/renderer/type-expr.d.ts +0 -61
  197. package/dist/renderer/type-expr.d.ts.map +0 -1
  198. package/dist/renderer/type-expr.js +0 -131
  199. package/dist/renderer/type-expr.js.map +0 -1
  200. package/dist/vite.d.ts.map +0 -1
  201. package/loader.cjs +0 -22
package/dist/index.d.ts CHANGED
@@ -1,17 +1,2816 @@
1
+ import { ExprNode as ExprNode$2, PatchPath, Patch } from '@manifesto-ai/core';
2
+
3
+ /**
4
+ * Source Location Types
5
+ * Tracks positions in MEL source code for error reporting
6
+ */
7
+ /**
8
+ * A position in source code (1-based line/column)
9
+ */
10
+ interface Position {
11
+ /** 1-based line number */
12
+ line: number;
13
+ /** 1-based column number */
14
+ column: number;
15
+ /** 0-based byte offset from start of source */
16
+ offset: number;
17
+ }
18
+ /**
19
+ * A span in source code (start to end)
20
+ */
21
+ interface SourceLocation {
22
+ start: Position;
23
+ end: Position;
24
+ /** Optional source file path */
25
+ source?: string;
26
+ }
27
+ /**
28
+ * Create a position
29
+ */
30
+ declare function createPosition(line: number, column: number, offset: number): Position;
31
+ /**
32
+ * Create a source location from two positions
33
+ */
34
+ declare function createLocation(start: Position, end: Position, source?: string): SourceLocation;
35
+ /**
36
+ * Create a zero-width location at a position
37
+ */
38
+ declare function createPointLocation(pos: Position, source?: string): SourceLocation;
39
+ /**
40
+ * Merge two locations into one spanning both
41
+ */
42
+ declare function mergeLocations(a: SourceLocation, b: SourceLocation): SourceLocation;
43
+
44
+ /**
45
+ * Token Types for MEL Lexer
46
+ * Based on MEL SPEC v0.3.3 Section 3
47
+ */
48
+
49
+ /**
50
+ * All token kinds in MEL
51
+ */
52
+ type TokenKind = "DOMAIN" | "STATE" | "COMPUTED" | "ACTION" | "EFFECT" | "WHEN" | "ONCE" | "PATCH" | "UNSET" | "MERGE" | "TRUE" | "FALSE" | "NULL" | "AS" | "AVAILABLE" | "FAIL" | "STOP" | "WITH" | "TYPE" | "IMPORT" | "FROM" | "EXPORT" | "PLUS" | "MINUS" | "STAR" | "SLASH" | "PERCENT" | "EQ_EQ" | "BANG_EQ" | "LT" | "LT_EQ" | "GT" | "GT_EQ" | "AMP_AMP" | "PIPE_PIPE" | "BANG" | "QUESTION_QUESTION" | "QUESTION" | "COLON" | "EQ" | "LPAREN" | "RPAREN" | "LBRACE" | "RBRACE" | "LBRACKET" | "RBRACKET" | "COMMA" | "SEMICOLON" | "DOT" | "PIPE" | "NUMBER" | "STRING" | "IDENTIFIER" | "SYSTEM_IDENT" | "ITEM" | "EOF" | "ERROR";
53
+ /**
54
+ * A token produced by the lexer
55
+ */
56
+ interface Token {
57
+ kind: TokenKind;
58
+ /** The raw text of the token */
59
+ lexeme: string;
60
+ /** Parsed value for literals */
61
+ value?: unknown;
62
+ /** Location in source */
63
+ location: SourceLocation;
64
+ }
65
+ /**
66
+ * Keywords lookup table
67
+ */
68
+ declare const KEYWORDS: Record<string, TokenKind>;
69
+ /**
70
+ * Reserved keywords (JS keywords that are forbidden in MEL)
71
+ */
72
+ declare const RESERVED_KEYWORDS: Set<string>;
73
+ /**
74
+ * Check if a token is a keyword
75
+ */
76
+ declare function isKeyword(lexeme: string): boolean;
77
+ /**
78
+ * Check if a token is a reserved word
79
+ */
80
+ declare function isReserved(lexeme: string): boolean;
81
+ /**
82
+ * Get keyword token kind, or undefined if not a keyword
83
+ * Note: Uses Object.hasOwn to avoid prototype pollution (e.g., "toString")
84
+ */
85
+ declare function getKeywordKind(lexeme: string): TokenKind | undefined;
86
+ /**
87
+ * Create a token
88
+ */
89
+ declare function createToken(kind: TokenKind, lexeme: string, location: SourceLocation, value?: unknown): Token;
90
+
91
+ /**
92
+ * Diagnostic Types for MEL Compiler
93
+ * Error and warning reporting structures
94
+ */
95
+
96
+ /**
97
+ * Severity level of a diagnostic
98
+ */
99
+ type DiagnosticSeverity = "error" | "warning" | "info";
100
+ /**
101
+ * A diagnostic message (error, warning, or info)
102
+ */
103
+ interface Diagnostic {
104
+ /** Severity level */
105
+ severity: DiagnosticSeverity;
106
+ /** Error code (e.g., "MEL001", "MEL_LEXER") */
107
+ code: string;
108
+ /** Human-readable message */
109
+ message: string;
110
+ /** Location in source */
111
+ location: SourceLocation;
112
+ /** The source line containing the error */
113
+ source?: string;
114
+ /** Suggested fix */
115
+ suggestion?: string;
116
+ /** Related diagnostics */
117
+ related?: RelatedDiagnostic[];
118
+ }
119
+ /**
120
+ * A related diagnostic (for multi-location errors)
121
+ */
122
+ interface RelatedDiagnostic {
123
+ message: string;
124
+ location: SourceLocation;
125
+ }
126
+ /**
127
+ * Create an error diagnostic
128
+ */
129
+ declare function createError(code: string, message: string, location: SourceLocation, options?: {
130
+ source?: string;
131
+ suggestion?: string;
132
+ related?: RelatedDiagnostic[];
133
+ }): Diagnostic;
134
+ /**
135
+ * Create a warning diagnostic
136
+ */
137
+ declare function createWarning(code: string, message: string, location: SourceLocation, options?: {
138
+ source?: string;
139
+ suggestion?: string;
140
+ }): Diagnostic;
141
+ /**
142
+ * Create an info diagnostic
143
+ */
144
+ declare function createInfo(code: string, message: string, location: SourceLocation): Diagnostic;
145
+ /**
146
+ * Check if a diagnostic is an error
147
+ */
148
+ declare function isError(diagnostic: Diagnostic): boolean;
149
+ /**
150
+ * Check if any diagnostics contain errors
151
+ */
152
+ declare function hasErrors(diagnostics: Diagnostic[]): boolean;
153
+ /**
154
+ * Filter diagnostics by severity
155
+ */
156
+ declare function filterBySeverity(diagnostics: Diagnostic[], severity: DiagnosticSeverity): Diagnostic[];
157
+
158
+ /**
159
+ * MEL Lexer
160
+ * Tokenizes MEL source code based on SPEC v0.3.1 Section 3
161
+ */
162
+
163
+ /**
164
+ * Result of lexical analysis
165
+ */
166
+ interface LexResult {
167
+ tokens: Token[];
168
+ diagnostics: Diagnostic[];
169
+ }
170
+ /**
171
+ * Lexer for MEL source code
172
+ */
173
+ declare class Lexer {
174
+ private source;
175
+ private sourcePath?;
176
+ private tokens;
177
+ private diagnostics;
178
+ private start;
179
+ private current;
180
+ private line;
181
+ private column;
182
+ private lineStart;
183
+ constructor(source: string, sourcePath?: string);
184
+ /**
185
+ * Tokenize the source code
186
+ */
187
+ tokenize(): LexResult;
188
+ private scanToken;
189
+ private lineComment;
190
+ private blockComment;
191
+ private string;
192
+ private number;
193
+ private identifier;
194
+ private systemIdentifier;
195
+ private isAtEnd;
196
+ private advance;
197
+ private peek;
198
+ private peekNext;
199
+ private match;
200
+ private newline;
201
+ private isDigit;
202
+ private isHexDigit;
203
+ private isAlpha;
204
+ private isAlphaNumeric;
205
+ private currentLocation;
206
+ private positionAt;
207
+ private addToken;
208
+ private error;
209
+ private getSourceLine;
210
+ }
211
+ /**
212
+ * Tokenize MEL source code
213
+ */
214
+ declare function tokenize(source: string, sourcePath?: string): LexResult;
215
+
216
+ /**
217
+ * AST Node Types for MEL Parser
218
+ * Based on MEL SPEC v0.3.3 Section 4
219
+ */
220
+
221
+ /**
222
+ * Base interface for all AST nodes
223
+ */
224
+ interface ASTNode {
225
+ location: SourceLocation;
226
+ }
227
+ /**
228
+ * Root node of a MEL program
229
+ */
230
+ interface ProgramNode extends ASTNode {
231
+ kind: "program";
232
+ imports: ImportNode[];
233
+ domain: DomainNode;
234
+ }
235
+ /**
236
+ * Import declaration
237
+ */
238
+ interface ImportNode extends ASTNode {
239
+ kind: "import";
240
+ names: string[];
241
+ from: string;
242
+ }
243
+ /**
244
+ * Domain declaration
245
+ */
246
+ interface DomainNode extends ASTNode {
247
+ kind: "domain";
248
+ name: string;
249
+ /** v0.3.3: Named type declarations */
250
+ types: TypeDeclNode[];
251
+ members: DomainMember[];
252
+ }
253
+ /**
254
+ * Domain member types
255
+ */
256
+ type DomainMember = StateNode | ComputedNode | ActionNode | FlowDeclNode;
257
+ /**
258
+ * Type declaration (v0.3.3)
259
+ * Syntax: type Name = TypeExpr
260
+ */
261
+ interface TypeDeclNode extends ASTNode {
262
+ kind: "typeDecl";
263
+ name: string;
264
+ typeExpr: TypeExprNode;
265
+ }
266
+ /**
267
+ * State block declaration
268
+ */
269
+ interface StateNode extends ASTNode {
270
+ kind: "state";
271
+ fields: StateFieldNode[];
272
+ }
273
+ /**
274
+ * State field declaration
275
+ */
276
+ interface StateFieldNode extends ASTNode {
277
+ kind: "stateField";
278
+ name: string;
279
+ typeExpr: TypeExprNode;
280
+ initializer?: ExprNode$1;
281
+ }
282
+ /**
283
+ * Computed value declaration
284
+ */
285
+ interface ComputedNode extends ASTNode {
286
+ kind: "computed";
287
+ name: string;
288
+ expression: ExprNode$1;
289
+ }
290
+ /**
291
+ * Action declaration
292
+ */
293
+ interface ActionNode extends ASTNode {
294
+ kind: "action";
295
+ name: string;
296
+ params: ParamNode[];
297
+ /** v0.3.2: Optional availability condition */
298
+ available?: ExprNode$1;
299
+ body: GuardedStmtNode[];
300
+ }
301
+ /**
302
+ * Flow declaration (v0.7.0 / ADR-013a)
303
+ * Raw AST preserves flow declarations until the expansion pass removes them.
304
+ */
305
+ interface FlowDeclNode extends ASTNode {
306
+ kind: "flow";
307
+ name: string;
308
+ params: ParamNode[];
309
+ body: FlowStmtNode[];
310
+ }
311
+ /**
312
+ * Parameter declaration
313
+ */
314
+ interface ParamNode extends ASTNode {
315
+ kind: "param";
316
+ name: string;
317
+ typeExpr: TypeExprNode;
318
+ }
319
+ /**
320
+ * Guarded statement types (top-level in action body)
321
+ */
322
+ type GuardedStmtNode = WhenStmtNode | OnceStmtNode | OnceIntentStmtNode | IncludeStmtNode | FailStmtNode | StopStmtNode;
323
+ /**
324
+ * Raw flow statement types (top-level in flow body).
325
+ * Parser stays permissive; validation narrows the allowed subset.
326
+ */
327
+ type FlowStmtNode = WhenStmtNode | IncludeStmtNode | OnceStmtNode | OnceIntentStmtNode | PatchStmtNode | EffectStmtNode;
328
+ /**
329
+ * Inner statement types (inside guards)
330
+ */
331
+ type InnerStmtNode = PatchStmtNode | EffectStmtNode | WhenStmtNode | OnceStmtNode | OnceIntentStmtNode | IncludeStmtNode | FailStmtNode | StopStmtNode;
332
+ /**
333
+ * When guard statement
334
+ */
335
+ interface WhenStmtNode extends ASTNode {
336
+ kind: "when";
337
+ condition: ExprNode$1;
338
+ body: InnerStmtNode[];
339
+ }
340
+ /**
341
+ * Once guard statement (per-intent idempotency)
342
+ */
343
+ interface OnceStmtNode extends ASTNode {
344
+ kind: "once";
345
+ marker: PathNode;
346
+ condition?: ExprNode$1;
347
+ body: InnerStmtNode[];
348
+ }
349
+ /**
350
+ * Once-intent guard statement (per-intent idempotency sugar)
351
+ */
352
+ interface OnceIntentStmtNode extends ASTNode {
353
+ kind: "onceIntent";
354
+ condition?: ExprNode$1;
355
+ body: InnerStmtNode[];
356
+ }
357
+ /**
358
+ * Include statement (v0.7.0 / ADR-013a)
359
+ * Raw AST preserves include sites until the expansion pass inlines them.
360
+ */
361
+ interface IncludeStmtNode extends ASTNode {
362
+ kind: "include";
363
+ flowName: string;
364
+ args: ExprNode$1[];
365
+ }
366
+ /**
367
+ * Patch statement
368
+ */
369
+ interface PatchStmtNode extends ASTNode {
370
+ kind: "patch";
371
+ path: PathNode;
372
+ op: "set" | "unset" | "merge";
373
+ value?: ExprNode$1;
374
+ }
375
+ /**
376
+ * Effect statement
377
+ */
378
+ interface EffectStmtNode extends ASTNode {
379
+ kind: "effect";
380
+ effectType: string;
381
+ args: EffectArgNode[];
382
+ }
383
+ /**
384
+ * Effect argument
385
+ */
386
+ interface EffectArgNode extends ASTNode {
387
+ kind: "effectArg";
388
+ name: string;
389
+ value: ExprNode$1 | PathNode;
390
+ isPath: boolean;
391
+ }
392
+ /**
393
+ * Fail statement (v0.3.2) - terminates flow with error
394
+ * Compiles to FlowNode { kind: "fail", code, message }
395
+ */
396
+ interface FailStmtNode extends ASTNode {
397
+ kind: "fail";
398
+ code: string;
399
+ message?: ExprNode$1;
400
+ }
401
+ /**
402
+ * Stop statement (v0.3.2) - early exit, no error
403
+ * Compiles to FlowNode { kind: "halt", reason }
404
+ */
405
+ interface StopStmtNode extends ASTNode {
406
+ kind: "stop";
407
+ reason: string;
408
+ }
409
+ /**
410
+ * Type expression node
411
+ */
412
+ type TypeExprNode = SimpleTypeNode | UnionTypeNode | ArrayTypeNode | RecordTypeNode | LiteralTypeNode | ObjectTypeNode;
413
+ interface SimpleTypeNode extends ASTNode {
414
+ kind: "simpleType";
415
+ name: string;
416
+ }
417
+ interface UnionTypeNode extends ASTNode {
418
+ kind: "unionType";
419
+ types: TypeExprNode[];
420
+ }
421
+ interface ArrayTypeNode extends ASTNode {
422
+ kind: "arrayType";
423
+ elementType: TypeExprNode;
424
+ }
425
+ interface RecordTypeNode extends ASTNode {
426
+ kind: "recordType";
427
+ keyType: TypeExprNode;
428
+ valueType: TypeExprNode;
429
+ }
430
+ interface LiteralTypeNode extends ASTNode {
431
+ kind: "literalType";
432
+ value: string | number | boolean | null;
433
+ }
434
+ /**
435
+ * Object type node (v0.3.3)
436
+ * Represents inline object types: { field: Type, ... }
437
+ * Note: In state fields, this triggers W012 warning (use named type instead)
438
+ */
439
+ interface ObjectTypeNode extends ASTNode {
440
+ kind: "objectType";
441
+ fields: TypeFieldNode[];
442
+ }
443
+ /**
444
+ * Type field within an object type
445
+ */
446
+ interface TypeFieldNode extends ASTNode {
447
+ kind: "typeField";
448
+ name: string;
449
+ typeExpr: TypeExprNode;
450
+ optional: boolean;
451
+ }
452
+ /**
453
+ * All expression types
454
+ */
455
+ type ExprNode$1 = LiteralExprNode | IdentifierExprNode | SystemIdentExprNode | IterationVarExprNode | PropertyAccessExprNode | IndexAccessExprNode | FunctionCallExprNode | UnaryExprNode | BinaryExprNode | TernaryExprNode | ObjectLiteralExprNode | ArrayLiteralExprNode;
456
+ /**
457
+ * Literal expression (number, string, boolean, null)
458
+ */
459
+ interface LiteralExprNode extends ASTNode {
460
+ kind: "literal";
461
+ value: unknown;
462
+ literalType: "number" | "string" | "boolean" | "null";
463
+ }
464
+ /**
465
+ * Identifier expression
466
+ */
467
+ interface IdentifierExprNode extends ASTNode {
468
+ kind: "identifier";
469
+ name: string;
470
+ }
471
+ /**
472
+ * System identifier expression ($system.*, $meta.*, $input.*)
473
+ */
474
+ interface SystemIdentExprNode extends ASTNode {
475
+ kind: "systemIdent";
476
+ path: string[];
477
+ }
478
+ /**
479
+ * Iteration variable expression ($item only)
480
+ * v0.3.2: $acc removed - reduce pattern deprecated
481
+ */
482
+ interface IterationVarExprNode extends ASTNode {
483
+ kind: "iterationVar";
484
+ name: "item";
485
+ }
486
+ /**
487
+ * Property access expression (a.b)
488
+ */
489
+ interface PropertyAccessExprNode extends ASTNode {
490
+ kind: "propertyAccess";
491
+ object: ExprNode$1;
492
+ property: string;
493
+ }
494
+ /**
495
+ * Index access expression (a[b])
496
+ */
497
+ interface IndexAccessExprNode extends ASTNode {
498
+ kind: "indexAccess";
499
+ object: ExprNode$1;
500
+ index: ExprNode$1;
501
+ }
502
+ /**
503
+ * Function call expression
504
+ */
505
+ interface FunctionCallExprNode extends ASTNode {
506
+ kind: "functionCall";
507
+ name: string;
508
+ args: ExprNode$1[];
509
+ }
510
+ /**
511
+ * Unary expression (!a, -a)
512
+ */
513
+ interface UnaryExprNode extends ASTNode {
514
+ kind: "unary";
515
+ operator: "!" | "-";
516
+ operand: ExprNode$1;
517
+ }
518
+ /**
519
+ * Binary operators
520
+ */
521
+ type BinaryOperator = "+" | "-" | "*" | "/" | "%" | "==" | "!=" | "<" | "<=" | ">" | ">=" | "&&" | "||" | "??";
522
+ /**
523
+ * Binary expression (a + b, a && b, etc.)
524
+ */
525
+ interface BinaryExprNode extends ASTNode {
526
+ kind: "binary";
527
+ operator: BinaryOperator;
528
+ left: ExprNode$1;
529
+ right: ExprNode$1;
530
+ }
531
+ /**
532
+ * Ternary expression (a ? b : c)
533
+ */
534
+ interface TernaryExprNode extends ASTNode {
535
+ kind: "ternary";
536
+ condition: ExprNode$1;
537
+ consequent: ExprNode$1;
538
+ alternate: ExprNode$1;
539
+ }
540
+ /**
541
+ * Object literal expression ({ a: 1, b: 2 })
542
+ */
543
+ interface ObjectLiteralExprNode extends ASTNode {
544
+ kind: "objectLiteral";
545
+ properties: ObjectPropertyNode[];
546
+ }
547
+ interface ObjectPropertyNode extends ASTNode {
548
+ kind: "objectProperty";
549
+ key: string;
550
+ value: ExprNode$1;
551
+ }
552
+ /**
553
+ * Array literal expression ([1, 2, 3])
554
+ */
555
+ interface ArrayLiteralExprNode extends ASTNode {
556
+ kind: "arrayLiteral";
557
+ elements: ExprNode$1[];
558
+ }
559
+ /**
560
+ * Path node for patch targets and effect destinations
561
+ */
562
+ interface PathNode extends ASTNode {
563
+ kind: "path";
564
+ segments: PathSegmentNode[];
565
+ }
566
+ type PathSegmentNode = PropertySegmentNode | IndexSegmentNode;
567
+ interface PropertySegmentNode extends ASTNode {
568
+ kind: "propertySegment";
569
+ name: string;
570
+ }
571
+ interface IndexSegmentNode extends ASTNode {
572
+ kind: "indexSegment";
573
+ index: ExprNode$1;
574
+ }
575
+ /**
576
+ * Check if a node is an expression
577
+ */
578
+ declare function isExprNode(node: ASTNode): node is ExprNode$1;
579
+ /**
580
+ * Check if a node is a statement
581
+ */
582
+ declare function isStmtNode(node: ASTNode): node is InnerStmtNode;
583
+
584
+ /**
585
+ * Operator Precedence for MEL Parser
586
+ * Based on MEL SPEC v0.3.1 Section 4.9
587
+ */
588
+
589
+ /**
590
+ * Precedence levels (higher = binds tighter)
591
+ */
592
+ declare const enum Precedence {
593
+ NONE = 0,
594
+ TERNARY = 1,// ? :
595
+ NULLISH = 2,// ??
596
+ OR = 3,// ||
597
+ AND = 4,// &&
598
+ EQUALITY = 5,// == !=
599
+ COMPARISON = 6,// < <= > >=
600
+ ADDITIVE = 7,// + -
601
+ MULTIPLICATIVE = 8,// * / %
602
+ UNARY = 9,// ! -
603
+ CALL = 10,// ()
604
+ ACCESS = 11
605
+ }
606
+ /**
607
+ * Get the precedence of a binary operator token
608
+ */
609
+ declare function getBinaryPrecedence(kind: TokenKind): Precedence;
610
+ /**
611
+ * Map token kind to binary operator
612
+ */
613
+ declare function tokenToBinaryOp(kind: TokenKind): BinaryOperator | null;
614
+ /**
615
+ * Check if a token is a binary operator
616
+ */
617
+ declare function isBinaryOp(kind: TokenKind): boolean;
618
+ /**
619
+ * Check if a token is a unary operator
620
+ */
621
+ declare function isUnaryOp(kind: TokenKind): boolean;
622
+ /**
623
+ * Check if operators are right-associative
624
+ */
625
+ declare function isRightAssociative(kind: TokenKind): boolean;
626
+
627
+ /**
628
+ * MEL Parser
629
+ * Recursive descent parser with Pratt parsing for expressions
630
+ * Based on MEL SPEC v0.3.3 Section 4
631
+ */
632
+
633
+ /**
634
+ * Result of parsing
635
+ */
636
+ interface ParseResult {
637
+ program: ProgramNode | null;
638
+ diagnostics: Diagnostic[];
639
+ }
640
+ /**
641
+ * Parser for MEL source code
642
+ */
643
+ declare class Parser {
644
+ private tokens;
645
+ private current;
646
+ private diagnostics;
647
+ constructor(tokens: Token[]);
648
+ /**
649
+ * Parse tokens into an AST
650
+ */
651
+ parse(): ParseResult;
652
+ private parseProgram;
653
+ private parseImport;
654
+ private parseDomain;
655
+ /**
656
+ * v0.3.3: Parse type declaration
657
+ * Syntax: type Name = TypeExpr
658
+ */
659
+ private parseTypeDecl;
660
+ private parseDomainMember;
661
+ private parseState;
662
+ private parseStateField;
663
+ private parseComputed;
664
+ private parseAction;
665
+ private parseFlowDecl;
666
+ private parseParam;
667
+ private parseGuardedStmt;
668
+ private parseFlowStmt;
669
+ /**
670
+ * Skip tokens until we reach a recovery point (closing brace, guard keyword, or EOF).
671
+ */
672
+ private skipToRecoveryPoint;
673
+ private parseWhenStmt;
674
+ private parseOnceStmt;
675
+ private parseOnceIntentStmt;
676
+ private parseInnerStmt;
677
+ private parseIncludeStmt;
678
+ private parsePatchStmt;
679
+ private parseEffectStmt;
680
+ private parseEffectArg;
681
+ /**
682
+ * v0.3.2: Parse fail statement
683
+ * FailStmt ::= 'fail' StringLiteral ('with' Expr)?
684
+ */
685
+ private parseFailStmt;
686
+ /**
687
+ * v0.3.2: Parse stop statement
688
+ * StopStmt ::= 'stop' StringLiteral
689
+ */
690
+ private parseStopStmt;
691
+ private parseTypeExpr;
692
+ private parseBaseType;
693
+ /**
694
+ * v0.3.3: Parse object type
695
+ * Syntax: { field: Type, field?: Type, ... }
696
+ */
697
+ private parseObjectType;
698
+ private parseExpression;
699
+ private parseTernary;
700
+ private parsePrimary;
701
+ private parseFunctionCall;
702
+ private parsePostfix;
703
+ private parseObjectLiteral;
704
+ private parseArrayLiteral;
705
+ private parsePath;
706
+ private isUnaryContext;
707
+ private peek;
708
+ private peekNext;
709
+ private peekAt;
710
+ private previous;
711
+ private isAtEnd;
712
+ private advance;
713
+ private check;
714
+ private isOnceIntentContext;
715
+ private isFlowDeclContext;
716
+ private isIncludeContext;
717
+ private match;
718
+ private consume;
719
+ private error;
720
+ private errorAtCurrent;
721
+ }
722
+ /**
723
+ * Parse tokens into an AST
724
+ */
725
+ declare function parse(tokens: Token[]): ParseResult;
726
+
727
+ /**
728
+ * Scope Analysis for MEL
729
+ * Tracks variable scopes and resolves identifiers
730
+ * Based on MEL SPEC v0.3.1 Section 4.10
731
+ */
732
+
733
+ /**
734
+ * Symbol kinds
735
+ */
736
+ type SymbolKind = "state" | "computed" | "param" | "action" | "iteration";
737
+ /**
738
+ * Symbol information
739
+ */
740
+ interface Symbol {
741
+ name: string;
742
+ kind: SymbolKind;
743
+ location: SourceLocation;
744
+ type?: string;
745
+ }
746
+ /**
747
+ * Scope represents a lexical scope
748
+ */
749
+ declare class Scope {
750
+ readonly parent: Scope | null;
751
+ readonly symbols: Map<string, Symbol>;
752
+ readonly kind: "domain" | "action" | "guard";
753
+ constructor(kind: "domain" | "action" | "guard", parent?: Scope | null);
754
+ /**
755
+ * Define a new symbol in this scope
756
+ */
757
+ define(symbol: Symbol): void;
758
+ /**
759
+ * Look up a symbol, searching parent scopes if not found
760
+ */
761
+ lookup(name: string): Symbol | undefined;
762
+ /**
763
+ * Check if a symbol is defined in this scope (not parent scopes)
764
+ */
765
+ isDefined(name: string): boolean;
766
+ }
767
+ /**
768
+ * Result of scope analysis
769
+ */
770
+ interface ScopeAnalysisResult {
771
+ scopes: Map<string, Scope>;
772
+ diagnostics: Diagnostic[];
773
+ }
774
+ /**
775
+ * Scope Analyzer - builds scope tree and checks for errors
776
+ */
777
+ declare class ScopeAnalyzer {
778
+ private diagnostics;
779
+ private scopes;
780
+ private currentScope;
781
+ private domainScope;
782
+ /**
783
+ * Analyze a MEL program
784
+ */
785
+ analyze(program: ProgramNode): ScopeAnalysisResult;
786
+ private analyzeDomain;
787
+ private analyzeComputedExpr;
788
+ private analyzeAction;
789
+ private analyzeStmt;
790
+ private analyzeExpr;
791
+ private checkIdentifier;
792
+ private checkSystemIdent;
793
+ private validatePath;
794
+ private defineSymbol;
795
+ private error;
796
+ }
797
+ /**
798
+ * Analyze a MEL program for scope issues
799
+ */
800
+ declare function analyzeScope(program: ProgramNode): ScopeAnalysisResult;
801
+
802
+ /**
803
+ * Semantic Validator for MEL
804
+ * Validates semantic rules beyond syntax
805
+ * Based on MEL SPEC v0.3.3 and FDR-MEL-*
806
+ */
807
+
808
+ /**
809
+ * Result of semantic validation
810
+ */
811
+ interface ValidationResult {
812
+ valid: boolean;
813
+ diagnostics: Diagnostic[];
814
+ }
815
+ /**
816
+ * Semantic Validator
817
+ */
818
+ declare class SemanticValidator {
819
+ private ctx;
820
+ private symbols;
821
+ /**
822
+ * Validate a MEL program
823
+ */
824
+ validate(program: ProgramNode): ValidationResult;
825
+ private validateDomain;
826
+ /**
827
+ * v0.3.3: Validate state fields for W012 (anonymous object types)
828
+ */
829
+ private validateState;
830
+ /**
831
+ * v0.3.3: Validate state field - check for anonymous object types (W012)
832
+ */
833
+ private validateStateField;
834
+ private validateStateInitializer;
835
+ /**
836
+ * v0.3.3: Check if a type expression contains anonymous object types
837
+ * Issues W012 warning for inline object types in state fields
838
+ */
839
+ private checkAnonymousObjectType;
840
+ private validateAction;
841
+ /**
842
+ * v0.3.3: Validate available expression is pure (E005)
843
+ * No $system.*, no effects, no $input.*
844
+ */
845
+ private validateAvailableExpr;
846
+ private validateGuardedStmt;
847
+ private validateWhen;
848
+ private validateOnce;
849
+ private validateOnceIntent;
850
+ private validatePatch;
851
+ private validateEffect;
852
+ private validateFail;
853
+ private validateStop;
854
+ private validateCondition;
855
+ private validateExpr;
856
+ private validateFunctionCall;
857
+ private validatePrimitiveEquality;
858
+ private error;
859
+ private warn;
860
+ }
861
+ /**
862
+ * Validate a MEL program semantically
863
+ */
864
+ declare function validateSemantics(program: ProgramNode): ValidationResult;
865
+
866
+ /**
867
+ * MEL Compiler Diagnostic Codes
868
+ * Based on MEL SPEC v0.3.3 Appendix A
869
+ */
870
+ /**
871
+ * Diagnostic code information
872
+ */
873
+ interface DiagnosticCode {
874
+ code: string;
875
+ message: string;
876
+ category: "syntax" | "semantic" | "type" | "system";
877
+ }
878
+ /**
879
+ * All diagnostic codes
880
+ */
881
+ declare const DIAGNOSTIC_CODES: Record<string, DiagnosticCode>;
882
+ /**
883
+ * Get diagnostic code information
884
+ */
885
+ declare function getDiagnosticInfo(code: string): DiagnosticCode | undefined;
886
+ /**
887
+ * Format a diagnostic code for display
888
+ */
889
+ declare function formatDiagnosticCode(code: string): string;
890
+
891
+ /**
892
+ * Plain-text Diagnostic Formatter
893
+ *
894
+ * Browser-safe (no ANSI colors). Produces human-readable error messages
895
+ * with optional source context and caret indicators.
896
+ *
897
+ * @module
898
+ */
899
+
900
+ /**
901
+ * Format a single diagnostic as plain text.
902
+ *
903
+ * Without source: `[MEL_PARSER] Expected '{' (3:15)`
904
+ * With source:
905
+ * ```
906
+ * [MEL_PARSER] Expected '{' (3:15)
907
+ * 3 | domain Bad bad syntax here }
908
+ * ^^^
909
+ * ```
910
+ */
911
+ declare function formatDiagnostic(diagnostic: Diagnostic, source?: string): string;
912
+ /**
913
+ * Format multiple diagnostics, separated by blank lines.
914
+ */
915
+ declare function formatDiagnostics(diagnostics: Diagnostic[], source?: string): string;
916
+
917
+ /**
918
+ * Lowering Context Types
919
+ *
920
+ * Defines contexts for expression and patch lowering.
921
+ *
922
+ * @see SPEC v0.4.0 §17.2
923
+ */
924
+ /**
925
+ * Allowed system path prefixes.
926
+ *
927
+ * In Translator path, only 'meta' and 'input' are allowed.
928
+ * 'system' is forbidden (requires Flow execution).
929
+ *
930
+ * @see FDR-MEL-071
931
+ */
932
+ type AllowedSysPrefix = "meta" | "input";
933
+ /**
934
+ * Context for single expression lowering.
935
+ *
936
+ * @see SPEC v0.4.0 §17.2
937
+ */
938
+ interface ExprLoweringContext {
939
+ /**
940
+ * Expression context mode.
941
+ * - 'schema': for addComputed, addConstraint, etc.
942
+ * - 'action': for guards, patches, effects
943
+ */
944
+ mode: "schema" | "action";
945
+ /**
946
+ * Allowed system path prefixes.
947
+ * In Translator path: only ["meta", "input"]
948
+ *
949
+ * @see FDR-MEL-071
950
+ */
951
+ allowSysPaths?: {
952
+ prefixes: AllowedSysPrefix[];
953
+ };
954
+ /**
955
+ * Function table version for call lowering.
956
+ */
957
+ fnTableVersion: string;
958
+ /**
959
+ * Action name (for action context).
960
+ */
961
+ actionName?: string;
962
+ /**
963
+ * Whether $item is allowed in this context.
964
+ * Only true for effect.args fields.
965
+ *
966
+ * @see FDR-MEL-068
967
+ */
968
+ allowItem?: boolean;
969
+ }
970
+ /**
971
+ * Context for patch lowering.
972
+ *
973
+ * NO mode field - Compiler determines context per op-field.
974
+ *
975
+ * @see SPEC v0.4.0 §17.2, AD-COMP-LOW-002
976
+ */
977
+ interface PatchLoweringContext {
978
+ /**
979
+ * Allowed system path prefixes.
980
+ * In Translator path: only ["meta", "input"]
981
+ *
982
+ * @see FDR-MEL-071
983
+ */
984
+ allowSysPaths?: {
985
+ prefixes: AllowedSysPrefix[];
986
+ };
987
+ /**
988
+ * Function table version for call lowering.
989
+ */
990
+ fnTableVersion: string;
991
+ /**
992
+ * Action name (for action-related ops).
993
+ */
994
+ actionName?: string;
995
+ }
996
+ /**
997
+ * Default expression lowering context for schema mode.
998
+ */
999
+ declare const DEFAULT_SCHEMA_CONTEXT: ExprLoweringContext;
1000
+ /**
1001
+ * Default expression lowering context for action mode.
1002
+ */
1003
+ declare const DEFAULT_ACTION_CONTEXT: ExprLoweringContext;
1004
+ /**
1005
+ * Context for effect.args (allows $item).
1006
+ */
1007
+ declare const EFFECT_ARGS_CONTEXT: ExprLoweringContext;
1008
+ /**
1009
+ * Default patch lowering context.
1010
+ */
1011
+ declare const DEFAULT_PATCH_CONTEXT: PatchLoweringContext;
1012
+
1013
+ /**
1014
+ * Expression Lowering
1015
+ *
1016
+ * Transforms MEL Canonical IR (8 kinds) to Core Runtime IR (30+ kinds).
1017
+ *
1018
+ * @see SPEC v0.4.0 §17
1019
+ */
1020
+
1021
+ /**
1022
+ * MEL primitive value.
1023
+ */
1024
+ type MelPrimitive = null | boolean | number | string;
1025
+ /**
1026
+ * MEL path segment.
1027
+ */
1028
+ type MelPathSegment = {
1029
+ kind: "prop";
1030
+ name: string;
1031
+ };
1032
+ /**
1033
+ * MEL path node array.
1034
+ */
1035
+ type MelPathNode = MelPathSegment[];
1036
+ /**
1037
+ * MEL system path as segment array.
1038
+ */
1039
+ type MelSystemPath = string[];
1040
+ /**
1041
+ * MEL object field.
1042
+ */
1043
+ type MelObjField = {
1044
+ key: string;
1045
+ value: MelExprNode;
1046
+ };
1047
+ /**
1048
+ * MEL Canonical IR (8 kinds).
1049
+ *
1050
+ * @see SPEC v0.4.0 §17.1.1
1051
+ */
1052
+ type MelExprNode = {
1053
+ kind: "lit";
1054
+ value: MelPrimitive;
1055
+ } | {
1056
+ kind: "var";
1057
+ name: "item";
1058
+ } | {
1059
+ kind: "sys";
1060
+ path: MelSystemPath;
1061
+ } | {
1062
+ kind: "get";
1063
+ base?: MelExprNode;
1064
+ path: MelPathNode;
1065
+ } | {
1066
+ kind: "field";
1067
+ object: MelExprNode;
1068
+ property: string;
1069
+ } | {
1070
+ kind: "call";
1071
+ fn: string;
1072
+ args: MelExprNode[];
1073
+ } | {
1074
+ kind: "obj";
1075
+ fields: MelObjField[];
1076
+ } | {
1077
+ kind: "arr";
1078
+ elements: MelExprNode[];
1079
+ };
1080
+ /**
1081
+ * Lower MEL expression to Core expression.
1082
+ *
1083
+ * @param input - MEL canonical IR expression
1084
+ * @param ctx - Lowering context
1085
+ * @returns Core runtime IR expression
1086
+ * @throws LoweringError if expression cannot be lowered
1087
+ *
1088
+ * @see SPEC v0.4.0 §17.3
1089
+ */
1090
+ declare function lowerExprNode(input: MelExprNode, ctx: ExprLoweringContext): ExprNode$2;
1091
+
1092
+ /**
1093
+ * IR Generator - Transforms MEL AST to Core DomainSchema
1094
+ * Based on MEL SPEC v0.3.3 Section 5
1095
+ */
1096
+
1097
+ /**
1098
+ * Core ExprNode types (simplified, matching core/schema/expr.ts)
1099
+ */
1100
+ type CoreExprNode = {
1101
+ kind: "lit";
1102
+ value: unknown;
1103
+ } | {
1104
+ kind: "get";
1105
+ path: string;
1106
+ } | {
1107
+ kind: "eq";
1108
+ left: CoreExprNode;
1109
+ right: CoreExprNode;
1110
+ } | {
1111
+ kind: "neq";
1112
+ left: CoreExprNode;
1113
+ right: CoreExprNode;
1114
+ } | {
1115
+ kind: "gt";
1116
+ left: CoreExprNode;
1117
+ right: CoreExprNode;
1118
+ } | {
1119
+ kind: "gte";
1120
+ left: CoreExprNode;
1121
+ right: CoreExprNode;
1122
+ } | {
1123
+ kind: "lt";
1124
+ left: CoreExprNode;
1125
+ right: CoreExprNode;
1126
+ } | {
1127
+ kind: "lte";
1128
+ left: CoreExprNode;
1129
+ right: CoreExprNode;
1130
+ } | {
1131
+ kind: "and";
1132
+ args: CoreExprNode[];
1133
+ } | {
1134
+ kind: "or";
1135
+ args: CoreExprNode[];
1136
+ } | {
1137
+ kind: "not";
1138
+ arg: CoreExprNode;
1139
+ } | {
1140
+ kind: "if";
1141
+ cond: CoreExprNode;
1142
+ then: CoreExprNode;
1143
+ else: CoreExprNode;
1144
+ } | {
1145
+ kind: "add";
1146
+ left: CoreExprNode;
1147
+ right: CoreExprNode;
1148
+ } | {
1149
+ kind: "sub";
1150
+ left: CoreExprNode;
1151
+ right: CoreExprNode;
1152
+ } | {
1153
+ kind: "mul";
1154
+ left: CoreExprNode;
1155
+ right: CoreExprNode;
1156
+ } | {
1157
+ kind: "div";
1158
+ left: CoreExprNode;
1159
+ right: CoreExprNode;
1160
+ } | {
1161
+ kind: "mod";
1162
+ left: CoreExprNode;
1163
+ right: CoreExprNode;
1164
+ } | {
1165
+ kind: "neg";
1166
+ arg: CoreExprNode;
1167
+ } | {
1168
+ kind: "abs";
1169
+ arg: CoreExprNode;
1170
+ } | {
1171
+ kind: "min";
1172
+ args: CoreExprNode[];
1173
+ } | {
1174
+ kind: "max";
1175
+ args: CoreExprNode[];
1176
+ } | {
1177
+ kind: "sumArray";
1178
+ array: CoreExprNode;
1179
+ } | {
1180
+ kind: "minArray";
1181
+ array: CoreExprNode;
1182
+ } | {
1183
+ kind: "maxArray";
1184
+ array: CoreExprNode;
1185
+ } | {
1186
+ kind: "floor";
1187
+ arg: CoreExprNode;
1188
+ } | {
1189
+ kind: "ceil";
1190
+ arg: CoreExprNode;
1191
+ } | {
1192
+ kind: "round";
1193
+ arg: CoreExprNode;
1194
+ } | {
1195
+ kind: "sqrt";
1196
+ arg: CoreExprNode;
1197
+ } | {
1198
+ kind: "pow";
1199
+ base: CoreExprNode;
1200
+ exponent: CoreExprNode;
1201
+ } | {
1202
+ kind: "concat";
1203
+ args: CoreExprNode[];
1204
+ } | {
1205
+ kind: "trim";
1206
+ str: CoreExprNode;
1207
+ } | {
1208
+ kind: "toLowerCase";
1209
+ str: CoreExprNode;
1210
+ } | {
1211
+ kind: "toUpperCase";
1212
+ str: CoreExprNode;
1213
+ } | {
1214
+ kind: "strLen";
1215
+ str: CoreExprNode;
1216
+ } | {
1217
+ kind: "substring";
1218
+ str: CoreExprNode;
1219
+ start: CoreExprNode;
1220
+ end?: CoreExprNode;
1221
+ } | {
1222
+ kind: "len";
1223
+ arg: CoreExprNode;
1224
+ } | {
1225
+ kind: "at";
1226
+ array: CoreExprNode;
1227
+ index: CoreExprNode;
1228
+ } | {
1229
+ kind: "first";
1230
+ array: CoreExprNode;
1231
+ } | {
1232
+ kind: "last";
1233
+ array: CoreExprNode;
1234
+ } | {
1235
+ kind: "slice";
1236
+ array: CoreExprNode;
1237
+ start: CoreExprNode;
1238
+ end?: CoreExprNode;
1239
+ } | {
1240
+ kind: "includes";
1241
+ array: CoreExprNode;
1242
+ item: CoreExprNode;
1243
+ } | {
1244
+ kind: "filter";
1245
+ array: CoreExprNode;
1246
+ predicate: CoreExprNode;
1247
+ } | {
1248
+ kind: "map";
1249
+ array: CoreExprNode;
1250
+ mapper: CoreExprNode;
1251
+ } | {
1252
+ kind: "find";
1253
+ array: CoreExprNode;
1254
+ predicate: CoreExprNode;
1255
+ } | {
1256
+ kind: "every";
1257
+ array: CoreExprNode;
1258
+ predicate: CoreExprNode;
1259
+ } | {
1260
+ kind: "some";
1261
+ array: CoreExprNode;
1262
+ predicate: CoreExprNode;
1263
+ } | {
1264
+ kind: "append";
1265
+ array: CoreExprNode;
1266
+ items: CoreExprNode[];
1267
+ } | {
1268
+ kind: "object";
1269
+ fields: Record<string, CoreExprNode>;
1270
+ } | {
1271
+ kind: "field";
1272
+ object: CoreExprNode;
1273
+ property: string;
1274
+ } | {
1275
+ kind: "keys";
1276
+ obj: CoreExprNode;
1277
+ } | {
1278
+ kind: "values";
1279
+ obj: CoreExprNode;
1280
+ } | {
1281
+ kind: "entries";
1282
+ obj: CoreExprNode;
1283
+ } | {
1284
+ kind: "merge";
1285
+ objects: CoreExprNode[];
1286
+ } | {
1287
+ kind: "typeof";
1288
+ arg: CoreExprNode;
1289
+ } | {
1290
+ kind: "isNull";
1291
+ arg: CoreExprNode;
1292
+ } | {
1293
+ kind: "coalesce";
1294
+ args: CoreExprNode[];
1295
+ } | {
1296
+ kind: "toString";
1297
+ arg: CoreExprNode;
1298
+ };
1299
+ type CompilerExprNode = MelExprNode;
1300
+ /**
1301
+ * Core FlowNode types (matching core/schema/flow.ts)
1302
+ */
1303
+ type CoreFlowNode = {
1304
+ kind: "seq";
1305
+ steps: CoreFlowNode[];
1306
+ } | {
1307
+ kind: "if";
1308
+ cond: CoreExprNode;
1309
+ then: CoreFlowNode;
1310
+ else?: CoreFlowNode;
1311
+ } | {
1312
+ kind: "patch";
1313
+ op: "set" | "unset" | "merge";
1314
+ path: PatchPath;
1315
+ value?: CoreExprNode;
1316
+ } | {
1317
+ kind: "effect";
1318
+ type: string;
1319
+ params: Record<string, CoreExprNode>;
1320
+ } | {
1321
+ kind: "call";
1322
+ flow: string;
1323
+ } | {
1324
+ kind: "halt";
1325
+ reason?: string;
1326
+ } | {
1327
+ kind: "fail";
1328
+ code: string;
1329
+ message?: CoreExprNode;
1330
+ };
1331
+ type CompilerFlowNode = {
1332
+ kind: "seq";
1333
+ steps: CompilerFlowNode[];
1334
+ } | {
1335
+ kind: "if";
1336
+ cond: CompilerExprNode;
1337
+ then: CompilerFlowNode;
1338
+ else?: CompilerFlowNode;
1339
+ } | {
1340
+ kind: "patch";
1341
+ op: "set" | "unset" | "merge";
1342
+ path: PatchPath;
1343
+ value?: CompilerExprNode;
1344
+ } | {
1345
+ kind: "effect";
1346
+ type: string;
1347
+ params: Record<string, CompilerExprNode>;
1348
+ } | {
1349
+ kind: "call";
1350
+ flow: string;
1351
+ } | {
1352
+ kind: "halt";
1353
+ reason?: string;
1354
+ } | {
1355
+ kind: "fail";
1356
+ code: string;
1357
+ message?: CompilerExprNode;
1358
+ };
1359
+ /**
1360
+ * Field type definition
1361
+ */
1362
+ type FieldType = "string" | "number" | "boolean" | "null" | "object" | "array" | {
1363
+ enum: readonly unknown[];
1364
+ };
1365
+ /**
1366
+ * Field specification
1367
+ */
1368
+ interface FieldSpec {
1369
+ type: FieldType;
1370
+ required: boolean;
1371
+ default?: unknown;
1372
+ description?: string;
1373
+ fields?: Record<string, FieldSpec>;
1374
+ items?: FieldSpec;
1375
+ }
1376
+ /**
1377
+ * State specification
1378
+ */
1379
+ interface StateSpec {
1380
+ fields: Record<string, FieldSpec>;
1381
+ }
1382
+ /**
1383
+ * Computed field specification
1384
+ */
1385
+ interface ComputedFieldSpec {
1386
+ deps: string[];
1387
+ expr: CoreExprNode;
1388
+ description?: string;
1389
+ }
1390
+ interface CompilerComputedFieldSpec {
1391
+ deps: string[];
1392
+ expr: CompilerExprNode;
1393
+ description?: string;
1394
+ }
1395
+ /**
1396
+ * Computed specification
1397
+ */
1398
+ interface ComputedSpec {
1399
+ fields: Record<string, ComputedFieldSpec>;
1400
+ }
1401
+ /**
1402
+ * Action specification
1403
+ */
1404
+ interface ActionSpec {
1405
+ flow: CoreFlowNode;
1406
+ input?: FieldSpec;
1407
+ available?: CoreExprNode;
1408
+ description?: string;
1409
+ }
1410
+ interface CompilerActionSpec {
1411
+ flow: CompilerFlowNode;
1412
+ input?: FieldSpec;
1413
+ available?: CompilerExprNode;
1414
+ description?: string;
1415
+ }
1416
+ /**
1417
+ * Domain schema (output IR)
1418
+ */
1419
+ /**
1420
+ * v0.3.3: Type specification (named type declaration)
1421
+ */
1422
+ interface TypeSpec {
1423
+ name: string;
1424
+ definition: TypeDefinition;
1425
+ }
1426
+ /**
1427
+ * v0.3.3: Type definition structure
1428
+ */
1429
+ type TypeDefinition = {
1430
+ kind: "primitive";
1431
+ type: string;
1432
+ } | {
1433
+ kind: "array";
1434
+ element: TypeDefinition;
1435
+ } | {
1436
+ kind: "record";
1437
+ key: TypeDefinition;
1438
+ value: TypeDefinition;
1439
+ } | {
1440
+ kind: "object";
1441
+ fields: Record<string, {
1442
+ type: TypeDefinition;
1443
+ optional: boolean;
1444
+ }>;
1445
+ } | {
1446
+ kind: "union";
1447
+ types: TypeDefinition[];
1448
+ } | {
1449
+ kind: "literal";
1450
+ value: string | number | boolean | null;
1451
+ } | {
1452
+ kind: "ref";
1453
+ name: string;
1454
+ };
1455
+ interface DomainSchema {
1456
+ id: string;
1457
+ version: string;
1458
+ hash: string;
1459
+ /** v0.3.3: Named type declarations */
1460
+ types: Record<string, TypeSpec>;
1461
+ state: StateSpec;
1462
+ computed: ComputedSpec;
1463
+ actions: Record<string, ActionSpec>;
1464
+ meta?: {
1465
+ name?: string;
1466
+ description?: string;
1467
+ authors?: string[];
1468
+ };
1469
+ }
1470
+ interface CanonicalDomainSchema {
1471
+ id: string;
1472
+ version: string;
1473
+ hash: string;
1474
+ types: Record<string, TypeSpec>;
1475
+ state: StateSpec;
1476
+ computed: {
1477
+ fields: Record<string, CompilerComputedFieldSpec>;
1478
+ };
1479
+ actions: Record<string, CompilerActionSpec>;
1480
+ meta?: {
1481
+ name?: string;
1482
+ description?: string;
1483
+ authors?: string[];
1484
+ };
1485
+ }
1486
+ interface GenerateResult {
1487
+ schema: DomainSchema | null;
1488
+ diagnostics: Diagnostic[];
1489
+ }
1490
+ interface GenerateCanonicalResult {
1491
+ schema: CanonicalDomainSchema | null;
1492
+ diagnostics: Diagnostic[];
1493
+ }
1494
+ declare function generateCanonical(program: ProgramNode): GenerateCanonicalResult;
1495
+ /**
1496
+ * Generate runtime-ready DomainSchema from MEL AST.
1497
+ */
1498
+ declare function generate(program: ProgramNode): GenerateResult;
1499
+
1500
+ /**
1501
+ * Expression Normalizer
1502
+ * Converts MEL operators and function calls to Core ExprNode format
1503
+ * Based on MEL SPEC v0.3.1 Section 4 and FDR-MEL-038
1504
+ */
1505
+
1506
+ /**
1507
+ * Normalize a binary operator to Core ExprNode
1508
+ */
1509
+ declare function normalizeExpr(op: BinaryOperator, left: CoreExprNode, right: CoreExprNode): CoreExprNode;
1510
+ /**
1511
+ * Function name to Core ExprNode mapping
1512
+ */
1513
+ declare function normalizeFunctionCall(name: string, args: CoreExprNode[]): CoreExprNode;
1514
+
1515
+ /**
1516
+ * System Value Lowering
1517
+ * Transforms $system.* references into effect-based acquisition
1518
+ * Based on MEL SPEC v0.3.1 Section 5.4
1519
+ */
1520
+
1521
+ /**
1522
+ * Apply system value lowering to a domain schema
1523
+ */
1524
+ declare function lowerSystemValues(schema: DomainSchema): DomainSchema;
1525
+
1526
+ /**
1527
+ * TypeExpr to MEL Renderer
1528
+ *
1529
+ * Converts TypeExpr AST to MEL type syntax.
1530
+ *
1531
+ * @example
1532
+ * // { kind: "primitive", name: "string" } -> "string"
1533
+ * // { kind: "array", element: { kind: "ref", name: "Todo" } } -> "Array<Todo>"
1534
+ * // { kind: "union", members: [...] } -> "string | number | null"
1535
+ */
1536
+ /**
1537
+ * TypeExpr type from translator package
1538
+ */
1539
+ type TypeExpr = {
1540
+ kind: "primitive";
1541
+ name: "string" | "number" | "boolean" | "null";
1542
+ } | {
1543
+ kind: "literal";
1544
+ value: string | number | boolean | null;
1545
+ } | {
1546
+ kind: "ref";
1547
+ name: string;
1548
+ } | {
1549
+ kind: "array";
1550
+ element: TypeExpr;
1551
+ } | {
1552
+ kind: "record";
1553
+ key: TypeExpr;
1554
+ value: TypeExpr;
1555
+ } | {
1556
+ kind: "union";
1557
+ members: TypeExpr[];
1558
+ } | {
1559
+ kind: "object";
1560
+ fields: TypeField[];
1561
+ };
1562
+ type TypeField = {
1563
+ readonly name: string;
1564
+ readonly optional: boolean;
1565
+ readonly type: TypeExpr;
1566
+ };
1567
+ /**
1568
+ * Renders a TypeExpr to MEL type syntax string.
1569
+ *
1570
+ * @param typeExpr - The TypeExpr to render
1571
+ * @returns MEL type syntax string
1572
+ */
1573
+ declare function renderTypeExpr(typeExpr: TypeExpr): string;
1574
+ /**
1575
+ * Renders a TypeField with optional default value.
1576
+ *
1577
+ * @param field - The TypeField to render
1578
+ * @param defaultValue - Optional default value
1579
+ * @returns MEL field declaration string
1580
+ */
1581
+ declare function renderTypeField(field: TypeField, defaultValue?: unknown): string;
1582
+ /**
1583
+ * Renders a JavaScript value to MEL syntax.
1584
+ */
1585
+ declare function renderValue(value: unknown): string;
1586
+
1587
+ /**
1588
+ * ExprNode to MEL Renderer
1589
+ *
1590
+ * Converts ExprNode AST to MEL expression syntax.
1591
+ *
1592
+ * @example
1593
+ * // { kind: "lit", value: 5 } -> "5"
1594
+ * // { kind: "get", path: "count" } -> "count"
1595
+ * // { kind: "add", left: { kind: "get", path: "x" }, right: { kind: "lit", value: 1 } } -> "add(x, 1)"
1596
+ * // { kind: "gt", left: { kind: "get", path: "count" }, right: { kind: "lit", value: 0 } } -> "gt(count, 0)"
1597
+ */
1598
+ /**
1599
+ * ExprNode type (subset from core package)
1600
+ */
1601
+ type ExprNode = {
1602
+ kind: "lit";
1603
+ value: unknown;
1604
+ } | {
1605
+ kind: "get";
1606
+ path: string;
1607
+ } | {
1608
+ kind: "eq";
1609
+ left: ExprNode;
1610
+ right: ExprNode;
1611
+ } | {
1612
+ kind: "neq";
1613
+ left: ExprNode;
1614
+ right: ExprNode;
1615
+ } | {
1616
+ kind: "gt";
1617
+ left: ExprNode;
1618
+ right: ExprNode;
1619
+ } | {
1620
+ kind: "gte";
1621
+ left: ExprNode;
1622
+ right: ExprNode;
1623
+ } | {
1624
+ kind: "lt";
1625
+ left: ExprNode;
1626
+ right: ExprNode;
1627
+ } | {
1628
+ kind: "lte";
1629
+ left: ExprNode;
1630
+ right: ExprNode;
1631
+ } | {
1632
+ kind: "and";
1633
+ args: ExprNode[];
1634
+ } | {
1635
+ kind: "or";
1636
+ args: ExprNode[];
1637
+ } | {
1638
+ kind: "not";
1639
+ arg: ExprNode;
1640
+ } | {
1641
+ kind: "if";
1642
+ cond: ExprNode;
1643
+ then: ExprNode;
1644
+ else: ExprNode;
1645
+ } | {
1646
+ kind: "add";
1647
+ left: ExprNode;
1648
+ right: ExprNode;
1649
+ } | {
1650
+ kind: "sub";
1651
+ left: ExprNode;
1652
+ right: ExprNode;
1653
+ } | {
1654
+ kind: "mul";
1655
+ left: ExprNode;
1656
+ right: ExprNode;
1657
+ } | {
1658
+ kind: "div";
1659
+ left: ExprNode;
1660
+ right: ExprNode;
1661
+ } | {
1662
+ kind: "mod";
1663
+ left: ExprNode;
1664
+ right: ExprNode;
1665
+ } | {
1666
+ kind: "concat";
1667
+ args: ExprNode[];
1668
+ } | {
1669
+ kind: "substring";
1670
+ str: ExprNode;
1671
+ start: ExprNode;
1672
+ end?: ExprNode;
1673
+ } | {
1674
+ kind: "trim";
1675
+ str: ExprNode;
1676
+ } | {
1677
+ kind: "len";
1678
+ arg: ExprNode;
1679
+ } | {
1680
+ kind: "at";
1681
+ array: ExprNode;
1682
+ index: ExprNode;
1683
+ } | {
1684
+ kind: "first";
1685
+ array: ExprNode;
1686
+ } | {
1687
+ kind: "last";
1688
+ array: ExprNode;
1689
+ } | {
1690
+ kind: "slice";
1691
+ array: ExprNode;
1692
+ start: ExprNode;
1693
+ end?: ExprNode;
1694
+ } | {
1695
+ kind: "includes";
1696
+ array: ExprNode;
1697
+ item: ExprNode;
1698
+ } | {
1699
+ kind: "filter";
1700
+ array: ExprNode;
1701
+ predicate: ExprNode;
1702
+ } | {
1703
+ kind: "map";
1704
+ array: ExprNode;
1705
+ mapper: ExprNode;
1706
+ } | {
1707
+ kind: "find";
1708
+ array: ExprNode;
1709
+ predicate: ExprNode;
1710
+ } | {
1711
+ kind: "every";
1712
+ array: ExprNode;
1713
+ predicate: ExprNode;
1714
+ } | {
1715
+ kind: "some";
1716
+ array: ExprNode;
1717
+ predicate: ExprNode;
1718
+ } | {
1719
+ kind: "append";
1720
+ array: ExprNode;
1721
+ items: ExprNode[];
1722
+ } | {
1723
+ kind: "object";
1724
+ fields: Record<string, ExprNode>;
1725
+ } | {
1726
+ kind: "field";
1727
+ object: ExprNode;
1728
+ property: string;
1729
+ } | {
1730
+ kind: "keys";
1731
+ obj: ExprNode;
1732
+ } | {
1733
+ kind: "values";
1734
+ obj: ExprNode;
1735
+ } | {
1736
+ kind: "entries";
1737
+ obj: ExprNode;
1738
+ } | {
1739
+ kind: "merge";
1740
+ objects: ExprNode[];
1741
+ } | {
1742
+ kind: "typeof";
1743
+ arg: ExprNode;
1744
+ } | {
1745
+ kind: "isNull";
1746
+ arg: ExprNode;
1747
+ } | {
1748
+ kind: "coalesce";
1749
+ args: ExprNode[];
1750
+ };
1751
+ /**
1752
+ * Renders an ExprNode to MEL expression syntax string.
1753
+ *
1754
+ * @param expr - The ExprNode to render
1755
+ * @returns MEL expression syntax string
1756
+ */
1757
+ declare function renderExprNode(expr: ExprNode): string;
1758
+
1759
+ /**
1760
+ * PatchOp to MEL Renderer
1761
+ *
1762
+ * Converts PatchOp AST to MEL syntax snippets.
1763
+ *
1764
+ * Note: These are fragments, not complete domain definitions.
1765
+ * The caller is responsible for assembling fragments into a valid MEL domain.
1766
+ */
1767
+
1768
+ type AddTypeOp = {
1769
+ kind: "addType";
1770
+ typeName: string;
1771
+ typeExpr: TypeExpr;
1772
+ };
1773
+ type AddFieldOp = {
1774
+ kind: "addField";
1775
+ typeName: string;
1776
+ field: TypeField & {
1777
+ defaultValue?: unknown;
1778
+ };
1779
+ };
1780
+ type SetFieldTypeOp = {
1781
+ kind: "setFieldType";
1782
+ path: string;
1783
+ typeExpr: TypeExpr;
1784
+ };
1785
+ type SetDefaultValueOp = {
1786
+ kind: "setDefaultValue";
1787
+ path: string;
1788
+ value: unknown;
1789
+ };
1790
+ type AddConstraintOp = {
1791
+ kind: "addConstraint";
1792
+ targetPath: string;
1793
+ rule: ExprNode;
1794
+ message?: string;
1795
+ };
1796
+ type AddComputedOp = {
1797
+ kind: "addComputed";
1798
+ name: string;
1799
+ expr: ExprNode;
1800
+ deps?: string[];
1801
+ };
1802
+ type AddActionAvailableOp = {
1803
+ kind: "addActionAvailable";
1804
+ actionName: string;
1805
+ expr: ExprNode;
1806
+ };
1807
+ type PatchOp = AddTypeOp | AddFieldOp | SetFieldTypeOp | SetDefaultValueOp | AddConstraintOp | AddComputedOp | AddActionAvailableOp;
1808
+ interface RenderOptions {
1809
+ /**
1810
+ * Indentation string (default: " ")
1811
+ */
1812
+ indent?: string;
1813
+ /**
1814
+ * Include comments with metadata
1815
+ */
1816
+ includeComments?: boolean;
1817
+ /**
1818
+ * Comment prefix for metadata
1819
+ */
1820
+ commentPrefix?: string;
1821
+ }
1822
+ /**
1823
+ * Renders a PatchOp to MEL syntax string.
1824
+ *
1825
+ * @param op - The PatchOp to render
1826
+ * @param options - Rendering options
1827
+ * @returns MEL syntax string
1828
+ */
1829
+ declare function renderPatchOp(op: PatchOp, options?: RenderOptions): string;
1830
+ /**
1831
+ * Gets the type name from a semantic path.
1832
+ *
1833
+ * @example
1834
+ * // "Todo.title" -> "Todo"
1835
+ * // "User.address.city" -> "User"
1836
+ * // "count" -> undefined
1837
+ */
1838
+ declare function extractTypeName(path: string): string | undefined;
1839
+
1840
+ /**
1841
+ * PatchFragment to MEL Renderer
1842
+ *
1843
+ * Converts PatchFragment to MEL syntax with metadata comments.
1844
+ */
1845
+
1846
+ interface PatchFragment {
1847
+ /**
1848
+ * Unique fragment identifier (content-addressed)
1849
+ */
1850
+ fragmentId: string;
1851
+ /**
1852
+ * Source intent identifier
1853
+ */
1854
+ sourceIntentId: string;
1855
+ /**
1856
+ * Fragment operation
1857
+ */
1858
+ op: PatchOp;
1859
+ /**
1860
+ * Confidence score (0-1)
1861
+ */
1862
+ confidence: number;
1863
+ /**
1864
+ * Evidence strings
1865
+ */
1866
+ evidence: string[];
1867
+ /**
1868
+ * Creation timestamp (ISO 8601)
1869
+ */
1870
+ createdAt: string;
1871
+ }
1872
+ interface FragmentRenderOptions extends RenderOptions {
1873
+ /**
1874
+ * Include fragment metadata as comments
1875
+ */
1876
+ includeMetadata?: boolean;
1877
+ /**
1878
+ * Include evidence as comments
1879
+ */
1880
+ includeEvidence?: boolean;
1881
+ /**
1882
+ * Include confidence score
1883
+ */
1884
+ includeConfidence?: boolean;
1885
+ /**
1886
+ * Include fragment ID
1887
+ */
1888
+ includeFragmentId?: boolean;
1889
+ }
1890
+ /**
1891
+ * Renders a PatchFragment to MEL syntax string with optional metadata.
1892
+ *
1893
+ * @param fragment - The PatchFragment to render
1894
+ * @param options - Rendering options
1895
+ * @returns MEL syntax string with metadata comments
1896
+ */
1897
+ declare function renderFragment(fragment: PatchFragment, options?: FragmentRenderOptions): string;
1898
+ /**
1899
+ * Renders multiple PatchFragments to MEL syntax string.
1900
+ *
1901
+ * @param fragments - The PatchFragments to render
1902
+ * @param options - Rendering options
1903
+ * @returns MEL syntax string with all fragments
1904
+ */
1905
+ declare function renderFragments(fragments: PatchFragment[], options?: FragmentRenderOptions): string;
1906
+ /**
1907
+ * Renders PatchFragments grouped by operation kind.
1908
+ *
1909
+ * @param fragments - The PatchFragments to render
1910
+ * @param options - Rendering options
1911
+ * @returns Object with rendered strings grouped by operation kind
1912
+ */
1913
+ declare function renderFragmentsByKind(fragments: PatchFragment[], options?: FragmentRenderOptions): Record<string, string>;
1914
+ /**
1915
+ * Renders PatchFragments as a complete MEL domain block.
1916
+ *
1917
+ * @param domainName - The domain name
1918
+ * @param fragments - The PatchFragments to render
1919
+ * @param options - Rendering options
1920
+ * @returns Complete MEL domain string
1921
+ */
1922
+ declare function renderAsDomain(domainName: string, fragments: PatchFragment[], options?: FragmentRenderOptions): string;
1923
+
1924
+ /**
1925
+ * Lowering Error Types
1926
+ *
1927
+ * Defines error types for MEL IR → Core IR lowering.
1928
+ *
1929
+ * @see SPEC v0.4.0 §17.6
1930
+ */
1931
+ /**
1932
+ * Lowering error codes.
1933
+ *
1934
+ * @see SPEC v0.4.0 §17.6
1935
+ */
1936
+ type LoweringErrorCode =
1937
+ /** var in non-effect context, sys in schema */
1938
+ "INVALID_KIND_FOR_CONTEXT"
1939
+ /** Unknown function name in call node */
1940
+ | "UNKNOWN_CALL_FN"
1941
+ /** sys.system in Translator path */
1942
+ | "INVALID_SYS_PATH"
1943
+ /** get.base is not var(item) */
1944
+ | "UNSUPPORTED_BASE"
1945
+ /** Malformed node structure */
1946
+ | "INVALID_SHAPE"
1947
+ /** Unknown node kind */
1948
+ | "UNKNOWN_NODE_KIND";
1949
+ /**
1950
+ * Lowering error class.
1951
+ *
1952
+ * Thrown when MEL IR cannot be lowered to Core IR.
1953
+ *
1954
+ * @see SPEC v0.4.0 §17.6
1955
+ */
1956
+ declare class LoweringError extends Error {
1957
+ readonly code: LoweringErrorCode;
1958
+ readonly path?: string[];
1959
+ readonly details?: Record<string, unknown>;
1960
+ constructor(code: LoweringErrorCode, message: string, options?: {
1961
+ path?: string[];
1962
+ details?: Record<string, unknown>;
1963
+ });
1964
+ }
1965
+ /**
1966
+ * Create a lowering error for invalid kind in context.
1967
+ *
1968
+ * @example
1969
+ * throw invalidKindForContext("var", "schema");
1970
+ */
1971
+ declare function invalidKindForContext(kind: string, context: string, path?: string[]): LoweringError;
1972
+ /**
1973
+ * Create a lowering error for unknown call function.
1974
+ *
1975
+ * @example
1976
+ * throw unknownCallFn("unknownFunc");
1977
+ */
1978
+ declare function unknownCallFn(fn: string, path?: string[]): LoweringError;
1979
+ /**
1980
+ * Create a lowering error for invalid sys path.
1981
+ *
1982
+ * @example
1983
+ * throw invalidSysPath(["system", "uuid"]);
1984
+ */
1985
+ declare function invalidSysPath(sysPath: string[], path?: string[]): LoweringError;
1986
+ /**
1987
+ * Create a lowering error for unsupported base expression.
1988
+ *
1989
+ * @example
1990
+ * throw unsupportedBase("call");
1991
+ */
1992
+ declare function unsupportedBase(baseKind: string, path?: string[]): LoweringError;
1993
+ /**
1994
+ * Create a lowering error for invalid shape.
1995
+ *
1996
+ * @example
1997
+ * throw invalidShape("missing 'value' field");
1998
+ */
1999
+ declare function invalidShape(description: string, path?: string[]): LoweringError;
2000
+ /**
2001
+ * Create a lowering error for unknown node kind.
2002
+ *
2003
+ * @example
2004
+ * throw unknownNodeKind("foo");
2005
+ */
2006
+ declare function unknownNodeKind(kind: string, path?: string[]): LoweringError;
2007
+
2008
+ /**
2009
+ * Patch Lowering
2010
+ *
2011
+ * Transforms PatchFragment[] (MEL IR) to ConditionalPatchOp[] (Core IR).
2012
+ *
2013
+ * @see SPEC v0.4.0 §17.4, §17.5
2014
+ */
2015
+
2016
+ /**
2017
+ * MEL TypeExpr (Translator output).
2018
+ */
2019
+ type MelTypeExpr = {
2020
+ kind: "primitive";
2021
+ name: "string" | "number" | "boolean" | "null";
2022
+ } | {
2023
+ kind: "array";
2024
+ element: MelTypeExpr;
2025
+ } | {
2026
+ kind: "object";
2027
+ fields: MelTypeField[];
2028
+ } | {
2029
+ kind: "union";
2030
+ members: MelTypeExpr[];
2031
+ } | {
2032
+ kind: "literal";
2033
+ value: string | number | boolean | null;
2034
+ } | {
2035
+ kind: "ref";
2036
+ name: string;
2037
+ };
2038
+ /**
2039
+ * MEL TypeField.
2040
+ */
2041
+ type MelTypeField = {
2042
+ name: string;
2043
+ type: MelTypeExpr;
2044
+ optional?: boolean;
2045
+ };
2046
+ /**
2047
+ * MEL PatchOp (Translator output - schema operations).
2048
+ *
2049
+ * @see SPEC v0.4.0 §17.4
2050
+ */
2051
+ type MelPatchOp = {
2052
+ kind: "addType";
2053
+ typeName: string;
2054
+ typeExpr: MelTypeExpr;
2055
+ } | {
2056
+ kind: "addField";
2057
+ typeName: string;
2058
+ field: MelTypeField & {
2059
+ defaultValue?: unknown;
2060
+ };
2061
+ } | {
2062
+ kind: "setFieldType";
2063
+ path: string;
2064
+ typeExpr: MelTypeExpr;
2065
+ } | {
2066
+ kind: "setDefaultValue";
2067
+ path: string;
2068
+ value: unknown;
2069
+ } | {
2070
+ kind: "addConstraint";
2071
+ targetPath: string;
2072
+ rule: MelExprNode;
2073
+ message?: string;
2074
+ } | {
2075
+ kind: "addComputed";
2076
+ name: string;
2077
+ expr: MelExprNode;
2078
+ deps?: string[];
2079
+ } | {
2080
+ kind: "addActionAvailable";
2081
+ actionName: string;
2082
+ expr: MelExprNode;
2083
+ };
2084
+ /**
2085
+ * MEL PatchFragment (Translator output).
2086
+ *
2087
+ * Contains MEL IR expressions that need lowering.
2088
+ *
2089
+ * @see SPEC v0.4.0 §17.4
2090
+ */
2091
+ interface MelPatchFragment {
2092
+ /**
2093
+ * Unique fragment identifier (content-addressed).
2094
+ */
2095
+ fragmentId: string;
2096
+ /**
2097
+ * Source intent identifier.
2098
+ */
2099
+ sourceIntentId: string;
2100
+ /**
2101
+ * Fragment operation with MEL IR expressions.
2102
+ */
2103
+ op: MelPatchOp;
2104
+ /**
2105
+ * Optional condition (MEL IR).
2106
+ * Preserved in output as Core IR.
2107
+ */
2108
+ condition?: MelExprNode;
2109
+ /**
2110
+ * Confidence score (0-1).
2111
+ */
2112
+ confidence: number;
2113
+ /**
2114
+ * Evidence strings.
2115
+ */
2116
+ evidence: string[];
2117
+ /**
2118
+ * Creation timestamp (ISO 8601).
2119
+ */
2120
+ createdAt: string;
2121
+ }
2122
+ /**
2123
+ * Lowered TypeExpr (Core format).
2124
+ */
2125
+ type LoweredTypeExpr = {
2126
+ kind: "primitive";
2127
+ name: "string" | "number" | "boolean" | "null";
2128
+ } | {
2129
+ kind: "array";
2130
+ element: LoweredTypeExpr;
2131
+ } | {
2132
+ kind: "object";
2133
+ fields: LoweredTypeField[];
2134
+ } | {
2135
+ kind: "union";
2136
+ members: LoweredTypeExpr[];
2137
+ } | {
2138
+ kind: "literal";
2139
+ value: string | number | boolean | null;
2140
+ } | {
2141
+ kind: "ref";
2142
+ name: string;
2143
+ };
2144
+ /**
2145
+ * Lowered TypeField.
2146
+ */
2147
+ type LoweredTypeField = {
2148
+ name: string;
2149
+ type: LoweredTypeExpr;
2150
+ optional?: boolean;
2151
+ };
2152
+ /**
2153
+ * Lowered PatchOp (Core IR expressions).
2154
+ *
2155
+ * Same structure as MelPatchOp but with Core IR expressions.
2156
+ */
2157
+ type LoweredPatchOp = {
2158
+ kind: "addType";
2159
+ typeName: string;
2160
+ typeExpr: LoweredTypeExpr;
2161
+ } | {
2162
+ kind: "addField";
2163
+ typeName: string;
2164
+ field: LoweredTypeField & {
2165
+ defaultValue?: unknown;
2166
+ };
2167
+ } | {
2168
+ kind: "setFieldType";
2169
+ path: string;
2170
+ typeExpr: LoweredTypeExpr;
2171
+ } | {
2172
+ kind: "setDefaultValue";
2173
+ path: string;
2174
+ value: unknown;
2175
+ } | {
2176
+ kind: "addConstraint";
2177
+ targetPath: string;
2178
+ rule: ExprNode$2;
2179
+ message?: string;
2180
+ } | {
2181
+ kind: "addComputed";
2182
+ name: string;
2183
+ expr: ExprNode$2;
2184
+ deps?: string[];
2185
+ } | {
2186
+ kind: "addActionAvailable";
2187
+ actionName: string;
2188
+ expr: ExprNode$2;
2189
+ };
2190
+ /**
2191
+ * Schema conditional patch operation (intermediate IR for Translator → Host).
2192
+ *
2193
+ * Used for schema evolution operations (addType, addField, addComputed, etc.).
2194
+ * Preserves fragment condition for later evaluation.
2195
+ *
2196
+ * @see SPEC v0.4.0 §17.5
2197
+ */
2198
+ interface SchemaConditionalPatchOp {
2199
+ /**
2200
+ * Fragment identifier (for tracing).
2201
+ */
2202
+ fragmentId: string;
2203
+ /**
2204
+ * Condition expression (Core IR).
2205
+ * If present, op is only applied when condition evaluates to true.
2206
+ *
2207
+ * @see FDR-MEL-073
2208
+ */
2209
+ condition?: ExprNode$2;
2210
+ /**
2211
+ * Lowered patch operation.
2212
+ */
2213
+ op: LoweredPatchOp;
2214
+ /**
2215
+ * Confidence (preserved from fragment).
2216
+ */
2217
+ confidence: number;
2218
+ }
2219
+ /**
2220
+ * @deprecated Use SchemaConditionalPatchOp instead.
2221
+ */
2222
+ type ConditionalPatchOp = SchemaConditionalPatchOp;
2223
+ /**
2224
+ * Lower PatchFragment[] to SchemaConditionalPatchOp[].
2225
+ *
2226
+ * Transforms MEL IR expressions to Core IR expressions.
2227
+ * Preserves fragment conditions for evaluation phase.
2228
+ *
2229
+ * @param fragments - MEL IR patch fragments from Translator
2230
+ * @param ctx - Patch lowering context
2231
+ * @returns Core IR schema conditional patch operations
2232
+ *
2233
+ * @see SPEC v0.4.0 §17.5
2234
+ */
2235
+ declare function lowerPatchFragments(fragments: MelPatchFragment[], ctx: PatchLoweringContext): SchemaConditionalPatchOp[];
2236
+
2237
+ /**
2238
+ * Runtime Patch Lowering
2239
+ *
2240
+ * Transforms MEL runtime patches (set/unset/merge) to Core IR.
2241
+ *
2242
+ * @see SPEC v0.4.0 §17.5
2243
+ */
2244
+
2245
+ /**
2246
+ * MEL runtime patch operation type.
2247
+ *
2248
+ * @see SPEC v0.4.0 §17.5
2249
+ */
2250
+ type MelRuntimePatchOp = "set" | "unset" | "merge";
2251
+ /**
2252
+ * MEL path segment for runtime patches before expression lowering.
2253
+ */
2254
+ type MelIRPathSegment = {
2255
+ kind: "prop";
2256
+ name: string;
2257
+ } | {
2258
+ kind: "expr";
2259
+ expr: MelExprNode;
2260
+ };
2261
+ /**
2262
+ * MEL runtime patch path represented as IR segments.
2263
+ */
2264
+ type MelIRPatchPath = MelIRPathSegment[];
2265
+ /**
2266
+ * Lowered runtime IR path segment.
2267
+ */
2268
+ type IRPathSegment = {
2269
+ kind: "prop";
2270
+ name: string;
2271
+ } | {
2272
+ kind: "expr";
2273
+ expr: ExprNode$2;
2274
+ };
2275
+ /**
2276
+ * Runtime patch path represented as IR segments.
2277
+ */
2278
+ type IRPatchPath = IRPathSegment[];
2279
+ /**
2280
+ * MEL runtime patch (Translator output for action patches).
2281
+ *
2282
+ * Contains MEL IR expressions that need lowering to Core IR.
2283
+ */
2284
+ interface MelRuntimePatch {
2285
+ /**
2286
+ * Optional condition (MEL IR).
2287
+ * If present, patch is only applied when condition evaluates to true.
2288
+ */
2289
+ condition?: MelExprNode;
2290
+ /**
2291
+ * Patch operation type.
2292
+ */
2293
+ op: MelRuntimePatchOp;
2294
+ /**
2295
+ * Target path in snapshot.
2296
+ * Uses IR segments and is resolved to concrete PatchPath at evaluation time.
2297
+ */
2298
+ path: MelIRPatchPath;
2299
+ /**
2300
+ * Value expression (MEL IR) for set/merge operations.
2301
+ * Required for "set" and "merge", forbidden for "unset".
2302
+ */
2303
+ value?: MelExprNode;
2304
+ }
2305
+ /**
2306
+ * Runtime ConditionalPatchOp for snapshot state mutations.
2307
+ *
2308
+ * This is the intermediate representation between Translator output
2309
+ * and final concrete Patch[]. Host must call evaluateRuntimePatches()
2310
+ * to get concrete values.
2311
+ *
2312
+ * @see SPEC v0.4.0 §17.5, §20
2313
+ */
2314
+ interface RuntimeConditionalPatchOp {
2315
+ /**
2316
+ * Optional condition expression (Core IR).
2317
+ * If present, patch is only applied when condition evaluates to true.
2318
+ *
2319
+ * @see SPEC v0.4.0 §18.6 (boolean-only conditions)
2320
+ */
2321
+ condition?: ExprNode$2;
2322
+ /**
2323
+ * Patch operation type.
2324
+ */
2325
+ op: "set" | "unset" | "merge";
2326
+ /**
2327
+ * Target path in IR form.
2328
+ * Evaluator resolves this to concrete PatchPath.
2329
+ */
2330
+ path: IRPatchPath;
2331
+ /**
2332
+ * Value expression (Core IR) for set/merge operations.
2333
+ * Required for "set" and "merge", undefined for "unset".
2334
+ */
2335
+ value?: ExprNode$2;
2336
+ }
2337
+ /**
2338
+ * Lower MEL runtime patches to Core IR.
2339
+ *
2340
+ * Transforms MEL IR expressions to Core IR expressions.
2341
+ * The returned patches still contain expressions that need to be
2342
+ * evaluated by evaluateRuntimePatches() to get concrete values.
2343
+ *
2344
+ * @param patches - MEL IR runtime patches from Translator
2345
+ * @param ctx - Expression lowering context
2346
+ * @returns Core IR runtime conditional patches
2347
+ *
2348
+ * @see SPEC v0.4.0 §17.5
2349
+ */
2350
+ declare function lowerRuntimePatches(patches: MelRuntimePatch[], ctx: ExprLoweringContext): RuntimeConditionalPatchOp[];
2351
+ /**
2352
+ * Lower a single MEL runtime patch to Core IR.
2353
+ */
2354
+ declare function lowerRuntimePatch(patch: MelRuntimePatch, ctx: ExprLoweringContext): RuntimeConditionalPatchOp;
2355
+
2356
+ /**
2357
+ * Evaluation Context Types
2358
+ *
2359
+ * Defines context for expression evaluation.
2360
+ *
2361
+ * @see SPEC v0.4.0 §18.3
2362
+ */
2363
+ /**
2364
+ * Minimal snapshot shape for evaluation.
2365
+ *
2366
+ * @see SPEC v0.4.0 §18.7
2367
+ */
2368
+ interface EvaluationSnapshot {
2369
+ /**
2370
+ * Domain data (matches StateSpec).
2371
+ * Path resolution default target.
2372
+ */
2373
+ data: unknown;
2374
+ /**
2375
+ * Computed values (matches ComputedSpec).
2376
+ * Accessed via bare key paths (e.g., "total", not "computed.total").
2377
+ */
2378
+ computed: Record<string, unknown>;
2379
+ }
2380
+ /**
2381
+ * Intent metadata for evaluation.
2382
+ *
2383
+ * @see SPEC v0.4.0 §18.3
2384
+ */
2385
+ interface EvaluationMeta {
2386
+ /**
2387
+ * Intent identifier.
2388
+ */
2389
+ intentId: string;
2390
+ /**
2391
+ * Actor reference (optional).
2392
+ */
2393
+ actor?: {
2394
+ type: string;
2395
+ id: string;
2396
+ };
2397
+ /**
2398
+ * Timestamp (optional).
2399
+ */
2400
+ timestamp?: number;
2401
+ }
2402
+ /**
2403
+ * Evaluation context.
2404
+ *
2405
+ * @see SPEC v0.4.0 §18.3
2406
+ */
2407
+ interface EvaluationContext {
2408
+ /**
2409
+ * Current snapshot for state lookups.
2410
+ * Paths resolve to snapshot.data.* by default.
2411
+ */
2412
+ snapshot: EvaluationSnapshot;
2413
+ /**
2414
+ * Intent metadata.
2415
+ * Paths starting with "meta.*" resolve here.
2416
+ */
2417
+ meta: EvaluationMeta;
2418
+ /**
2419
+ * Intent input.
2420
+ * Paths starting with "input.*" resolve here.
2421
+ */
2422
+ input: Record<string, unknown>;
2423
+ /**
2424
+ * Current $item value (for effect.args evaluation).
2425
+ * Paths starting with "$item.*" resolve here.
2426
+ */
2427
+ item?: unknown;
2428
+ }
2429
+ /**
2430
+ * Create a minimal evaluation context.
2431
+ *
2432
+ * @param options - Context options
2433
+ * @returns Evaluation context
2434
+ */
2435
+ declare function createEvaluationContext(options: Partial<EvaluationContext> & {
2436
+ meta: EvaluationMeta;
2437
+ }): EvaluationContext;
2438
+ /**
2439
+ * Create a working snapshot by cloning and applying a patch.
2440
+ *
2441
+ * Used for sequential evaluation semantics.
2442
+ *
2443
+ * @see FDR-MEL-070
2444
+ */
2445
+ declare function applyPatchToWorkingSnapshot(snapshot: EvaluationSnapshot, path: string, value: unknown): EvaluationSnapshot;
2446
+
2447
+ /**
2448
+ * Expression Evaluation
2449
+ *
2450
+ * Evaluates Core IR expressions against evaluation context.
2451
+ *
2452
+ * AXIOM A35: Expression evaluation is total; invalid operations return null, never throw.
2453
+ *
2454
+ * @see SPEC v0.4.0 §18
2455
+ */
2456
+
2457
+ /**
2458
+ * Evaluate a Core IR expression.
2459
+ *
2460
+ * Total function: returns null on any error, never throws.
2461
+ *
2462
+ * @param expr - Core IR expression
2463
+ * @param ctx - Evaluation context
2464
+ * @returns Evaluated value or null on error
2465
+ *
2466
+ * @see SPEC v0.4.0 §18.4, A35
2467
+ */
2468
+ declare function evaluateExpr(expr: ExprNode$2, ctx: EvaluationContext): unknown;
2469
+
2470
+ /**
2471
+ * Patch Evaluation
2472
+ *
2473
+ * Evaluates ConditionalPatchOp[] to produce concrete schema operations.
2474
+ *
2475
+ * @see SPEC v0.4.0 §18.5, §18.6
2476
+ */
2477
+
2478
+ /**
2479
+ * Evaluated schema patch operation.
2480
+ *
2481
+ * All conditions have been evaluated and values resolved where appropriate.
2482
+ * Expressions in addComputed, addConstraint, addActionAvailable are preserved
2483
+ * for runtime evaluation by Core.
2484
+ */
2485
+ type EvaluatedPatchOp = LoweredPatchOp;
2486
+ /**
2487
+ * Result of evaluating a conditional patch.
2488
+ */
2489
+ interface EvaluatedPatch {
2490
+ /**
2491
+ * Fragment identifier (for tracing).
2492
+ */
2493
+ fragmentId: string;
2494
+ /**
2495
+ * The evaluated operation.
2496
+ */
2497
+ op: EvaluatedPatchOp;
2498
+ /**
2499
+ * Confidence (preserved from fragment).
2500
+ */
2501
+ confidence: number;
2502
+ /**
2503
+ * Whether condition was evaluated (true) or there was no condition.
2504
+ */
2505
+ conditionEvaluated: boolean;
2506
+ }
2507
+ /**
2508
+ * Result of patch evaluation.
2509
+ */
2510
+ interface PatchEvaluationResult {
2511
+ /**
2512
+ * Patches that passed their conditions.
2513
+ */
2514
+ patches: EvaluatedPatch[];
2515
+ /**
2516
+ * Patches that were skipped due to false/null conditions.
2517
+ */
2518
+ skipped: Array<{
2519
+ fragmentId: string;
2520
+ reason: "false" | "null" | "non-boolean";
2521
+ }>;
2522
+ /**
2523
+ * Final working snapshot after all evaluations.
2524
+ */
2525
+ finalSnapshot: EvaluationSnapshot;
2526
+ }
2527
+ /**
2528
+ * Evaluate conditional patch operations.
2529
+ *
2530
+ * Implements sequential evaluation semantics: later patches see effects
2531
+ * of earlier patches via working snapshot.
2532
+ *
2533
+ * Conditions are boolean-only: true applies, false/null/non-boolean skips.
2534
+ *
2535
+ * @param ops - Conditional patch operations from lowering phase
2536
+ * @param ctx - Initial evaluation context
2537
+ * @returns Evaluation result with applied and skipped patches
2538
+ *
2539
+ * @see SPEC v0.4.0 §18.5, FDR-MEL-070, FDR-MEL-073
2540
+ */
2541
+ declare function evaluateConditionalPatchOps(ops: ConditionalPatchOp[], ctx: EvaluationContext): PatchEvaluationResult;
2542
+ /**
2543
+ * Simple evaluation: returns patches that pass conditions.
2544
+ *
2545
+ * Does not track skipped patches or maintain sequential semantics.
2546
+ * Use this for stateless condition evaluation.
2547
+ *
2548
+ * @param ops - Conditional patch operations
2549
+ * @param ctx - Evaluation context
2550
+ * @returns Patches that passed their conditions
2551
+ */
2552
+ declare function evaluatePatches(ops: ConditionalPatchOp[], ctx: EvaluationContext): EvaluatedPatch[];
2553
+ /**
2554
+ * Evaluate expressions in a patch operation to concrete values.
2555
+ *
2556
+ * Use this when you need fully concrete values (no expressions).
2557
+ *
2558
+ * Note: addComputed.expr, addConstraint.rule, and addActionAvailable.expr
2559
+ * are meant to remain as expressions for runtime evaluation by Core.
2560
+ *
2561
+ * @param op - Lowered patch operation
2562
+ * @param ctx - Evaluation context
2563
+ * @returns Patch operation with evaluated expressions
2564
+ */
2565
+ declare function evaluatePatchExpressions(op: LoweredPatchOp, ctx: EvaluationContext): LoweredPatchOp;
2566
+ /**
2567
+ * Check if a condition evaluates to true.
2568
+ *
2569
+ * Boolean-only: only true returns true.
2570
+ * false, null, and non-boolean values return false.
2571
+ *
2572
+ * @param condition - Condition expression (or undefined for always-true)
2573
+ * @param ctx - Evaluation context
2574
+ * @returns True if condition passes
2575
+ *
2576
+ * @see FDR-MEL-073
2577
+ */
2578
+ declare function evaluateCondition(condition: ExprNode$2 | undefined, ctx: EvaluationContext): boolean;
2579
+ /**
2580
+ * Classify a condition evaluation result.
2581
+ *
2582
+ * @param condition - Condition expression
2583
+ * @param ctx - Evaluation context
2584
+ * @returns Classification of condition result
2585
+ */
2586
+ declare function classifyCondition(condition: ExprNode$2 | undefined, ctx: EvaluationContext): {
2587
+ passes: boolean;
2588
+ reason: "no-condition" | "true" | "false" | "null" | "non-boolean";
2589
+ };
2590
+
2591
+ /**
2592
+ * Runtime Patch Evaluation
2593
+ *
2594
+ * Evaluates RuntimeConditionalPatchOp[] to produce concrete Patch[].
2595
+ */
2596
+
2597
+ /**
2598
+ * Skip reason for runtime patches.
2599
+ */
2600
+ type RuntimePatchSkipReason = "false" | "null" | "non-boolean" | "invalid-path";
2601
+ /**
2602
+ * Skipped patch info.
2603
+ */
2604
+ interface SkippedRuntimePatch {
2605
+ /**
2606
+ * Index in the original ops array.
2607
+ */
2608
+ index: number;
2609
+ /**
2610
+ * Target path (display form).
2611
+ */
2612
+ path: string;
2613
+ /**
2614
+ * Reason why patch was skipped.
2615
+ */
2616
+ reason: RuntimePatchSkipReason;
2617
+ }
2618
+ /**
2619
+ * Result of runtime patch evaluation with trace information.
2620
+ */
2621
+ interface RuntimePatchEvaluationResult {
2622
+ /**
2623
+ * Concrete patches that passed conditions.
2624
+ * Order is preserved from input.
2625
+ */
2626
+ patches: Patch[];
2627
+ /**
2628
+ * Patches that were skipped due to false/null/non-boolean conditions.
2629
+ */
2630
+ skipped: SkippedRuntimePatch[];
2631
+ /**
2632
+ * Non-fatal warnings collected during evaluation.
2633
+ */
2634
+ warnings: string[];
2635
+ /**
2636
+ * Final working snapshot after all evaluations.
2637
+ */
2638
+ finalSnapshot: EvaluationSnapshot;
2639
+ }
2640
+ /**
2641
+ * Evaluate runtime conditional patches to concrete Patch[].
2642
+ */
2643
+ declare function evaluateRuntimePatches(ops: RuntimeConditionalPatchOp[], ctx: EvaluationContext): Patch[];
2644
+ /**
2645
+ * Evaluate runtime patches with trace information.
2646
+ */
2647
+ declare function evaluateRuntimePatchesWithTrace(ops: RuntimeConditionalPatchOp[], ctx: EvaluationContext): RuntimePatchEvaluationResult;
2648
+
2649
+ /**
2650
+ * MEL Text Ingest API
2651
+ *
2652
+ * Compiles MEL text to DomainSchema or RuntimeConditionalPatchOp[].
2653
+ *
2654
+ * @see SPEC v0.4.0 §19
2655
+ */
2656
+
2657
+ /**
2658
+ * Trace entry for compilation steps.
2659
+ */
2660
+ interface CompileTrace {
2661
+ phase: "lex" | "parse" | "analyze" | "generate" | "lower";
2662
+ durationMs: number;
2663
+ details?: Record<string, unknown>;
2664
+ }
2665
+ /**
2666
+ * Domain compilation options.
2667
+ */
2668
+ interface CompileMelDomainOptions {
2669
+ mode: "domain";
2670
+ fnTableVersion?: string;
2671
+ }
2672
+ /**
2673
+ * Domain compilation result.
2674
+ *
2675
+ * @see SPEC v0.4.0 §19.1
2676
+ */
2677
+ interface CompileMelDomainResult {
2678
+ /**
2679
+ * Compiled schema, or null if errors occurred.
2680
+ */
2681
+ schema: DomainSchema | null;
2682
+ /**
2683
+ * Compilation trace.
2684
+ */
2685
+ trace: CompileTrace[];
2686
+ /**
2687
+ * Warning diagnostics.
2688
+ */
2689
+ warnings: Diagnostic[];
2690
+ /**
2691
+ * Error diagnostics.
2692
+ */
2693
+ errors: Diagnostic[];
2694
+ }
2695
+ /**
2696
+ * Patch compilation options.
2697
+ */
2698
+ interface CompileMelPatchOptions {
2699
+ mode: "patch";
2700
+ /**
2701
+ * Action name for context.
2702
+ */
2703
+ actionName: string;
2704
+ /**
2705
+ * Allowed system path prefixes.
2706
+ * Default: ["meta", "input"] (system is forbidden per §20.3).
2707
+ */
2708
+ allowSysPaths?: {
2709
+ prefixes: ("meta" | "input")[];
2710
+ };
2711
+ /**
2712
+ * Function table version.
2713
+ */
2714
+ fnTableVersion?: string;
2715
+ }
2716
+ /**
2717
+ * Patch compilation result.
2718
+ *
2719
+ * @see SPEC v0.4.0 §19.2
2720
+ */
2721
+ interface CompileMelPatchResult {
2722
+ /**
2723
+ * Compiled patch operations.
2724
+ * These still contain Core IR expressions that need evaluation.
2725
+ */
2726
+ ops: RuntimeConditionalPatchOp[];
2727
+ /**
2728
+ * Compilation trace.
2729
+ */
2730
+ trace: CompileTrace[];
2731
+ /**
2732
+ * Warning diagnostics.
2733
+ */
2734
+ warnings: Diagnostic[];
2735
+ /**
2736
+ * Error diagnostics.
2737
+ */
2738
+ errors: Diagnostic[];
2739
+ }
2740
+ /**
2741
+ * Compile MEL text to DomainSchema.
2742
+ *
2743
+ * Takes a complete MEL domain definition and produces a DomainSchema
2744
+ * suitable for use with core.compute().
2745
+ *
2746
+ * @param melText - MEL domain source text
2747
+ * @param options - Compilation options
2748
+ * @returns Compilation result with schema or errors
2749
+ *
2750
+ * @see SPEC v0.4.0 §19.1
2751
+ */
2752
+ declare function compileMelDomain(melText: string, options?: CompileMelDomainOptions): CompileMelDomainResult;
2753
+ /**
2754
+ * Compile MEL patch text to RuntimeConditionalPatchOp[].
2755
+ *
2756
+ * Takes MEL patch statements (set, unset, merge) and produces
2757
+ * RuntimeConditionalPatchOp[] with Core IR expressions.
2758
+ *
2759
+ * The returned ops still contain expressions that need to be evaluated
2760
+ * by evaluateRuntimePatches() to get concrete values.
2761
+ *
2762
+ * Constraints:
2763
+ * - §20.3: $system.* is forbidden in Translator path
2764
+ *
2765
+ * @param melText - MEL patch source text
2766
+ * @param options - Compilation options
2767
+ * @returns Compilation result with ops or errors
2768
+ *
2769
+ * @see SPEC v0.4.0 §19.2
2770
+ */
2771
+ declare function compileMelPatch(melText: string, options: CompileMelPatchOptions): CompileMelPatchResult;
2772
+
1
2773
  /**
2
2774
  * @manifesto-ai/compiler
3
2775
  *
4
2776
  * MEL (Manifesto Expression Language) compiler.
5
2777
  * Provides lexer, parser, analyzer, lowering, evaluation, and rendering.
6
2778
  */
7
- export * from "./lexer/index.js";
8
- export * from "./parser/index.js";
9
- export * from "./analyzer/index.js";
10
- export * from "./diagnostics/index.js";
11
- export * from "./generator/index.js";
12
- export { renderTypeExpr, renderTypeField, renderValue, renderExprNode, renderPatchOp, extractTypeName, renderFragment, renderFragments, renderFragmentsByKind, renderAsDomain, type TypeExpr, type TypeField, type ExprNode as RendererExprNode, type PatchOp, type AddTypeOp, type AddFieldOp, type SetFieldTypeOp, type SetDefaultValueOp, type AddConstraintOp, type AddComputedOp, type AddActionAvailableOp, type RenderOptions, type PatchFragment, type FragmentRenderOptions, } from "./renderer/index.js";
13
- export * from "./lowering/index.js";
14
- export * from "./evaluation/index.js";
15
- export * from "./api/index.js";
16
- export type { DomainSchema as DomainModule } from "./generator/ir.js";
17
- //# sourceMappingURL=index.d.ts.map
2779
+
2780
+ interface CompileOptions {
2781
+ /** Whether to lower system values during compilation */
2782
+ lowerSystemValues?: boolean;
2783
+ /** Skip scope/semantic validation */
2784
+ skipSemanticAnalysis?: boolean;
2785
+ /** Backward-compatible passthrough for legacy callers */
2786
+ mode?: "domain";
2787
+ }
2788
+ interface CompileResult {
2789
+ schema: DomainSchema | null;
2790
+ trace: CompileTrace[];
2791
+ warnings: Diagnostic[];
2792
+ errors: Diagnostic[];
2793
+ success: boolean;
2794
+ }
2795
+ /**
2796
+ * Backward-compatible compile API.
2797
+ *
2798
+ * Current public API is `compileMelDomain`, but several test/code paths and CLI
2799
+ * still call this legacy helper.
2800
+ *
2801
+ * This wrapper keeps the legacy contract:
2802
+ * - returns `{ success }`
2803
+ * - supports optional `lowerSystemValues` and `skipSemanticAnalysis`
2804
+ * - includes parse/analyze/generate diagnostics in one result
2805
+ */
2806
+ declare function compile(source: string, options?: CompileOptions): CompileResult;
2807
+ /**
2808
+ * Backward-compatible token+parse helper.
2809
+ */
2810
+ declare function parseSource(source: string): ParseResult;
2811
+ /**
2812
+ * Backward-compatible check helper.
2813
+ */
2814
+ declare function check(source: string): Diagnostic[];
2815
+
2816
+ export { type ASTNode, type ActionNode, type ActionSpec, type AddActionAvailableOp, type AddComputedOp, type AddConstraintOp, type AddFieldOp, type AddTypeOp, type AllowedSysPrefix, type ArrayLiteralExprNode, type ArrayTypeNode, type BinaryExprNode, type BinaryOperator, type CanonicalDomainSchema, type CompileMelDomainOptions, type CompileMelDomainResult, type CompileMelPatchOptions, type CompileMelPatchResult, type CompileOptions, type CompileResult, type CompileTrace, type CompilerActionSpec, type CompilerComputedFieldSpec, type CompilerExprNode, type CompilerFlowNode, type ComputedFieldSpec, type ComputedNode, type ComputedSpec, type ConditionalPatchOp, type CoreExprNode, type CoreFlowNode, DEFAULT_ACTION_CONTEXT, DEFAULT_PATCH_CONTEXT, DEFAULT_SCHEMA_CONTEXT, DIAGNOSTIC_CODES, type Diagnostic, type DiagnosticCode, type DiagnosticSeverity, type DomainMember, type DomainSchema as DomainModule, type DomainNode, type DomainSchema, EFFECT_ARGS_CONTEXT, type EffectArgNode, type EffectStmtNode, type EvaluatedPatch, type EvaluatedPatchOp, type EvaluationContext, type EvaluationMeta, type EvaluationSnapshot, type ExprLoweringContext, type ExprNode$1 as ExprNode, type FailStmtNode, type FieldSpec, type FieldType, type FlowDeclNode, type FlowStmtNode, type FragmentRenderOptions, type FunctionCallExprNode, type GenerateCanonicalResult, type GenerateResult, type GuardedStmtNode, type IRPatchPath, type IRPathSegment, type IdentifierExprNode, type ImportNode, type IncludeStmtNode, type IndexAccessExprNode, type IndexSegmentNode, type InnerStmtNode, type IterationVarExprNode, KEYWORDS, type LexResult, Lexer, type LiteralExprNode, type LiteralTypeNode, type LoweredPatchOp, type LoweredTypeExpr, type LoweredTypeField, LoweringError, type LoweringErrorCode, type MelExprNode, type MelIRPatchPath, type MelIRPathSegment, type MelObjField, type MelPatchFragment, type MelPatchOp, type MelPathNode, type MelPathSegment, type MelPrimitive, type MelRuntimePatch, type MelRuntimePatchOp, type MelSystemPath, type MelTypeExpr, type MelTypeField, type ObjectLiteralExprNode, type ObjectPropertyNode, type ObjectTypeNode, type OnceIntentStmtNode, type OnceStmtNode, type ParamNode, type ParseResult, Parser, type PatchEvaluationResult, type PatchFragment, type PatchLoweringContext, type PatchOp, type PatchStmtNode, type PathNode, type PathSegmentNode, type Position, Precedence, type ProgramNode, type PropertyAccessExprNode, type PropertySegmentNode, RESERVED_KEYWORDS, type RecordTypeNode, type RelatedDiagnostic, type RenderOptions, type ExprNode as RendererExprNode, type RuntimeConditionalPatchOp, type RuntimePatchEvaluationResult, type RuntimePatchSkipReason, type SchemaConditionalPatchOp, Scope, type ScopeAnalysisResult, ScopeAnalyzer, SemanticValidator, type SetDefaultValueOp, type SetFieldTypeOp, type SimpleTypeNode, type SkippedRuntimePatch, type SourceLocation, type StateFieldNode, type StateNode, type StateSpec, type StopStmtNode, type Symbol, type SymbolKind, type SystemIdentExprNode, type TernaryExprNode, type Token, type TokenKind, type TypeDeclNode, type TypeDefinition, type TypeExpr, type TypeExprNode, type TypeField, type TypeFieldNode, type TypeSpec, type UnaryExprNode, type UnionTypeNode, type ValidationResult, type WhenStmtNode, analyzeScope, applyPatchToWorkingSnapshot, check, classifyCondition, compile, compileMelDomain, compileMelPatch, createError, createEvaluationContext, createInfo, createLocation, createPointLocation, createPosition, createToken, createWarning, evaluateCondition, evaluateConditionalPatchOps, evaluateExpr, evaluatePatchExpressions, evaluatePatches, evaluateRuntimePatches, evaluateRuntimePatchesWithTrace, extractTypeName, filterBySeverity, formatDiagnostic, formatDiagnosticCode, formatDiagnostics, generate, generateCanonical, getBinaryPrecedence, getDiagnosticInfo, getKeywordKind, hasErrors, invalidKindForContext, invalidShape, invalidSysPath, isBinaryOp, isError, isExprNode, isKeyword, isReserved, isRightAssociative, isStmtNode, isUnaryOp, lowerExprNode, lowerPatchFragments, lowerRuntimePatch, lowerRuntimePatches, lowerSystemValues, mergeLocations, normalizeExpr, normalizeFunctionCall, parse, parseSource, renderAsDomain, renderExprNode, renderFragment, renderFragments, renderFragmentsByKind, renderPatchOp, renderTypeExpr, renderTypeField, renderValue, tokenToBinaryOp, tokenize, unknownCallFn, unknownNodeKind, unsupportedBase, validateSemantics };