@manifesto-ai/compiler 3.9.0 → 5.0.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/README.md CHANGED
@@ -1,16 +1,22 @@
1
1
  # @manifesto-ai/compiler
2
2
 
3
- > **Compiler** translates MEL (Manifesto Expression Language) into DomainSchema for Manifesto Core.
3
+ > **Compiler** lets apps import MEL domains and can emit generated SDK domain facades.
4
4
 
5
5
  ---
6
6
 
7
7
  ## What is the Compiler?
8
8
 
9
- The compiler is the MEL frontend for Manifesto. It tokenizes, parses, validates, and lowers MEL source into a DomainSchema that Core can evaluate deterministically.
9
+ The compiler is the MEL frontend for Manifesto. For app developers, it lets a
10
+ bundler import `.mel` files and optionally emit the generated
11
+ `<source>.domain.ts` facade used by `createManifesto<TDomain>()`.
10
12
 
13
+ ```text
14
+ .mel source -> compiler plugin -> createManifesto()
15
+ -> optional generated <source>.domain.ts facade
11
16
  ```
12
- MEL source -> Compiler -> DomainSchema -> Core
13
- ```
17
+
18
+ Internally, the compiler tokenizes, parses, validates, and lowers MEL source
19
+ into the runtime schema consumed behind the SDK app path.
14
20
 
15
21
  ---
16
22
 
@@ -19,9 +25,10 @@ MEL source -> Compiler -> DomainSchema -> Core
19
25
  | Responsibility | Description |
20
26
  | --- | --- |
21
27
  | Parse MEL | Tokenize and parse MEL into an AST |
22
- | Validate | Scope, typing, and semantic checks aligned to the current compiler contract |
23
- | Generate IR | Produce DomainSchema for Core |
24
- | Lower system values | Optional lowering of $system.* into explicit effects |
28
+ | Validate | Scope, typing, and domain-rule checks aligned to the current compiler contract |
29
+ | Emit runtime schema | Produce the schema imported by `createManifesto()` |
30
+ | Emit optional TypeScript facade | Write generated domain types for larger SDK apps |
31
+ | Lower runtime/context expressions | Lower `$runtime.*` and `$context.*` references for deterministic runtime evaluation |
25
32
 
26
33
  ---
27
34
 
@@ -29,15 +36,15 @@ MEL source -> Compiler -> DomainSchema -> Core
29
36
 
30
37
  | NOT Responsible For | Who Is |
31
38
  | --- | --- |
32
- | Execute effects | Host |
33
- | Apply patches | Core |
34
- | Govern authority or seal history | `@manifesto-ai/governance` + `@manifesto-ai/lineage` |
39
+ | Execute external work | Runtime effect handlers |
40
+ | Apply domain transitions | Manifesto runtime |
41
+ | Add optional approval/history protocols | `@manifesto-ai/governance` + `@manifesto-ai/lineage` |
35
42
  | Bind UI or caller integrations | SDK / application layer |
36
43
 
37
44
  Current MEL/compiler highlights:
38
45
 
39
46
  - `available when` remains the coarse action gate.
40
- - `dispatchable when` is the fine bound-intent legality gate.
47
+ - `dispatchable when` is the fine input-specific legality gate.
41
48
  - Expression-level collection builtins include `filter`, `map`, `find`, `every`, and `some`.
42
49
  - Bounded parser-free sugar includes `absDiff`, `clamp`, `idiv`, `streak`, `match`, `argmax`, and `argmin`.
43
50
  - Current schema-position lowering supports `Record<string, T>` and `T | null`.
@@ -122,31 +129,32 @@ import { createCompilerCodegen } from "@manifesto-ai/codegen";
122
129
 
123
130
  melPlugin({
124
131
  include: /\.mel$/, // File filter (default: /\.mel$/)
125
- codegen: {
126
- emit: createCompilerCodegen(),
127
- timing: "transform", // default: run during dev/build transforms
128
- },
132
+ codegen: createCompilerCodegen(),
129
133
  });
130
134
  ```
131
135
 
132
- `codegen` is an explicit emitter hook. `@manifesto-ai/compiler` does not import `@manifesto-ai/codegen` for you; install it only if you want MEL artifacts written during dev or build and inject the emitter yourself.
136
+ `codegen` is an explicit emitter hook. `@manifesto-ai/compiler` does not import
137
+ `@manifesto-ai/codegen` for you; install it only if you want MEL artifacts
138
+ written during dev or build and inject the emitter yourself.
133
139
 
134
- `createCompilerCodegen()` can be called with no options. In that default mode it uses the canonical domain plugin and writes `<source>.domain.ts` next to the compiled `.mel` file during transform. If you prefer build-end emission, set `timing: "build"` or `timing: "both"`. You can still customize the pipeline:
140
+ `createCompilerCodegen()` can be called with no options. In that default mode
141
+ it writes `<source>.domain.ts` next to the compiled `.mel` file during
142
+ transform. You can still customize the generated facade:
135
143
 
