@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.
Files changed (72) hide show
  1. package/dist/analyzer/entity-primitives.d.ts +3 -0
  2. package/dist/analyzer/expr-type-surface.d.ts +21 -0
  3. package/dist/analyzer/flow-composition.d.ts +7 -0
  4. package/dist/analyzer/index.d.ts +5 -0
  5. package/dist/analyzer/scope.d.ts +76 -0
  6. package/dist/analyzer/validator.d.ts +69 -0
  7. package/dist/api/compile-mel-patch-collector.d.ts +33 -0
  8. package/dist/api/compile-mel-patch-expr.d.ts +8 -0
  9. package/dist/api/compile-mel-patch-location.d.ts +9 -0
  10. package/dist/api/compile-mel-patch.d.ts +5 -0
  11. package/dist/api/compile-mel.d.ts +125 -0
  12. package/dist/api/index.d.ts +9 -0
  13. package/dist/{chunk-4JJQCFJH.js → chunk-7TT6Y5ZC.js} +6 -2
  14. package/dist/chunk-7TT6Y5ZC.js.map +1 -0
  15. package/dist/{chunk-AYZTDA3J.js → chunk-LI5HNMZV.js} +2 -2
  16. package/dist/{chunk-K4IKHGOP.js → chunk-WZRGVNJK.js} +3 -3
  17. package/dist/diagnostics/codes.d.ts +24 -0
  18. package/dist/diagnostics/format.d.ts +25 -0
  19. package/dist/diagnostics/index.d.ts +6 -0
  20. package/dist/diagnostics/types.d.ts +66 -0
  21. package/dist/esbuild.d.ts +6 -8
  22. package/dist/esbuild.js +3 -3
  23. package/dist/evaluation/context.d.ts +90 -0
  24. package/dist/evaluation/evaluate-expr.d.ts +23 -0
  25. package/dist/evaluation/evaluate-patch.d.ts +122 -0
  26. package/dist/evaluation/evaluate-runtime-patch.d.ts +59 -0
  27. package/dist/evaluation/index.d.ts +14 -0
  28. package/dist/generator/index.d.ts +6 -0
  29. package/dist/generator/ir.d.ts +185 -0
  30. package/dist/generator/lowering.d.ts +10 -0
  31. package/dist/generator/normalizer.d.ts +15 -0
  32. package/dist/generator/runtime-lowering.d.ts +2 -0
  33. package/dist/index.d.ts +19 -2785
  34. package/dist/index.js +1 -1
  35. package/dist/lexer/index.d.ts +6 -0
  36. package/dist/lexer/lexer.d.ts +58 -0
  37. package/dist/lexer/source-location.d.ts +40 -0
  38. package/dist/lexer/tokens.d.ts +46 -0
  39. package/dist/lowering/context.d.ts +95 -0
  40. package/dist/lowering/errors.d.ts +83 -0
  41. package/dist/lowering/index.d.ts +19 -0
  42. package/dist/lowering/lower-expr.d.ts +79 -0
  43. package/dist/lowering/lower-patch.d.ts +230 -0
  44. package/dist/lowering/lower-runtime-patch.d.ts +126 -0
  45. package/dist/lowering/to-mel-expr.d.ts +12 -0
  46. package/dist/mel-module.d.ts +14 -0
  47. package/dist/node-loader.d.ts +3 -7
  48. package/dist/node-loader.js +2 -2
  49. package/dist/parser/ast.d.ts +367 -0
  50. package/dist/parser/index.d.ts +6 -0
  51. package/dist/parser/parser.d.ts +101 -0
  52. package/dist/parser/precedence.d.ts +43 -0
  53. package/dist/renderer/expr-node.d.ts +171 -0
  54. package/dist/renderer/fragment.d.ts +83 -0
  55. package/dist/renderer/index.d.ts +22 -0
  56. package/dist/renderer/patch-op.d.ts +81 -0
  57. package/dist/renderer/type-expr.d.ts +60 -0
  58. package/dist/rollup.d.ts +6 -8
  59. package/dist/rollup.js +3 -3
  60. package/dist/rspack.d.ts +6 -7
  61. package/dist/rspack.js +3 -3
  62. package/dist/unplugin.d.ts +14 -0
  63. package/dist/utils/unicode-order.d.ts +5 -0
  64. package/dist/vite.d.ts +6 -8
  65. package/dist/vite.js +3 -3
  66. package/dist/webpack.d.ts +6 -8
  67. package/dist/webpack.js +3 -3
  68. package/package.json +16 -14
  69. package/dist/chunk-4JJQCFJH.js.map +0 -1
  70. package/dist/unplugin-6wnvFiEo.d.ts +0 -17
  71. /package/dist/{chunk-AYZTDA3J.js.map → chunk-LI5HNMZV.js.map} +0 -0
  72. /package/dist/{chunk-K4IKHGOP.js.map → chunk-WZRGVNJK.js.map} +0 -0
