/** * IR Generator - Transforms MEL AST to Core DomainSchema * Based on MEL SPEC v0.3.3 Section 5 */ import type { Diagnostic } from "../diagnostics/types.js"; import type { ProgramNode } from "../parser/ast.js"; import type { MelExprNode } from "../lowering/lower-expr.js"; import { type ExprNode as RuntimeExprNode, type FlowNode as RuntimeFlowNode } from "@manifesto-ai/core"; /** * Core ExprNode types (simplified, matching core/schema/expr.ts) */ export type CoreExprNode = RuntimeExprNode; export type CompilerExprNode = MelExprNode; /** * Core FlowNode type (kept attached to @manifesto-ai/core to avoid schema drift). */ export type CoreFlowNode = RuntimeFlowNode; type CompilerFlowPatchSegment = { kind: "prop"; name: string; } | { kind: "index"; index: number; } | { kind: "expr"; expr: CompilerExprNode; }; type CompilerFlowPatchPath = CompilerFlowPatchSegment[]; export type CompilerFlowNode = { kind: "seq"; steps: CompilerFlowNode[]; } | { kind: "if"; cond: CompilerExprNode; then: CompilerFlowNode; else?: CompilerFlowNode; } | { kind: "patch"; op: "set" | "unset" | "merge"; path: CompilerFlowPatchPath; value?: CompilerExprNode; } | { kind: "causalGuard"; guardId: string; body: CompilerFlowNode; } | { kind: "effect"; type: string; params: Record; } | { kind: "call"; flow: string; } | { kind: "halt"; reason?: string; } | { kind: "fail"; code: string; message?: CompilerExprNode; }; /** * Field type definition */ export type FieldType = "string" | "number" | "boolean" | "null" | "object" | "array" | { enum: readonly unknown[]; }; /** * Field specification */ export interface FieldSpec { type: FieldType; required: boolean; default?: unknown; description?: string; fields?: Record; items?: FieldSpec; } /** * State specification */ export interface StateSpec { fields: Record; fieldTypes?: Record; } export interface ContextSpec { fields: Record; fieldTypes?: Record; } /** * Computed field specification */ export interface ComputedFieldSpec { deps: string[]; expr: CoreExprNode; description?: string; } export interface CompilerComputedFieldSpec { deps: string[]; expr: CompilerExprNode; description?: string; } /** * Computed specification */ export interface ComputedSpec { fields: Record; } /** * Action specification */ export interface ActionSpec { flow: CoreFlowNode; input?: FieldSpec; inputType?: TypeDefinition; params?: readonly string[]; available?: CoreExprNode; dispatchable?: CoreExprNode; description?: string; } export interface CompilerActionSpec { flow: CompilerFlowNode; input?: FieldSpec; inputType?: TypeDefinition; params?: readonly string[]; available?: CompilerExprNode; dispatchable?: CompilerExprNode; description?: string; } /** * Domain schema (output IR) */ /** * v0.3.3: Type specification (named type declaration) */ export interface TypeSpec { name: string; definition: TypeDefinition; } /** * v0.3.3: Type definition structure */ export type TypeDefinition = { kind: "primitive"; type: string; } | { kind: "array"; element: TypeDefinition; } | { kind: "record"; key: TypeDefinition; value: TypeDefinition; } | { kind: "object"; fields: Record; } | { kind: "union"; types: TypeDefinition[]; } | { kind: "literal"; value: string | number | boolean | null; } | { kind: "ref"; name: string; }; export interface DomainSchema { id: string; version: string; hash: string; /** v0.3.3: Named type declarations */ types: Record; state: StateSpec; context?: ContextSpec; computed: ComputedSpec; actions: Record; meta?: { name?: string; description?: string; authors?: string[]; }; } export interface CanonicalDomainSchema { id: string; version: string; hash: string; types: Record; state: StateSpec; context?: ContextSpec; computed: { fields: Record; }; actions: Record; meta?: { name?: string; description?: string; authors?: string[]; }; } export interface GenerateResult { schema: DomainSchema | null; diagnostics: Diagnostic[]; } export interface GenerateCanonicalResult { schema: CanonicalDomainSchema | null; diagnostics: Diagnostic[]; } export declare function generateCanonical(program: ProgramNode): GenerateCanonicalResult; /** * Generate runtime-ready DomainSchema from MEL AST. */ export declare function generate(program: ProgramNode): GenerateResult; export {};