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