136
144
  ```typescript
137
145
  import { createCompilerCodegen, createDomainPlugin } from "@manifesto-ai/codegen";
138
146
 
139
147
  melPlugin({
140
- codegen: {
141
- emit: createCompilerCodegen({
142
- outDir: "src/generated",
143
- plugins: [createDomainPlugin({ interfaceName: "CounterDomain" })],
144
- }),
145
- timing: "build",
146
- },
148
+ codegen: createCompilerCodegen({
149
+ outDir: "src/generated",
150
+ plugins: [createDomainPlugin({ interfaceName: "TodoDomain" })],
151
+ }),
147
152
  });
148
153
  ```
149
154
 
155
+ Advanced build setups can still pass `{ emit, timing }` when they need build-end
156
+ or dual transform/build emission.
157
+
150
158
  ### Subpath Exports
151
159
 
152
160
  | Export | Bundler |
@@ -181,12 +189,12 @@ const source = `
181
189
  domain Counter {
182
190
  state { count: number = 0 }
183
191
  action increment() {
184
- when true { patch count = add(count, 1) }
192
+ onceIntent { patch count = count + 1 }
185
193
  }
186
194
  }
187
195
  `;
188
196
 
189
- const result = compile(source, { lowerSystemValues: true });
197
+ const result = compile(source);
190
198
 
