@manifesto-ai/compiler 1.8.3 → 1.9.1
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.
- package/dist/analyzer/entity-primitives.d.ts +3 -0
- package/dist/analyzer/expr-type-surface.d.ts +21 -0
- package/dist/analyzer/flow-composition.d.ts +7 -0
- package/dist/analyzer/index.d.ts +5 -0
- package/dist/analyzer/scope.d.ts +76 -0
- package/dist/analyzer/validator.d.ts +69 -0
- package/dist/api/compile-mel-patch-collector.d.ts +33 -0
- package/dist/api/compile-mel-patch-expr.d.ts +8 -0
- package/dist/api/compile-mel-patch-location.d.ts +9 -0
- package/dist/api/compile-mel-patch.d.ts +5 -0
- package/dist/api/compile-mel.d.ts +125 -0
- package/dist/api/index.d.ts +9 -0
- package/dist/{chunk-4JJQCFJH.js → chunk-7TT6Y5ZC.js} +6 -2
- package/dist/chunk-7TT6Y5ZC.js.map +1 -0
- package/dist/{chunk-AYZTDA3J.js → chunk-LI5HNMZV.js} +2 -2
- package/dist/{chunk-K4IKHGOP.js → chunk-WZRGVNJK.js} +3 -3
- package/dist/diagnostics/codes.d.ts +24 -0
- package/dist/diagnostics/format.d.ts +25 -0
- package/dist/diagnostics/index.d.ts +6 -0
- package/dist/diagnostics/types.d.ts +66 -0
- package/dist/esbuild.d.ts +6 -8
- package/dist/esbuild.js +3 -3
- package/dist/evaluation/context.d.ts +90 -0
- package/dist/evaluation/evaluate-expr.d.ts +23 -0
- package/dist/evaluation/evaluate-patch.d.ts +122 -0
- package/dist/evaluation/evaluate-runtime-patch.d.ts +59 -0
- package/dist/evaluation/index.d.ts +14 -0
- package/dist/generator/index.d.ts +6 -0
- package/dist/generator/ir.d.ts +185 -0
- package/dist/generator/lowering.d.ts +10 -0
- package/dist/generator/normalizer.d.ts +15 -0
- package/dist/generator/runtime-lowering.d.ts +2 -0
- package/dist/index.d.ts +19 -2785
- package/dist/index.js +1 -1
- package/dist/lexer/index.d.ts +6 -0
- package/dist/lexer/lexer.d.ts +58 -0
- package/dist/lexer/source-location.d.ts +40 -0
- package/dist/lexer/tokens.d.ts +46 -0
- package/dist/lowering/context.d.ts +95 -0
- package/dist/lowering/errors.d.ts +83 -0
- package/dist/lowering/index.d.ts +19 -0
- package/dist/lowering/lower-expr.d.ts +79 -0
- package/dist/lowering/lower-patch.d.ts +230 -0
- package/dist/lowering/lower-runtime-patch.d.ts +126 -0
- package/dist/lowering/to-mel-expr.d.ts +12 -0
- package/dist/mel-module.d.ts +14 -0
- package/dist/node-loader.d.ts +3 -7
- package/dist/node-loader.js +2 -2
- package/dist/parser/ast.d.ts +367 -0
- package/dist/parser/index.d.ts +6 -0
- package/dist/parser/parser.d.ts +101 -0
- package/dist/parser/precedence.d.ts +43 -0
- package/dist/renderer/expr-node.d.ts +171 -0
- package/dist/renderer/fragment.d.ts +83 -0
- package/dist/renderer/index.d.ts +22 -0
- package/dist/renderer/patch-op.d.ts +81 -0
- package/dist/renderer/type-expr.d.ts +60 -0
- package/dist/rollup.d.ts +6 -8
- package/dist/rollup.js +3 -3
- package/dist/rspack.d.ts +6 -7
- package/dist/rspack.js +3 -3
- package/dist/unplugin.d.ts +14 -0
- package/dist/utils/unicode-order.d.ts +5 -0
- package/dist/vite.d.ts +6 -8
- package/dist/vite.js +3 -3
- package/dist/webpack.d.ts +6 -8
- package/dist/webpack.js +3 -3
- package/package.json +16 -14
- package/dist/chunk-4JJQCFJH.js.map +0 -1
- package/dist/unplugin-6wnvFiEo.d.ts +0 -17
- /package/dist/{chunk-AYZTDA3J.js.map → chunk-LI5HNMZV.js.map} +0 -0
- /package/dist/{chunk-K4IKHGOP.js.map → chunk-WZRGVNJK.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
compileMelDomain
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7TT6Y5ZC.js";
|
|
4
4
|
|
|
5
5
|
// src/mel-module.ts
|
|
6
6
|
function formatDiagnostic(diagnostic) {
|
|
@@ -30,4 +30,4 @@ export {
|
|
|
30
30
|
formatDiagnostic,
|
|
31
31
|
compileMelToModuleCode
|
|
32
32
|
};
|
|
33
|
-
//# sourceMappingURL=chunk-
|
|
33
|
+
//# sourceMappingURL=chunk-LI5HNMZV.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
formatDiagnostic
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LI5HNMZV.js";
|
|
4
4
|
import {
|
|
5
5
|
compileMelDomain
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-7TT6Y5ZC.js";
|
|
7
7
|
|
|
8
8
|
// src/unplugin.ts
|
|
9
9
|
import { createUnplugin } from "unplugin";
|
|
@@ -71,4 +71,4 @@ ${details}`);
|
|
|
71
71
|
export {
|
|
72
72
|
unpluginMel
|
|
73
73
|
};
|
|
74
|
-
//# sourceMappingURL=chunk-
|
|
74
|
+
//# sourceMappingURL=chunk-WZRGVNJK.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MEL Compiler Diagnostic Codes
|
|
3
|
+
* Based on MEL SPEC v0.3.3 Appendix A
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Diagnostic code information
|
|
7
|
+
*/
|
|
8
|
+
export interface DiagnosticCode {
|
|
9
|
+
code: string;
|
|
10
|
+
message: string;
|
|
11
|
+
category: "syntax" | "semantic" | "type" | "system";
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* All diagnostic codes
|
|
15
|
+
*/
|
|
16
|
+
export declare const DIAGNOSTIC_CODES: Record<string, DiagnosticCode>;
|
|
17
|
+
/**
|
|
18
|
+
* Get diagnostic code information
|
|
19
|
+
*/
|
|
20
|
+
export declare function getDiagnosticInfo(code: string): DiagnosticCode | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Format a diagnostic code for display
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatDiagnosticCode(code: string): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain-text Diagnostic Formatter
|
|
3
|
+
*
|
|
4
|
+
* Browser-safe (no ANSI colors). Produces human-readable error messages
|
|
5
|
+
* with optional source context and caret indicators.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { Diagnostic } from "./types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Format a single diagnostic as plain text.
|
|
12
|
+
*
|
|
13
|
+
* Without source: `[MEL_PARSER] Expected '{' (3:15)`
|
|
14
|
+
* With source:
|
|
15
|
+
* ```
|
|
16
|
+
* [MEL_PARSER] Expected '{' (3:15)
|
|
17
|
+
* 3 | domain Bad bad syntax here }
|
|
18
|
+
* ^^^
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function formatDiagnostic(diagnostic: Diagnostic, source?: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Format multiple diagnostics, separated by blank lines.
|
|
24
|
+
*/
|
|
25
|
+
export declare function formatDiagnostics(diagnostics: Diagnostic[], source?: string): string;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostic Types for MEL Compiler
|
|
3
|
+
* Error and warning reporting structures
|
|
4
|
+
*/
|
|
5
|
+
import type { SourceLocation } from "../lexer/source-location.js";
|
|
6
|
+
/**
|
|
7
|
+
* Severity level of a diagnostic
|
|
8
|
+
*/
|
|
9
|
+
export type DiagnosticSeverity = "error" | "warning" | "info";
|
|
10
|
+
/**
|
|
11
|
+
* A diagnostic message (error, warning, or info)
|
|
12
|
+
*/
|
|
13
|
+
export interface Diagnostic {
|
|
14
|
+
/** Severity level */
|
|
15
|
+
severity: DiagnosticSeverity;
|
|
16
|
+
/** Error code (e.g., "MEL001", "MEL_LEXER") */
|
|
17
|
+
code: string;
|
|
18
|
+
/** Human-readable message */
|
|
19
|
+
message: string;
|
|
20
|
+
/** Location in source */
|
|
21
|
+
location: SourceLocation;
|
|
22
|
+
/** The source line containing the error */
|
|
23
|
+
source?: string;
|
|
24
|
+
/** Suggested fix */
|
|
25
|
+
suggestion?: string;
|
|
26
|
+
/** Related diagnostics */
|
|
27
|
+
related?: RelatedDiagnostic[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A related diagnostic (for multi-location errors)
|
|
31
|
+
*/
|
|
32
|
+
export interface RelatedDiagnostic {
|
|
33
|
+
message: string;
|
|
34
|
+
location: SourceLocation;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create an error diagnostic
|
|
38
|
+
*/
|
|
39
|
+
export declare function createError(code: string, message: string, location: SourceLocation, options?: {
|
|
40
|
+
source?: string;
|
|
41
|
+
suggestion?: string;
|
|
42
|
+
related?: RelatedDiagnostic[];
|
|
43
|
+
}): Diagnostic;
|
|
44
|
+
/**
|
|
45
|
+
* Create a warning diagnostic
|
|
46
|
+
*/
|
|
47
|
+
export declare function createWarning(code: string, message: string, location: SourceLocation, options?: {
|
|
48
|
+
source?: string;
|
|
49
|
+
suggestion?: string;
|
|
50
|
+
}): Diagnostic;
|
|
51
|
+
/**
|
|
52
|
+
* Create an info diagnostic
|
|
53
|
+
*/
|
|
54
|
+
export declare function createInfo(code: string, message: string, location: SourceLocation): Diagnostic;
|
|
55
|
+
/**
|
|
56
|
+
* Check if a diagnostic is an error
|
|
57
|
+
*/
|
|
58
|
+
export declare function isError(diagnostic: Diagnostic): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Check if any diagnostics contain errors
|
|
61
|
+
*/
|
|
62
|
+
export declare function hasErrors(diagnostics: Diagnostic[]): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Filter diagnostics by severity
|
|
65
|
+
*/
|
|
66
|
+
export declare function filterBySeverity(diagnostics: Diagnostic[], severity: DiagnosticSeverity): Diagnostic[];
|
package/dist/esbuild.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export { MelPluginOptions, melPlugin as default, melPlugin };
|
|
1
|
+
/**
|
|
2
|
+
* esbuild plugin for MEL files.
|
|
3
|
+
*/
|
|
4
|
+
export type { MelPluginOptions, MelCodegenOptions } from "./unplugin.js";
|
|
5
|
+
export declare const melPlugin: (options: import("./unplugin.js").MelPluginOptions) => import("unplugin").EsbuildPlugin;
|
|
6
|
+
export default melPlugin;
|
package/dist/esbuild.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
unpluginMel
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-WZRGVNJK.js";
|
|
4
|
+
import "./chunk-LI5HNMZV.js";
|
|
5
|
+
import "./chunk-7TT6Y5ZC.js";
|
|
6
6
|
|
|
7
7
|
// src/esbuild.ts
|
|
8
8
|
var melPlugin = unpluginMel.esbuild;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evaluation Context Types
|
|
3
|
+
*
|
|
4
|
+
* Defines context for expression evaluation.
|
|
5
|
+
*
|
|
6
|
+
* @see SPEC v0.4.0 §18.3
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Minimal snapshot shape for evaluation.
|
|
10
|
+
*
|
|
11
|
+
* @see SPEC v0.4.0 §18.7
|
|
12
|
+
*/
|
|
13
|
+
export interface EvaluationSnapshot {
|
|
14
|
+
/**
|
|
15
|
+
* Domain data (matches StateSpec).
|
|
16
|
+
* Path resolution default target.
|
|
17
|
+
*/
|
|
18
|
+
data: unknown;
|
|
19
|
+
/**
|
|
20
|
+
* Computed values (matches ComputedSpec).
|
|
21
|
+
* Accessed via bare key paths (e.g., "total", not "computed.total").
|
|
22
|
+
*/
|
|
23
|
+
computed: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Intent metadata for evaluation.
|
|
27
|
+
*
|
|
28
|
+
* @see SPEC v0.4.0 §18.3
|
|
29
|
+
*/
|
|
30
|
+
export interface EvaluationMeta {
|
|
31
|
+
/**
|
|
32
|
+
* Intent identifier.
|
|
33
|
+
*/
|
|
34
|
+
intentId: string;
|
|
35
|
+
/**
|
|
36
|
+
* Actor reference (optional).
|
|
37
|
+
*/
|
|
38
|
+
actor?: {
|
|
39
|
+
type: string;
|
|
40
|
+
id: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Timestamp (optional).
|
|
44
|
+
*/
|
|
45
|
+
timestamp?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Evaluation context.
|
|
49
|
+
*
|
|
50
|
+
* @see SPEC v0.4.0 §18.3
|
|
51
|
+
*/
|
|
52
|
+
export interface EvaluationContext {
|
|
53
|
+
/**
|
|
54
|
+
* Current snapshot for state lookups.
|
|
55
|
+
* Paths resolve to snapshot.data.* by default.
|
|
56
|
+
*/
|
|
57
|
+
snapshot: EvaluationSnapshot;
|
|
58
|
+
/**
|
|
59
|
+
* Intent metadata.
|
|
60
|
+
* Paths starting with "meta.*" resolve here.
|
|
61
|
+
*/
|
|
62
|
+
meta: EvaluationMeta;
|
|
63
|
+
/**
|
|
64
|
+
* Intent input.
|
|
65
|
+
* Paths starting with "input.*" resolve here.
|
|
66
|
+
*/
|
|
67
|
+
input: Record<string, unknown>;
|
|
68
|
+
/**
|
|
69
|
+
* Current $item value (for effect.args evaluation).
|
|
70
|
+
* Paths starting with "$item.*" resolve here.
|
|
71
|
+
*/
|
|
72
|
+
item?: unknown;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Create a minimal evaluation context.
|
|
76
|
+
*
|
|
77
|
+
* @param options - Context options
|
|
78
|
+
* @returns Evaluation context
|
|
79
|
+
*/
|
|
80
|
+
export declare function createEvaluationContext(options: Partial<EvaluationContext> & {
|
|
81
|
+
meta: EvaluationMeta;
|
|
82
|
+
}): EvaluationContext;
|
|
83
|
+
/**
|
|
84
|
+
* Create a working snapshot by cloning and applying a patch.
|
|
85
|
+
*
|
|
86
|
+
* Used for sequential evaluation semantics.
|
|
87
|
+
*
|
|
88
|
+
* @see FDR-MEL-070
|
|
89
|
+
*/
|
|
90
|
+
export declare function applyPatchToWorkingSnapshot(snapshot: EvaluationSnapshot, path: string, value: unknown): EvaluationSnapshot;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expression Evaluation
|
|
3
|
+
*
|
|
4
|
+
* Evaluates Core IR expressions against evaluation context.
|
|
5
|
+
*
|
|
6
|
+
* AXIOM A35: Expression evaluation is total; invalid operations return null, never throw.
|
|
7
|
+
*
|
|
8
|
+
* @see SPEC v0.4.0 §18
|
|
9
|
+
*/
|
|
10
|
+
import type { ExprNode } from "@manifesto-ai/core";
|
|
11
|
+
import type { EvaluationContext } from "./context.js";
|
|
12
|
+
/**
|
|
13
|
+
* Evaluate a Core IR expression.
|
|
14
|
+
*
|
|
15
|
+
* Total function: returns null on any error, never throws.
|
|
16
|
+
*
|
|
17
|
+
* @param expr - Core IR expression
|
|
18
|
+
* @param ctx - Evaluation context
|
|
19
|
+
* @returns Evaluated value or null on error
|
|
20
|
+
*
|
|
21
|
+
* @see SPEC v0.4.0 §18.4, A35
|
|
22
|
+
*/
|
|
23
|
+
export declare function evaluateExpr(expr: ExprNode, ctx: EvaluationContext): unknown;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Patch Evaluation
|
|
3
|
+
*
|
|
4
|
+
* Evaluates ConditionalPatchOp[] to produce concrete schema operations.
|
|
5
|
+
*
|
|
6
|
+
* @see SPEC v0.4.0 §18.5, §18.6
|
|
7
|
+
*/
|
|
8
|
+
import type { ExprNode as CoreExprNode } from "@manifesto-ai/core";
|
|
9
|
+
import type { ConditionalPatchOp, LoweredPatchOp } from "../lowering/lower-patch.js";
|
|
10
|
+
import type { EvaluationContext, EvaluationSnapshot } from "./context.js";
|
|
11
|
+
/**
|
|
12
|
+
* Evaluated schema patch operation.
|
|
13
|
+
*
|
|
14
|
+
* All conditions have been evaluated and values resolved where appropriate.
|
|
15
|
+
* Expressions in addComputed, addConstraint, addActionAvailable are preserved
|
|
16
|
+
* for runtime evaluation by Core.
|
|
17
|
+
*/
|
|
18
|
+
export type EvaluatedPatchOp = LoweredPatchOp;
|
|
19
|
+
/**
|
|
20
|
+
* Result of evaluating a conditional patch.
|
|
21
|
+
*/
|
|
22
|
+
export interface EvaluatedPatch {
|
|
23
|
+
/**
|
|
24
|
+
* Fragment identifier (for tracing).
|
|
25
|
+
*/
|
|
26
|
+
fragmentId: string;
|
|
27
|
+
/**
|
|
28
|
+
* The evaluated operation.
|
|
29
|
+
*/
|
|
30
|
+
op: EvaluatedPatchOp;
|
|
31
|
+
/**
|
|
32
|
+
* Confidence (preserved from fragment).
|
|
33
|
+
*/
|
|
34
|
+
confidence: number;
|
|
35
|
+
/**
|
|
36
|
+
* Whether condition was evaluated (true) or there was no condition.
|
|
37
|
+
*/
|
|
38
|
+
conditionEvaluated: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Result of patch evaluation.
|
|
42
|
+
*/
|
|
43
|
+
export interface PatchEvaluationResult {
|
|
44
|
+
/**
|
|
45
|
+
* Patches that passed their conditions.
|
|
46
|
+
*/
|
|
47
|
+
patches: EvaluatedPatch[];
|
|
48
|
+
/**
|
|
49
|
+
* Patches that were skipped due to false/null conditions.
|
|
50
|
+
*/
|
|
51
|
+
skipped: Array<{
|
|
52
|
+
fragmentId: string;
|
|
53
|
+
reason: "false" | "null" | "non-boolean";
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Final working snapshot after all evaluations.
|
|
57
|
+
*/
|
|
58
|
+
finalSnapshot: EvaluationSnapshot;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Evaluate conditional patch operations.
|
|
62
|
+
*
|
|
63
|
+
* Implements sequential evaluation semantics: later patches see effects
|
|
64
|
+
* of earlier patches via working snapshot.
|
|
65
|
+
*
|
|
66
|
+
* Conditions are boolean-only: true applies, false/null/non-boolean skips.
|
|
67
|
+
*
|
|
68
|
+
* @param ops - Conditional patch operations from lowering phase
|
|
69
|
+
* @param ctx - Initial evaluation context
|
|
70
|
+
* @returns Evaluation result with applied and skipped patches
|
|
71
|
+
*
|
|
72
|
+
* @see SPEC v0.4.0 §18.5, FDR-MEL-070, FDR-MEL-073
|
|
73
|
+
*/
|
|
74
|
+
export declare function evaluateConditionalPatchOps(ops: ConditionalPatchOp[], ctx: EvaluationContext): PatchEvaluationResult;
|
|
75
|
+
/**
|
|
76
|
+
* Simple evaluation: returns patches that pass conditions.
|
|
77
|
+
*
|
|
78
|
+
* Does not track skipped patches or maintain sequential semantics.
|
|
79
|
+
* Use this for stateless condition evaluation.
|
|
80
|
+
*
|
|
81
|
+
* @param ops - Conditional patch operations
|
|
82
|
+
* @param ctx - Evaluation context
|
|
83
|
+
* @returns Patches that passed their conditions
|
|
84
|
+
*/
|
|
85
|
+
export declare function evaluatePatches(ops: ConditionalPatchOp[], ctx: EvaluationContext): EvaluatedPatch[];
|
|
86
|
+
/**
|
|
87
|
+
* Evaluate expressions in a patch operation to concrete values.
|
|
88
|
+
*
|
|
89
|
+
* Use this when you need fully concrete values (no expressions).
|
|
90
|
+
*
|
|
91
|
+
* Note: addComputed.expr, addConstraint.rule, and addActionAvailable.expr
|
|
92
|
+
* are meant to remain as expressions for runtime evaluation by Core.
|
|
93
|
+
*
|
|
94
|
+
* @param op - Lowered patch operation
|
|
95
|
+
* @param ctx - Evaluation context
|
|
96
|
+
* @returns Patch operation with evaluated expressions
|
|
97
|
+
*/
|
|
98
|
+
export declare function evaluatePatchExpressions(op: LoweredPatchOp, ctx: EvaluationContext): LoweredPatchOp;
|
|
99
|
+
/**
|
|
100
|
+
* Check if a condition evaluates to true.
|
|
101
|
+
*
|
|
102
|
+
* Boolean-only: only true returns true.
|
|
103
|
+
* false, null, and non-boolean values return false.
|
|
104
|
+
*
|
|
105
|
+
* @param condition - Condition expression (or undefined for always-true)
|
|
106
|
+
* @param ctx - Evaluation context
|
|
107
|
+
* @returns True if condition passes
|
|
108
|
+
*
|
|
109
|
+
* @see FDR-MEL-073
|
|
110
|
+
*/
|
|
111
|
+
export declare function evaluateCondition(condition: CoreExprNode | undefined, ctx: EvaluationContext): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Classify a condition evaluation result.
|
|
114
|
+
*
|
|
115
|
+
* @param condition - Condition expression
|
|
116
|
+
* @param ctx - Evaluation context
|
|
117
|
+
* @returns Classification of condition result
|
|
118
|
+
*/
|
|
119
|
+
export declare function classifyCondition(condition: CoreExprNode | undefined, ctx: EvaluationContext): {
|
|
120
|
+
passes: boolean;
|
|
121
|
+
reason: "no-condition" | "true" | "false" | "null" | "non-boolean";
|
|
122
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Patch Evaluation
|
|
3
|
+
*
|
|
4
|
+
* Evaluates RuntimeConditionalPatchOp[] to produce concrete Patch[].
|
|
5
|
+
*/
|
|
6
|
+
import type { Patch } from "@manifesto-ai/core";
|
|
7
|
+
import type { RuntimeConditionalPatchOp } from "../lowering/lower-runtime-patch.js";
|
|
8
|
+
import type { EvaluationContext, EvaluationSnapshot } from "./context.js";
|
|
9
|
+
/**
|
|
10
|
+
* Skip reason for runtime patches.
|
|
11
|
+
*/
|
|
12
|
+
export type RuntimePatchSkipReason = "false" | "null" | "non-boolean" | "invalid-path";
|
|
13
|
+
/**
|
|
14
|
+
* Skipped patch info.
|
|
15
|
+
*/
|
|
16
|
+
export interface SkippedRuntimePatch {
|
|
17
|
+
/**
|
|
18
|
+
* Index in the original ops array.
|
|
19
|
+
*/
|
|
20
|
+
index: number;
|
|
21
|
+
/**
|
|
22
|
+
* Target path (display form).
|
|
23
|
+
*/
|
|
24
|
+
path: string;
|
|
25
|
+
/**
|
|
26
|
+
* Reason why patch was skipped.
|
|
27
|
+
*/
|
|
28
|
+
reason: RuntimePatchSkipReason;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Result of runtime patch evaluation with trace information.
|
|
32
|
+
*/
|
|
33
|
+
export interface RuntimePatchEvaluationResult {
|
|
34
|
+
/**
|
|
35
|
+
* Concrete patches that passed conditions.
|
|
36
|
+
* Order is preserved from input.
|
|
37
|
+
*/
|
|
38
|
+
patches: Patch[];
|
|
39
|
+
/**
|
|
40
|
+
* Patches that were skipped due to false/null/non-boolean conditions.
|
|
41
|
+
*/
|
|
42
|
+
skipped: SkippedRuntimePatch[];
|
|
43
|
+
/**
|
|
44
|
+
* Non-fatal warnings collected during evaluation.
|
|
45
|
+
*/
|
|
46
|
+
warnings: string[];
|
|
47
|
+
/**
|
|
48
|
+
* Final working snapshot after all evaluations.
|
|
49
|
+
*/
|
|
50
|
+
finalSnapshot: EvaluationSnapshot;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Evaluate runtime conditional patches to concrete Patch[].
|
|
54
|
+
*/
|
|
55
|
+
export declare function evaluateRuntimePatches(ops: RuntimeConditionalPatchOp[], ctx: EvaluationContext): Patch[];
|
|
56
|
+
/**
|
|
57
|
+
* Evaluate runtime patches with trace information.
|
|
58
|
+
*/
|
|
59
|
+
export declare function evaluateRuntimePatchesWithTrace(ops: RuntimeConditionalPatchOp[], ctx: EvaluationContext): RuntimePatchEvaluationResult;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evaluation Module
|
|
3
|
+
*
|
|
4
|
+
* Evaluates Core IR expressions and conditional patches.
|
|
5
|
+
*
|
|
6
|
+
* @see SPEC v0.4.0 §18
|
|
7
|
+
*/
|
|
8
|
+
export type { EvaluationSnapshot, EvaluationMeta, EvaluationContext, } from "./context.js";
|
|
9
|
+
export { createEvaluationContext, applyPatchToWorkingSnapshot, } from "./context.js";
|
|
10
|
+
export { evaluateExpr } from "./evaluate-expr.js";
|
|
11
|
+
export type { EvaluatedPatchOp, EvaluatedPatch, PatchEvaluationResult, } from "./evaluate-patch.js";
|
|
12
|
+
export { evaluateConditionalPatchOps, evaluatePatches, evaluatePatchExpressions, evaluateCondition, classifyCondition, } from "./evaluate-patch.js";
|
|
13
|
+
export type { RuntimePatchSkipReason, SkippedRuntimePatch, RuntimePatchEvaluationResult, } from "./evaluate-runtime-patch.js";
|
|
14
|
+
export { evaluateRuntimePatches, evaluateRuntimePatchesWithTrace, } from "./evaluate-runtime-patch.js";
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IR Generator - Transforms MEL AST to Core DomainSchema
|
|
3
|
+
* Based on MEL SPEC v0.3.3 Section 5
|
|
4
|
+
*/
|
|
5
|
+
import type { Diagnostic } from "../diagnostics/types.js";
|
|
6
|
+
import type { ProgramNode } from "../parser/ast.js";
|
|
7
|
+
import type { MelExprNode } from "../lowering/lower-expr.js";
|
|
8
|
+
import { type ExprNode as RuntimeExprNode, type FlowNode as RuntimeFlowNode, type PatchPath } from "@manifesto-ai/core";
|
|
9
|
+
/**
|
|
10
|
+
* Core ExprNode types (simplified, matching core/schema/expr.ts)
|
|
11
|
+
*/
|
|
12
|
+
export type CoreExprNode = RuntimeExprNode;
|
|
13
|
+
export type CompilerExprNode = MelExprNode;
|
|
14
|
+
/**
|
|
15
|
+
* Core FlowNode types (matching core/schema/flow.ts)
|
|
16
|
+
*/
|
|
17
|
+
export type CoreFlowNode = RuntimeFlowNode;
|
|
18
|
+
export type CompilerFlowNode = {
|
|
19
|
+
kind: "seq";
|
|
20
|
+
steps: CompilerFlowNode[];
|
|
21
|
+
} | {
|
|
22
|
+
kind: "if";
|
|
23
|
+
cond: CompilerExprNode;
|
|
24
|
+
then: CompilerFlowNode;
|
|
25
|
+
else?: CompilerFlowNode;
|
|
26
|
+
} | {
|
|
27
|
+
kind: "patch";
|
|
28
|
+
op: "set" | "unset" | "merge";
|
|
29
|
+
path: PatchPath;
|
|
30
|
+
value?: CompilerExprNode;
|
|
31
|
+
} | {
|
|
32
|
+
kind: "effect";
|
|
33
|
+
type: string;
|
|
34
|
+
params: Record<string, CompilerExprNode>;
|
|
35
|
+
} | {
|
|
36
|
+
kind: "call";
|
|
37
|
+
flow: string;
|
|
38
|
+
} | {
|
|
39
|
+
kind: "halt";
|
|
40
|
+
reason?: string;
|
|
41
|
+
} | {
|
|
42
|
+
kind: "fail";
|
|
43
|
+
code: string;
|
|
44
|
+
message?: CompilerExprNode;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Field type definition
|
|
48
|
+
*/
|
|
49
|
+
export type FieldType = "string" | "number" | "boolean" | "null" | "object" | "array" | {
|
|
50
|
+
enum: readonly unknown[];
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Field specification
|
|
54
|
+
*/
|
|
55
|
+
export interface FieldSpec {
|
|
56
|
+
type: FieldType;
|
|
57
|
+
required: boolean;
|
|
58
|
+
default?: unknown;
|
|
59
|
+
description?: string;
|
|
60
|
+
fields?: Record<string, FieldSpec>;
|
|
61
|
+
items?: FieldSpec;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* State specification
|
|
65
|
+
*/
|
|
66
|
+
export interface StateSpec {
|
|
67
|
+
fields: Record<string, FieldSpec>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Computed field specification
|
|
71
|
+
*/
|
|
72
|
+
export interface ComputedFieldSpec {
|
|
73
|
+
deps: string[];
|
|
74
|
+
expr: CoreExprNode;
|
|
75
|
+
description?: string;
|
|
76
|
+
}
|
|
77
|
+
export interface CompilerComputedFieldSpec {
|
|
78
|
+
deps: string[];
|
|
79
|
+
expr: CompilerExprNode;
|
|
80
|
+
description?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Computed specification
|
|
84
|
+
*/
|
|
85
|
+
export interface ComputedSpec {
|
|
86
|
+
fields: Record<string, ComputedFieldSpec>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Action specification
|
|
90
|
+
*/
|
|
91
|
+
export interface ActionSpec {
|
|
92
|
+
flow: CoreFlowNode;
|
|
93
|
+
input?: FieldSpec;
|
|
94
|
+
available?: CoreExprNode;
|
|
95
|
+
description?: string;
|
|
96
|
+
}
|
|
97
|
+
export interface CompilerActionSpec {
|
|
98
|
+
flow: CompilerFlowNode;
|
|
99
|
+
input?: FieldSpec;
|
|
100
|
+
available?: CompilerExprNode;
|
|
101
|
+
description?: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Domain schema (output IR)
|
|
105
|
+
*/
|
|
106
|
+
/**
|
|
107
|
+
* v0.3.3: Type specification (named type declaration)
|
|
108
|
+
*/
|
|
109
|
+
export interface TypeSpec {
|
|
110
|
+
name: string;
|
|
111
|
+
definition: TypeDefinition;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* v0.3.3: Type definition structure
|
|
115
|
+
*/
|
|
116
|
+
export type TypeDefinition = {
|
|
117
|
+
kind: "primitive";
|
|
118
|
+
type: string;
|
|
119
|
+
} | {
|
|
120
|
+
kind: "array";
|
|
121
|
+
element: TypeDefinition;
|
|
122
|
+
} | {
|
|
123
|
+
kind: "record";
|
|
124
|
+
key: TypeDefinition;
|
|
125
|
+
value: TypeDefinition;
|
|
126
|
+
} | {
|
|
127
|
+
kind: "object";
|
|
128
|
+
fields: Record<string, {
|
|
129
|
+
type: TypeDefinition;
|
|
130
|
+
optional: boolean;
|
|
131
|
+
}>;
|
|
132
|
+
} | {
|
|
133
|
+
kind: "union";
|
|
134
|
+
types: TypeDefinition[];
|
|
135
|
+
} | {
|
|
136
|
+
kind: "literal";
|
|
137
|
+
value: string | number | boolean | null;
|
|
138
|
+
} | {
|
|
139
|
+
kind: "ref";
|
|
140
|
+
name: string;
|
|
141
|
+
};
|
|
142
|
+
export interface DomainSchema {
|
|
143
|
+
id: string;
|
|
144
|
+
version: string;
|
|
145
|
+
hash: string;
|
|
146
|
+
/** v0.3.3: Named type declarations */
|
|
147
|
+
types: Record<string, TypeSpec>;
|
|
148
|
+
state: StateSpec;
|
|
149
|
+
computed: ComputedSpec;
|
|
150
|
+
actions: Record<string, ActionSpec>;
|
|
151
|
+
meta?: {
|
|
152
|
+
name?: string;
|
|
153
|
+
description?: string;
|
|
154
|
+
authors?: string[];
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
export interface CanonicalDomainSchema {
|
|
158
|
+
id: string;
|
|
159
|
+
version: string;
|
|
160
|
+
hash: string;
|
|
161
|
+
types: Record<string, TypeSpec>;
|
|
162
|
+
state: StateSpec;
|
|
163
|
+
computed: {
|
|
164
|
+
fields: Record<string, CompilerComputedFieldSpec>;
|
|
165
|
+
};
|
|
166
|
+
actions: Record<string, CompilerActionSpec>;
|
|
167
|
+
meta?: {
|
|
168
|
+
name?: string;
|
|
169
|
+
description?: string;
|
|
170
|
+
authors?: string[];
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
export interface GenerateResult {
|
|
174
|
+
schema: DomainSchema | null;
|
|
175
|
+
diagnostics: Diagnostic[];
|
|
176
|
+
}
|
|
177
|
+
export interface GenerateCanonicalResult {
|
|
178
|
+
schema: CanonicalDomainSchema | null;
|
|
179
|
+
diagnostics: Diagnostic[];
|
|
180
|
+
}
|
|
181
|
+
export declare function generateCanonical(program: ProgramNode): GenerateCanonicalResult;
|
|
182
|
+
/**
|
|
183
|
+
* Generate runtime-ready DomainSchema from MEL AST.
|
|
184
|
+
*/
|
|
185
|
+
export declare function generate(program: ProgramNode): GenerateResult;
|