@@ -0,0 +1,3 @@
1
+ import { type Diagnostic } from "../diagnostics/types.js";
2
+ import type { ProgramNode } from "../parser/ast.js";
3
+ export declare function validateEntityPrimitives(program: ProgramNode): Diagnostic[];
@@ -0,0 +1,21 @@
1
+ import type { ComputedNode, DomainNode, ExprNode, ParamNode, TypeDeclNode, TypeExprNode } from "../parser/ast.js";
2
+ export type TypeEnv = Map<string, TypeExprNode>;
3
+ export type ComparableSurfaceClass = "primitive" | "nonprimitive" | "unknown";
4
+ export interface DomainTypeSymbols {
5
+ stateTypes: Map<string, TypeExprNode>;
6
+ computedDecls: Map<string, ComputedNode>;
7
+ typeDefs: Map<string, TypeDeclNode>;
8
+ computedTypeCache: Map<string, TypeExprNode | null>;
9
+ computedTypeInFlight: Set<string>;
10
+ }
11
+ export declare function collectDomainTypeSymbols(domain: DomainNode): DomainTypeSymbols;
12
+ export declare function createActionTypeEnv(params: readonly ParamNode[]): TypeEnv;
13
+ export declare function inferExprType(expr: ExprNode, env: TypeEnv, symbols: DomainTypeSymbols): TypeExprNode | null;
14
+ export declare function classifyComparableExpr(expr: ExprNode, env: TypeEnv, symbols: DomainTypeSymbols): ComparableSurfaceClass;
15
+ export declare function classifyComparableType(typeExpr: TypeExprNode | null, symbols: DomainTypeSymbols): ComparableSurfaceClass;
16
+ export declare function resolveType(typeExpr: TypeExprNode | null, symbols: DomainTypeSymbols, seen?: Set<string>): TypeExprNode | null;
17
+ export declare function getPropertyType(typeExpr: TypeExprNode | null, property: string, symbols: DomainTypeSymbols): TypeExprNode | null;
18
+ export declare function getIndexType(typeExpr: TypeExprNode | null, symbols: DomainTypeSymbols): TypeExprNode | null;
19
+ export declare function getArrayElementType(typeExpr: TypeExprNode | null, symbols: DomainTypeSymbols): TypeExprNode | null;
20
+ export declare function isPrimitiveEntityIdType(typeExpr: TypeExprNode, symbols: DomainTypeSymbols): boolean;
21
+ export declare function isNullType(typeExpr: TypeExprNode): boolean;
@@ -0,0 +1,7 @@
1
+ import { type Diagnostic } from "../diagnostics/types.js";
2
+ import type { ProgramNode } from "../parser/ast.js";
3
+ export interface FlowExpansionResult {
4
+ program: ProgramNode;
5
+ diagnostics: Diagnostic[];
6
+ }
7
+ export declare function validateAndExpandFlows(program: ProgramNode): FlowExpansionResult;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Analyzer Module - Semantic analysis for MEL
3
+ */
4
+ export * from "./scope.js";
5
+ export * from "./validator.js";
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Scope Analysis for MEL
3
+ * Tracks variable scopes and resolves identifiers
4
+ * Based on MEL SPEC v0.3.1 Section 4.10
5
+ */
6
+ import type { ProgramNode } from "../parser/ast.js";
7
+ import type { Diagnostic } from "../diagnostics/types.js";
8
+ import type { SourceLocation } from "../lexer/source-location.js";
9
+ /**
10
+ * Symbol kinds
11
+ */
12
+ export type SymbolKind = "state" | "computed" | "param" | "action" | "iteration";
13
+ /**
14
+ * Symbol information
15
+ */
16
+ export interface Symbol {
17
+ name: string;
18
+ kind: SymbolKind;
19
+ location: SourceLocation;
20
+ type?: string;
21
+ }
22
+ /**
23
+ * Scope represents a lexical scope
24
+ */
25
+ export declare class Scope {
26
+ readonly parent: Scope | null;
27
+ readonly symbols: Map<string, Symbol>;
28
+ readonly kind: "domain" | "action" | "guard";
29
+ constructor(kind: "domain" | "action" | "guard", parent?: Scope | null);
30
+ /**
31
+ * Define a new symbol in this scope
32
+ */
33
+ define(symbol: Symbol): void;
34
+ /**
35
+ * Look up a symbol, searching parent scopes if not found
36
+ */
37
+ lookup(name: string): Symbol | undefined;
38
+ /**
39
+ * Check if a symbol is defined in this scope (not parent scopes)
40
+ */
41
+ isDefined(name: string): boolean;
42
+ }
43
+ /**
44
+ * Result of scope analysis
45
+ */
46
+ export interface ScopeAnalysisResult {
47
+ scopes: Map<string, Scope>;
48
+ diagnostics: Diagnostic[];
49
+ }
50
+ /**
51
+ * Scope Analyzer - builds scope tree and checks for errors
52
+ */
53
+ export declare class ScopeAnalyzer {
54
+ private diagnostics;
55
+ private scopes;
56
+ private currentScope;
57
+ private domainScope;
58
+ /**
59
+ * Analyze a MEL program
60
+ */
61
+ analyze(program: ProgramNode): ScopeAnalysisResult;
62
+ private analyzeDomain;
63
+ private analyzeComputedExpr;
64
+ private analyzeAction;
65
+ private analyzeStmt;
66
+ private analyzeExpr;
67
+ private checkIdentifier;
68
+ private checkSystemIdent;
69
+ private validatePath;
70
+ private defineSymbol;
71
+ private error;
72
+ }
73
+ /**
74
+ * Analyze a MEL program for scope issues
75
+ */
76
+ export declare function analyzeScope(program: ProgramNode): ScopeAnalysisResult;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Semantic Validator for MEL
3
+ * Validates semantic rules beyond syntax
4
+ * Based on MEL SPEC v0.3.3 and FDR-MEL-*
5
+ */
6
+ import type { ProgramNode } from "../parser/ast.js";
7
+ import type { Diagnostic } from "../diagnostics/types.js";
8
+ /**
9
+ * Result of semantic validation
10
+ */
11
+ export interface ValidationResult {
12
+ valid: boolean;
13
+ diagnostics: Diagnostic[];
14
+ }
15
+ /**
16
+ * Semantic Validator
17
+ */
18
+ export declare class SemanticValidator {
19
+ private ctx;
20
+ private symbols;
21
+ /**
22
+ * Validate a MEL program
23
+ */
24
+ validate(program: ProgramNode): ValidationResult;
25
+ private validateDomain;
26
+ /**
27
+ * v0.3.3: Validate state fields for W012 (anonymous object types)
28
+ */
29
+ private validateState;
30
+ /**
31
+ * v0.3.3: Validate state field - check for anonymous object types (W012)
32
+ */
33
+ private validateStateField;
34
+ private validateStateInitializer;
35
+ /**
36
+ * v0.3.3: Check if a type expression contains anonymous object types
37
+ * Issues W012 warning for inline object types in state fields
38
+ */
39
+ private checkAnonymousObjectType;
40
+ private validateAction;
41
+ /**
42
+ * v0.3.3: Validate available expression is pure (E005)
43
+ * No $system.*, no effects, no $input.*
44
+ */
45
+ private validateAvailableExpr;
46
+ private validateGuardedStmt;
47
+ private validateWhen;
48
+ private validateOnce;
49
+ private validateOnceIntent;
50
+ private validatePatch;
51
+ private validateEffect;
52
+ private validateFail;
53
+ private validateStop;
54
+ private validateCondition;
55
+ private validateExpr;
56
+ private validateFunctionCall;
57
+ private validatePrimitiveEquality;
58
+ private inferType;
59
+ private requireAssignable;
60
+ private requireArrayCompatible;
61
+ private requireLenCompatible;
62
+ private validateCoalesceTypes;
63
+ private error;
64
+ private warn;
65
+ }
66
+ /**
67
+ * Validate a MEL program semantically
68
+ */
69
+ export declare function validateSemantics(program: ProgramNode): ValidationResult;
@@ -0,0 +1,33 @@
1
+ import type { Diagnostic } from "../diagnostics/types.js";
2
+ import type { MelExprNode } from "../lowering/lower-expr.js";
3
+ import type { MelIRPatchPath } from "../lowering/lower-runtime-patch.js";
4
+ import type { GuardedStmtNode, InnerStmtNode, PatchStmtNode } from "../parser/ast.js";
5
+ import { toMelExpr } from "./compile-mel-patch-expr.js";
6
+ export interface PatchCollectContext {
7
+ actionName: string;
8
+ onceCounter: number;
9
+ onceIntentCounter: number;
10
+ whenCounter: number;
11
+ }
12
+ export type ConditionedPatchStatement = {
13
+ patch: PatchStmtNode;
14
+ condition?: MelExprNode;
15
+ };
16
+ export interface PatchCollectorDeps {
17
+ toMelExpr: (expr: Parameters<typeof toMelExpr>[0]) => MelExprNode;
18
+ mapLocation: (location: Diagnostic["location"]) => Diagnostic["location"];
19
+ }
20
+ export declare class PatchStatementCollector {
21
+ private readonly deps;
22
+ private readonly conditionComposer;
23
+ private readonly exprValidator;
24
+ constructor(deps: PatchCollectorDeps);
25
+ collect(stmts: GuardedStmtNode[] | InnerStmtNode[], errors: Diagnostic[], context: PatchCollectContext, parentCondition: MelExprNode | undefined): ConditionedPatchStatement[];
26
+ private collectPatchStatements;
27
+ }
28
+ export declare function compilePatchStmtToMelRuntime(patchStatement: ConditionedPatchStatement): {
29
+ op: "set" | "unset" | "merge";
30
+ path: MelIRPatchPath;
31
+ value?: MelExprNode;
32
+ condition?: MelExprNode;
33
+ };
@@ -0,0 +1,8 @@
1
+ import type { ExprNode } from "../parser/ast.js";
2
+ import type { MelExprNode } from "../lowering/lower-expr.js";
3
+ export declare function isSyntheticPatchCondition(condition: ExprNode): condition is (ExprNode & {
4
+ kind: "literal";
5
+ literalType: "boolean";
6
+ value: true;
7
+ });
8
+ export declare function toMelExpr(input: ExprNode): MelExprNode;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Location mapping helpers for compile-mel-patch synthetic wrapper diagnostics.
3
+ */
4
+ import type { Diagnostic } from "../diagnostics/types.js";
5
+ export declare const SYNTHETIC_PATCH_PREFIX_LINES = 3;
6
+ export declare const SYNTHETIC_PATCH_PREFIX_COLUMNS = 6;
7
+ export declare function computeLineStartOffsets(lines: string[]): number[];
8
+ export declare function makePatchLocationMapper(patchLines: string[], patchLineStarts: number[]): (location: Diagnostic["location"]) => Diagnostic["location"];
9
+ export declare function remapDiagnosticsToPatchSource(diagnostics: Diagnostic[], patchLines: string[], patchLineStarts: number[]): Diagnostic[];
@@ -0,0 +1,5 @@
1
+ import type { CompileMelPatchOptions, CompileMelPatchResult } from "./compile-mel.js";
2
+ /**
3
+ * Compile MEL patch text into RuntimeConditionalPatchOps.
4
+ */
5
+ export declare function compileMelPatchText(melText: string, options: CompileMelPatchOptions): CompileMelPatchResult;
@@ -0,0 +1,125 @@
1
+ /**
2
+ * MEL Text Ingest API
3
+ *
4
+ * Compiles MEL text to DomainSchema or RuntimeConditionalPatchOp[].
5
+ *
6
+ * @see SPEC v0.4.0 §19
7
+ */
8
+ import type { Diagnostic } from "../diagnostics/types.js";
9
+ import type { DomainSchema } from "../generator/ir.js";
10
+ import type { RuntimeConditionalPatchOp } from "../lowering/lower-runtime-patch.js";
11
+ /**
12
+ * Trace entry for compilation steps.
13
+ */
14
+ export interface CompileTrace {
15
+ phase: "lex" | "parse" | "analyze" | "generate" | "lower";
16
+ durationMs: number;
17
+ details?: Record<string, unknown>;
18
+ }
19
+ /**
20
+ * Domain compilation options.
21
+ */
22
+ export interface CompileMelDomainOptions {
23
+ mode: "domain";
24
+ fnTableVersion?: string;
25
+ }
26
+ /**
27
+ * Domain compilation result.
28
+ *
29
+ * @see SPEC v0.4.0 §19.1
30
+ */
31
+ export interface CompileMelDomainResult {
32
+ /**
33
+ * Compiled schema, or null if errors occurred.
34
+ */
35
+ schema: DomainSchema | null;
36
+ /**
37
+ * Compilation trace.
38
+ */
39
+ trace: CompileTrace[];
40
+ /**
41
+ * Warning diagnostics.
42
+ */
43
+ warnings: Diagnostic[];
44
+ /**
45
+ * Error diagnostics.
46
+ */
47
+ errors: Diagnostic[];
48
+ }
49
+ /**
50
+ * Patch compilation options.
51
+ */
52
+ export interface CompileMelPatchOptions {
53
+ mode: "patch";
54
+ /**
55
+ * Action name for context.
56
+ */
57
+ actionName: string;
58
+ /**
59
+ * Allowed system path prefixes.
60
+ * Default: ["meta", "input"] (system is forbidden per §20.3).
61
+ */
62
+ allowSysPaths?: {
63
+ prefixes: ("meta" | "input")[];
64
+ };
65
+ /**
66
+ * Function table version.
67
+ */
68
+ fnTableVersion?: string;
69
+ }
70
+ /**
71
+ * Patch compilation result.
72
+ *
73
+ * @see SPEC v0.4.0 §19.2
74
+ */
75
+ export interface CompileMelPatchResult {
76
+ /**
77
+ * Compiled patch operations.
78
+ * These still contain Core IR expressions that need evaluation.
79
+ */
80
+ ops: RuntimeConditionalPatchOp[];
81
+ /**
82
+ * Compilation trace.
83
+ */
84
+ trace: CompileTrace[];
85
+ /**
86
+ * Warning diagnostics.
87
+ */
88
+ warnings: Diagnostic[];
89
+ /**
90
+ * Error diagnostics.
91
+ */
92
+ errors: Diagnostic[];
93
+ }
94
+ /**
95
+ * Compile MEL text to DomainSchema.
96
+ *
97
+ * Takes a complete MEL domain definition and produces a DomainSchema
98
+ * suitable for use with core.compute().
99
+ *
100
+ * @param melText - MEL domain source text
101
+ * @param options - Compilation options
102
+ * @returns Compilation result with schema or errors
103
+ *
104
+ * @see SPEC v0.4.0 §19.1
105
+ */
106
+ export declare function compileMelDomain(melText: string, options?: CompileMelDomainOptions): CompileMelDomainResult;
107
+ /**
108
+ * Compile MEL patch text to RuntimeConditionalPatchOp[].
109
+ *
110
+ * Takes MEL patch statements (set, unset, merge) and produces
111
+ * RuntimeConditionalPatchOp[] with Core IR expressions.
112
+ *
113
+ * The returned ops still contain expressions that need to be evaluated
114
+ * by evaluateRuntimePatches() to get concrete values.
115
+ *
116
+ * Constraints:
117
+ * - §20.3: $system.* is forbidden in Translator path
118
+ *
119
+ * @param melText - MEL patch source text
120
+ * @param options - Compilation options
121
+ * @returns Compilation result with ops or errors
122
+ *
123
+ * @see SPEC v0.4.0 §19.2
124
+ */
125
+ export declare function compileMelPatch(melText: string, options: CompileMelPatchOptions): CompileMelPatchResult;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Compile API
3
+ *
4
+ * MEL text ingest functions.
5
+ *
6
+ * @see SPEC v0.4.0 §19
7
+ */
8
+ export type { CompileTrace, CompileMelDomainOptions, CompileMelDomainResult, CompileMelPatchOptions, CompileMelPatchResult, } from "./compile-mel.js";
9
+ export { compileMelDomain, compileMelPatch } from "./compile-mel.js";
@@ -4923,7 +4923,11 @@ function toMelBinaryOp(op) {
4923
4923
  }
4924
4924
 
4925
4925
  // src/generator/ir.ts
4926
- import { hashSchemaSync, semanticPathToPatchPath, sha256Sync } from "@manifesto-ai/core";
4926
+ import {
4927
+ hashSchemaSync,
4928
+ semanticPathToPatchPath,
4929
+ sha256Sync
4930
+ } from "@manifesto-ai/core";
4927
4931
 
4928
4932
  // src/generator/runtime-lowering.ts
4929
4933
  var ENTITY_PRIMITIVES = /* @__PURE__ */ new Set(["findById", "existsById", "updateById", "removeById"]);
@@ -7628,4 +7632,4 @@ export {
7628
7632
  compileMelDomain,
7629
7633
  compileMelPatch
7630
7634
  };
7631
- //# sourceMappingURL=chunk-4JJQCFJH.js.map
7635
+ //# sourceMappingURL=chunk-7TT6Y5ZC.js.map