191
199
  if (!result.success) {
192
200
  console.error(result.errors);
@@ -202,10 +210,13 @@ const errors = check(source);
202
210
  ```typescript
203
211
  type CompileOptions = {
204
212
  skipSemanticAnalysis?: boolean;
205
- lowerSystemValues?: boolean;
206
213
  };
207
214
  ```
208
215
 
216
+ Legacy compatibility options may still exist for older call sites, but they are
217
+ not current v5 integration seams. Runtime facts are represented through
218
+ `$runtime.*` and explicit Core `Context`, not compiler-lowered system values.
219
+
209
220
  ---
210
221
 
211
222
  ## Documentation
@@ -216,7 +227,7 @@ type CompileOptions = {
216
227
  | [MEL Syntax](../../docs/mel/SYNTAX.md) | Grammar and syntax |
217
228
  | [MEL Examples](../../docs/mel/EXAMPLES.md) | Example library |
218
229
  | [MEL Error Guide](../../docs/mel/ERROR-GUIDE.md) | Error codes and fixes |
219
- | [Compiler Spec](docs/SPEC-v1.1.0.md) | Current full compiler and MEL spec |
230
+ | [Compiler Spec](docs/SPEC-v1.2.0.md) | Current full compiler and MEL spec |
220
231
  | [Compiler FDR](docs/FDR-v0.5.0.md) | Design rationale |
221
232
  | [Compiler Compliance Suite](docs/compiler-SPEC-compilance-test-suite.md) | CCTS structure, rule modes, and execution guide |
222
233
 
@@ -6,6 +6,7 @@ export type TypeEnv = Map<string, TypeExprNode>;
6
6
  export type ComparableSurfaceClass = "primitive" | "nonprimitive" | "unknown";
7
7
  export interface DomainTypeSymbols {
8
8
  stateTypes: Map<string, TypeExprNode>;
9
+ contextTypes: Map<string, TypeExprNode>;
9
10
  computedDecls: Map<string, ComputedNode>;
10
11
  typeDefs: Map<string, TypeDeclNode>;
11
12
  computedTypeCache: Map<string, TypeExprNode | null>;
@@ -31,6 +31,7 @@ export declare class SemanticValidator {
31
31
  * v0.3.3: Validate state field - check for anonymous object types (W012)
32
32
  */
33
33
  private validateStateField;
34
+ private validateContext;
34
35
  private validateStateInitializer;
35
36
  /**
36
37
  * v0.3.3: Check if a type expression contains anonymous object types
@@ -39,13 +40,13 @@ export declare class SemanticValidator {
39
40
  private checkAnonymousObjectType;
40
41
  private validateAction;
41
42
  /**
42
- * v0.3.3: Validate available expression is pure (E005)
43
- * No $system.*, no effects, no $input.*
43
+ * v0.3.3: Validate available expression is pure (E005).
44
+ * No dollar namespace reads or action parameters.
44
45
  */
45
46
  private validateAvailableExpr;
46
47
  /**
47
- * v0.9.0: Validate dispatchable expression is pure (E047)
48
- * Allows state/computed/action params, but forbids direct $input.*, $meta.*, and $system.*.
48
+ * v0.9.0: Validate dispatchable expression is pure (E047).
49
+ * Allows state/computed/action params, but forbids direct dollar namespace reads.
49
50
  */
50
51
  private validateDispatchableExpr;
51
52
  private validateGuardedStmt;
@@ -58,6 +59,8 @@ export declare class SemanticValidator {
58
59
  private validateStop;
59
60
  private validateCondition;
60
61
  private validateExpr;
62
+ private validateDollarIdent;
63
+ private validateContextPath;
61
64
  private validateFunctionCall;
62
65
  private validatePrimitiveEquality;
63
66
  private inferType;
@@ -69,7 +72,6 @@ export declare class SemanticValidator {
69
72
  private validateMatchCall;
70
73
  private validateArgSelectionCall;
71
74
  private error;
72
- private warn;
73
75
  }
74
76
  /**
75
77
  * Validate a MEL program semantically
@@ -4,11 +4,9 @@ import type { MelIRPatchPath } from "../lowering/lower-runtime-patch.js";
4
4
  import type { GuardedStmtNode, InnerStmtNode, PatchStmtNode } from "../parser/ast.js";
5
5
  import { toMelExpr } from "./compile-mel-patch-expr.js";
6
6
  export interface PatchCollectContext {
7
- actionName: string;
8
- onceCounter: number;
9
- onceIntentCounter: number;
10
- whenCounter: number;
7
+ readonly actionName: string;
11
8
  }
9
+ type AllowedSysPrefix = "input" | "runtime" | "context";
12
10
  export type ConditionedPatchStatement = {
13
11
  patch: PatchStmtNode;
14
12
  condition?: MelExprNode;
@@ -19,11 +17,11 @@ export interface PatchCollectorDeps {
19
17
  }
20
18
  export declare class PatchStatementCollector {
21
19
  private readonly deps;
22
- private readonly conditionComposer;
23
20
  private readonly exprValidator;
24
- constructor(deps: PatchCollectorDeps);
21
+ constructor(deps: PatchCollectorDeps, allowSysPrefixes?: readonly AllowedSysPrefix[]);
25
22
  collect(stmts: GuardedStmtNode[] | InnerStmtNode[], errors: Diagnostic[], context: PatchCollectContext, parentCondition: MelExprNode | undefined): ConditionedPatchStatement[];
26
23
  private collectPatchStatements;
24
+ private pushUnsupportedControlError;
27
25
  }
28
26
  export declare function compilePatchStmtToMelRuntime(patchStatement: ConditionedPatchStatement): {
29
27
  op: "set" | "unset" | "merge";
@@ -31,3 +29,4 @@ export declare function compilePatchStmtToMelRuntime(patchStatement: Conditioned
31
29
  value?: MelExprNode;
32
30
  condition?: MelExprNode;
33
31
  };
32
+ export {};
@@ -81,11 +81,11 @@ export interface CompileMelPatchOptions {
81
81
  */
82
82
  actionName: string;
83
83
  /**
84
- * Allowed system path prefixes.
85
- * Default: ["meta", "input"] (system is forbidden per §20.3).
84
+ * Allowed dollar namespace prefixes.
85
+ * Default: ["input", "runtime", "context"].
86
86
  */
87
87
  allowSysPaths?: {
88
- prefixes: ("meta" | "input")[];
88
+ prefixes: ("input" | "runtime" | "context")[];
89
89
  };
90
90
  /**
91
91
  * Function table version.
@@ -140,7 +140,7 @@ export declare function compileMelModule(melText: string, options?: CompileMelMo
140
140
  * by evaluateRuntimePatches() to get concrete values.
141
141
  *
142
142
  * Constraints:
143
- * - §20.3: $system.* is forbidden in Translator path
143
+ * - ADR-027: `$system.*` and `$meta.*` are retired in current v5 MEL.
144
144
  *
145
145
  * @param melText - MEL patch source text
146
146
  * @param options - Compilation options
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @see SPEC v0.4.0 §19
7
7
  */
8
- export type { Annotation, AnnotationIndex, CompileTrace, CompileMelDomainOptions, CompileMelDomainResult, CompileMelModuleOptions, CompileMelModuleResult, CompileMelPatchOptions, CompileMelPatchResult, DomainModule, JsonLiteral, LocalTargetKey, SourceMapEmissionContext, SourceMapEntry, SourceMapIndex, SourceMapPath, SourcePoint, SourceSpan, } from "./compile-mel.js";
8
+ export type { Annotation, AnnotationIndex, CompileTrace, CompileMelDomainOptions, CompileMelDomainResult, CompileMelModuleOptions, CompileMelModuleResult, DomainModule, JsonLiteral, LocalTargetKey, SourceMapEmissionContext, SourceMapEntry, SourceMapIndex, SourceMapPath, SourcePoint, SourceSpan, } from "./compile-mel.js";
9
9
  export type { CompileFragmentInContextOptions, MelEditAddActionOp, MelEditAddAvailableOp, MelEditAddComputedOp, MelEditAddDispatchableOp, MelEditAddStateFieldOp, MelEditAddTypeOp, MelEditOp, MelEditRemoveDeclarationOp, MelEditRenameDeclarationOp, MelEditReplaceActionBodyOp, MelEditReplaceAvailableOp, MelEditReplaceComputedExprOp, MelEditReplaceDispatchableOp, MelEditReplaceStateDefaultOp, MelEditReplaceTypeFieldOp, MelEditResult, MelParamSource, MelTextEdit, SchemaDiff, SchemaModifiedTarget, } from "./compile-fragment-in-context.js";
10
- export { compileMelDomain, compileMelModule, compileMelPatch } from "./compile-mel.js";
10
+ export { compileMelDomain, compileMelModule } from "./compile-mel.js";
11
11
  export { compileFragmentInContext } from "./compile-fragment-in-context.js";