@manifesto-ai/compiler 1.0.0 → 1.4.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/LICENSE +21 -0
- package/README.md +52 -250
- package/dist/analyzer/index.d.ts +6 -0
- package/dist/analyzer/index.d.ts.map +1 -0
- package/dist/analyzer/index.js +6 -0
- package/dist/analyzer/index.js.map +1 -0
- package/dist/analyzer/scope.d.ts +77 -0
- package/dist/analyzer/scope.d.ts.map +1 -0
- package/dist/analyzer/scope.js +296 -0
- package/dist/analyzer/scope.js.map +1 -0
- package/dist/analyzer/validator.d.ts +60 -0
- package/dist/analyzer/validator.d.ts.map +1 -0
- package/dist/analyzer/validator.js +439 -0
- package/dist/analyzer/validator.js.map +1 -0
- package/dist/api/compile-mel.d.ts +126 -0
- package/dist/api/compile-mel.d.ts.map +1 -0
- package/dist/api/compile-mel.js +129 -0
- package/dist/api/compile-mel.js.map +1 -0
- package/dist/api/index.d.ts +9 -2
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +8 -2
- package/dist/api/index.js.map +1 -1
- package/dist/diagnostics/codes.d.ts +25 -0
- package/dist/diagnostics/codes.d.ts.map +1 -0
- package/dist/diagnostics/codes.js +154 -0
- package/dist/diagnostics/codes.js.map +1 -0
- package/dist/diagnostics/index.d.ts +6 -0
- package/dist/diagnostics/index.d.ts.map +1 -0
- package/dist/diagnostics/index.js +6 -0
- package/dist/diagnostics/index.js.map +1 -0
- package/dist/diagnostics/types.d.ts +67 -0
- package/dist/diagnostics/types.d.ts.map +1 -0
- package/dist/diagnostics/types.js +58 -0
- package/dist/diagnostics/types.js.map +1 -0
- package/dist/evaluation/context.d.ts +91 -0
- package/dist/evaluation/context.d.ts.map +1 -0
- package/dist/evaluation/context.js +59 -0
- package/dist/evaluation/context.js.map +1 -0
- package/dist/evaluation/evaluate-expr.d.ts +24 -0
- package/dist/evaluation/evaluate-expr.d.ts.map +1 -0
- package/dist/evaluation/evaluate-expr.js +563 -0
- package/dist/evaluation/evaluate-expr.js.map +1 -0
- package/dist/evaluation/evaluate-patch.d.ts +123 -0
- package/dist/evaluation/evaluate-patch.d.ts.map +1 -0
- package/dist/evaluation/evaluate-patch.js +202 -0
- package/dist/evaluation/evaluate-patch.js.map +1 -0
- package/dist/evaluation/evaluate-runtime-patch.d.ts +86 -0
- package/dist/evaluation/evaluate-runtime-patch.d.ts.map +1 -0
- package/dist/evaluation/evaluate-runtime-patch.js +153 -0
- package/dist/evaluation/evaluate-runtime-patch.js.map +1 -0
- package/dist/evaluation/index.d.ts +15 -0
- package/dist/evaluation/index.d.ts.map +1 -0
- package/dist/evaluation/index.js +13 -0
- package/dist/evaluation/index.js.map +1 -0
- package/dist/generator/index.d.ts +7 -0
- package/dist/generator/index.d.ts.map +1 -0
- package/dist/generator/index.js +7 -0
- package/dist/generator/index.js.map +1 -0
- package/dist/generator/ir.d.ts +344 -0
- package/dist/generator/ir.d.ts.map +1 -0
- package/dist/generator/ir.js +709 -0
- package/dist/generator/ir.js.map +1 -0
- package/dist/generator/lowering.d.ts +11 -0
- package/dist/generator/lowering.d.ts.map +1 -0
- package/dist/generator/lowering.js +362 -0
- package/dist/generator/lowering.js.map +1 -0
- package/dist/generator/normalizer.d.ts +16 -0
- package/dist/generator/normalizer.d.ts.map +1 -0
- package/dist/generator/normalizer.js +181 -0
- package/dist/generator/normalizer.js.map +1 -0
- package/dist/index.d.ts +11 -59
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -64
- package/dist/index.js.map +1 -1
- package/dist/lexer/index.d.ts +7 -0
- package/dist/lexer/index.d.ts.map +1 -0
- package/dist/lexer/index.js +7 -0
- package/dist/lexer/index.js.map +1 -0
- package/dist/lexer/lexer.d.ts +59 -0
- package/dist/lexer/lexer.d.ts.map +1 -0
- package/dist/lexer/lexer.js +433 -0
- package/dist/lexer/lexer.js.map +1 -0
- package/dist/lexer/source-location.d.ts +41 -0
- package/dist/lexer/source-location.d.ts.map +1 -0
- package/dist/lexer/source-location.js +33 -0
- package/dist/lexer/source-location.js.map +1 -0
- package/dist/lexer/tokens.d.ts +47 -0
- package/dist/lexer/tokens.d.ts.map +1 -0
- package/dist/lexer/tokens.js +73 -0
- package/dist/lexer/tokens.js.map +1 -0
- package/dist/lowering/context.d.ts +96 -0
- package/dist/lowering/context.d.ts.map +1 -0
- package/dist/lowering/context.js +42 -0
- package/dist/lowering/context.js.map +1 -0
- package/dist/lowering/errors.d.ts +84 -0
- package/dist/lowering/errors.d.ts.map +1 -0
- package/dist/lowering/errors.js +81 -0
- package/dist/lowering/errors.js.map +1 -0
- package/dist/lowering/index.d.ts +20 -0
- package/dist/lowering/index.d.ts.map +1 -0
- package/dist/lowering/index.js +13 -0
- package/dist/lowering/index.js.map +1 -0
- package/dist/lowering/lower-expr.d.ts +76 -0
- package/dist/lowering/lower-expr.d.ts.map +1 -0
- package/dist/lowering/lower-expr.js +351 -0
- package/dist/lowering/lower-expr.js.map +1 -0
- package/dist/lowering/lower-patch.d.ts +231 -0
- package/dist/lowering/lower-patch.d.ts.map +1 -0
- package/dist/lowering/lower-patch.js +146 -0
- package/dist/lowering/lower-patch.js.map +1 -0
- package/dist/lowering/lower-runtime-patch.d.ts +100 -0
- package/dist/lowering/lower-runtime-patch.d.ts.map +1 -0
- package/dist/lowering/lower-runtime-patch.js +49 -0
- package/dist/lowering/lower-runtime-patch.js.map +1 -0
- package/dist/parser/ast.d.ts +344 -0
- package/dist/parser/ast.d.ts.map +1 -0
- package/dist/parser/ast.js +24 -0
- package/dist/parser/ast.js.map +1 -0
- package/dist/parser/index.d.ts +7 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +7 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/parser.d.ts +92 -0
- package/dist/parser/parser.d.ts.map +1 -0
- package/dist/parser/parser.js +892 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/precedence.d.ts +44 -0
- package/dist/parser/precedence.d.ts.map +1 -0
- package/dist/parser/precedence.js +69 -0
- package/dist/parser/precedence.js.map +1 -0
- package/dist/renderer/expr-node.d.ts +168 -0
- package/dist/renderer/expr-node.d.ts.map +1 -0
- package/dist/renderer/expr-node.js +216 -0
- package/dist/renderer/expr-node.js.map +1 -0
- package/dist/renderer/fragment.d.ts +84 -0
- package/dist/renderer/fragment.d.ts.map +1 -0
- package/dist/renderer/fragment.js +172 -0
- package/dist/renderer/fragment.js.map +1 -0
- package/dist/renderer/index.d.ts +23 -0
- package/dist/renderer/index.d.ts.map +1 -0
- package/dist/renderer/index.js +27 -0
- package/dist/renderer/index.js.map +1 -0
- package/dist/renderer/patch-op.d.ts +82 -0
- package/dist/renderer/patch-op.d.ts.map +1 -0
- package/dist/renderer/patch-op.js +203 -0
- package/dist/renderer/patch-op.js.map +1 -0
- package/dist/renderer/type-expr.d.ts +61 -0
- package/dist/renderer/type-expr.d.ts.map +1 -0
- package/dist/renderer/type-expr.js +131 -0
- package/dist/renderer/type-expr.js.map +1 -0
- package/package.json +21 -24
- package/dist/__tests__/domain.test.d.ts +0 -2
- package/dist/__tests__/domain.test.d.ts.map +0 -1
- package/dist/__tests__/domain.test.js +0 -56
- package/dist/__tests__/domain.test.js.map +0 -1
- package/dist/__tests__/effects.test.d.ts +0 -2
- package/dist/__tests__/effects.test.d.ts.map +0 -1
- package/dist/__tests__/effects.test.js +0 -145
- package/dist/__tests__/effects.test.js.map +0 -1
- package/dist/__tests__/helpers/mock-adapter.d.ts +0 -47
- package/dist/__tests__/helpers/mock-adapter.d.ts.map +0 -1
- package/dist/__tests__/helpers/mock-adapter.js +0 -135
- package/dist/__tests__/helpers/mock-adapter.js.map +0 -1
- package/dist/__tests__/integration.test.d.ts +0 -2
- package/dist/__tests__/integration.test.d.ts.map +0 -1
- package/dist/__tests__/integration.test.js +0 -220
- package/dist/__tests__/integration.test.js.map +0 -1
- package/dist/__tests__/parser.test.d.ts +0 -2
- package/dist/__tests__/parser.test.d.ts.map +0 -1
- package/dist/__tests__/parser.test.js +0 -118
- package/dist/__tests__/parser.test.js.map +0 -1
- package/dist/__tests__/telemetry.test.d.ts +0 -2
- package/dist/__tests__/telemetry.test.d.ts.map +0 -1
- package/dist/__tests__/telemetry.test.js +0 -207
- package/dist/__tests__/telemetry.test.js.map +0 -1
- package/dist/api/compiler.d.ts +0 -86
- package/dist/api/compiler.d.ts.map +0 -1
- package/dist/api/compiler.js +0 -302
- package/dist/api/compiler.js.map +0 -1
- package/dist/api/factory.d.ts +0 -27
- package/dist/api/factory.d.ts.map +0 -1
- package/dist/api/factory.js +0 -60
- package/dist/api/factory.js.map +0 -1
- package/dist/cli/App.d.ts +0 -10
- package/dist/cli/App.d.ts.map +0 -1
- package/dist/cli/App.js +0 -75
- package/dist/cli/App.js.map +0 -1
- package/dist/cli/components/Error.d.ts +0 -10
- package/dist/cli/components/Error.d.ts.map +0 -1
- package/dist/cli/components/Error.js +0 -21
- package/dist/cli/components/Error.js.map +0 -1
- package/dist/cli/components/Header.d.ts +0 -10
- package/dist/cli/components/Header.d.ts.map +0 -1
- package/dist/cli/components/Header.js +0 -11
- package/dist/cli/components/Header.js.map +0 -1
- package/dist/cli/components/Metrics.d.ts +0 -10
- package/dist/cli/components/Metrics.d.ts.map +0 -1
- package/dist/cli/components/Metrics.js +0 -29
- package/dist/cli/components/Metrics.js.map +0 -1
- package/dist/cli/components/Progress.d.ts +0 -10
- package/dist/cli/components/Progress.d.ts.map +0 -1
- package/dist/cli/components/Progress.js +0 -37
- package/dist/cli/components/Progress.js.map +0 -1
- package/dist/cli/components/Resolution.d.ts +0 -11
- package/dist/cli/components/Resolution.d.ts.map +0 -1
- package/dist/cli/components/Resolution.js +0 -26
- package/dist/cli/components/Resolution.js.map +0 -1
- package/dist/cli/components/Result.d.ts +0 -10
- package/dist/cli/components/Result.d.ts.map +0 -1
- package/dist/cli/components/Result.js +0 -38
- package/dist/cli/components/Result.js.map +0 -1
- package/dist/cli/components/StatusBar.d.ts +0 -10
- package/dist/cli/components/StatusBar.d.ts.map +0 -1
- package/dist/cli/components/StatusBar.js +0 -21
- package/dist/cli/components/StatusBar.js.map +0 -1
- package/dist/cli/hooks/useCompiler.d.ts +0 -22
- package/dist/cli/hooks/useCompiler.d.ts.map +0 -1
- package/dist/cli/hooks/useCompiler.js +0 -214
- package/dist/cli/hooks/useCompiler.js.map +0 -1
- package/dist/cli/index.d.ts +0 -13
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js +0 -178
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/types.d.ts +0 -96
- package/dist/cli/types.d.ts.map +0 -1
- package/dist/cli/types.js +0 -26
- package/dist/cli/types.js.map +0 -1
- package/dist/domain/domain.d.ts +0 -76
- package/dist/domain/domain.d.ts.map +0 -1
- package/dist/domain/domain.js +0 -251
- package/dist/domain/domain.js.map +0 -1
- package/dist/domain/index.d.ts +0 -4
- package/dist/domain/index.d.ts.map +0 -1
- package/dist/domain/index.js +0 -4
- package/dist/domain/index.js.map +0 -1
- package/dist/domain/schema.d.ts +0 -198
- package/dist/domain/schema.d.ts.map +0 -1
- package/dist/domain/schema.js +0 -131
- package/dist/domain/schema.js.map +0 -1
- package/dist/domain/types.d.ts +0 -360
- package/dist/domain/types.d.ts.map +0 -1
- package/dist/domain/types.js +0 -2
- package/dist/domain/types.js.map +0 -1
- package/dist/effects/builder/index.d.ts +0 -2
- package/dist/effects/builder/index.d.ts.map +0 -1
- package/dist/effects/builder/index.js +0 -2
- package/dist/effects/builder/index.js.map +0 -1
- package/dist/effects/builder/validate-handler.d.ts +0 -27
- package/dist/effects/builder/validate-handler.d.ts.map +0 -1
- package/dist/effects/builder/validate-handler.js +0 -153
- package/dist/effects/builder/validate-handler.js.map +0 -1
- package/dist/effects/index.d.ts +0 -3
- package/dist/effects/index.d.ts.map +0 -1
- package/dist/effects/index.js +0 -5
- package/dist/effects/index.js.map +0 -1
- package/dist/effects/llm/adapter.d.ts +0 -123
- package/dist/effects/llm/adapter.d.ts.map +0 -1
- package/dist/effects/llm/adapter.js +0 -13
- package/dist/effects/llm/adapter.js.map +0 -1
- package/dist/effects/llm/anthropic-adapter.d.ts +0 -65
- package/dist/effects/llm/anthropic-adapter.d.ts.map +0 -1
- package/dist/effects/llm/anthropic-adapter.js +0 -178
- package/dist/effects/llm/anthropic-adapter.js.map +0 -1
- package/dist/effects/llm/handlers.d.ts +0 -44
- package/dist/effects/llm/handlers.d.ts.map +0 -1
- package/dist/effects/llm/handlers.js +0 -127
- package/dist/effects/llm/handlers.js.map +0 -1
- package/dist/effects/llm/index.d.ts +0 -7
- package/dist/effects/llm/index.d.ts.map +0 -1
- package/dist/effects/llm/index.js +0 -10
- package/dist/effects/llm/index.js.map +0 -1
- package/dist/effects/llm/openai-adapter.d.ts +0 -59
- package/dist/effects/llm/openai-adapter.d.ts.map +0 -1
- package/dist/effects/llm/openai-adapter.js +0 -206
- package/dist/effects/llm/openai-adapter.js.map +0 -1
- package/dist/effects/llm/parser.d.ts +0 -63
- package/dist/effects/llm/parser.d.ts.map +0 -1
- package/dist/effects/llm/parser.js +0 -177
- package/dist/effects/llm/parser.js.map +0 -1
- package/dist/effects/llm/prompts/index.d.ts +0 -4
- package/dist/effects/llm/prompts/index.d.ts.map +0 -1
- package/dist/effects/llm/prompts/index.js +0 -4
- package/dist/effects/llm/prompts/index.js.map +0 -1
- package/dist/effects/llm/prompts/normalize.d.ts +0 -19
- package/dist/effects/llm/prompts/normalize.d.ts.map +0 -1
- package/dist/effects/llm/prompts/normalize.js +0 -98
- package/dist/effects/llm/prompts/normalize.js.map +0 -1
- package/dist/effects/llm/prompts/propose.d.ts +0 -21
- package/dist/effects/llm/prompts/propose.d.ts.map +0 -1
- package/dist/effects/llm/prompts/propose.js +0 -326
- package/dist/effects/llm/prompts/propose.js.map +0 -1
- package/dist/effects/llm/prompts/segment.d.ts +0 -16
- package/dist/effects/llm/prompts/segment.d.ts.map +0 -1
- package/dist/effects/llm/prompts/segment.js +0 -57
- package/dist/effects/llm/prompts/segment.js.map +0 -1
- package/dist/effects/types.d.ts +0 -10
- package/dist/effects/types.d.ts.map +0 -1
- package/dist/effects/types.js +0 -2
- package/dist/effects/types.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Manifesto AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,310 +1,112 @@
|
|
|
1
1
|
# @manifesto-ai/compiler
|
|
2
2
|
|
|
3
|
-
> **
|
|
3
|
+
> **Status:** Deprecated (v2 focuses on Core/Host/World/App). This package is legacy and may be removed.
|
|
4
4
|
|
|
5
|
-
---
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
> **Compiler** translates MEL (Manifesto Expression Language) into DomainSchema for Manifesto Core.
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
---
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
## What is the Compiler?
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
The compiler is the MEL frontend for Manifesto. It tokenizes, parses, validates, and lowers MEL source into a DomainSchema that Core can evaluate deterministically.
|
|
14
13
|
|
|
15
14
|
```
|
|
16
|
-
|
|
17
|
-
│
|
|
18
|
-
LLM-powered pipeline (segment → normalize → propose)
|
|
19
|
-
Builder validation as authority
|
|
15
|
+
MEL source -> Compiler -> DomainSchema -> Core
|
|
20
16
|
```
|
|
21
17
|
|
|
22
18
|
---
|
|
23
19
|
|
|
24
|
-
## What Compiler Does
|
|
20
|
+
## What the Compiler Does
|
|
25
21
|
|
|
26
22
|
| Responsibility | Description |
|
|
27
|
-
|
|
28
|
-
| Parse
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
| Handle ambiguity | Request user resolution for unclear requirements |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| Parse MEL | Tokenize and parse MEL into an AST |
|
|
25
|
+
| Validate | Scope and semantic checks aligned to MEL v0.3.3 |
|
|
26
|
+
| Generate IR | Produce DomainSchema for Core |
|
|
27
|
+
| Lower system values | Optional lowering of $system.* into explicit effects |
|
|
33
28
|
|
|
34
29
|
---
|
|
35
30
|
|
|
36
|
-
## What Compiler Does NOT Do
|
|
31
|
+
## What the Compiler Does NOT Do
|
|
37
32
|
|
|
38
33
|
| NOT Responsible For | Who Is |
|
|
39
|
-
|
|
40
|
-
| Execute
|
|
41
|
-
|
|
|
42
|
-
|
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| Execute effects | Host |
|
|
36
|
+
| Apply patches | Core |
|
|
37
|
+
| Govern authority | World |
|
|
38
|
+
| Bind UI | Bridge / React |
|
|
43
39
|
|
|
44
40
|
---
|
|
45
41
|
|
|
46
42
|
## Installation
|
|
47
43
|
|
|
48
44
|
```bash
|
|
49
|
-
npm install
|
|
45
|
+
npm install -D @manifesto-ai/compiler
|
|
50
46
|
# or
|
|
51
|
-
pnpm add
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### LLM Provider (choose one)
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
npm install @anthropic-ai/sdk # For Anthropic
|
|
58
|
-
# or
|
|
59
|
-
npm install openai # For OpenAI
|
|
47
|
+
pnpm add -D @manifesto-ai/compiler
|
|
60
48
|
```
|
|
61
49
|
|
|
62
50
|
---
|
|
63
51
|
|
|
64
|
-
## Quick Example
|
|
65
|
-
|
|
66
|
-
### Using Anthropic (Built-in)
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
import { createCompiler } from "@manifesto-ai/compiler";
|
|
70
|
-
|
|
71
|
-
const compiler = createCompiler({
|
|
72
|
-
anthropic: { apiKey: process.env.ANTHROPIC_API_KEY },
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// Subscribe to state changes
|
|
76
|
-
compiler.subscribe((state) => {
|
|
77
|
-
console.log("Status:", state.status);
|
|
78
|
-
|
|
79
|
-
if (state.status === "success") {
|
|
80
|
-
console.log("Generated schema:", state.result);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (state.status === "discarded") {
|
|
84
|
-
console.log("Discarded:", state.discardReason);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// Start compilation
|
|
89
|
-
await compiler.start({
|
|
90
|
-
text: `
|
|
91
|
-
Track a list of todos with title and completion status.
|
|
92
|
-
Users can add new todos, toggle completion, and delete todos.
|
|
93
|
-
Show a count of remaining incomplete todos.
|
|
94
|
-
`,
|
|
95
|
-
context: {
|
|
96
|
-
domainName: "todo",
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### Using OpenAI
|
|
102
|
-
|
|
103
|
-
```typescript
|
|
104
|
-
import { createCompiler, createOpenAIAdapter } from "@manifesto-ai/compiler";
|
|
105
|
-
import OpenAI from "openai";
|
|
106
|
-
|
|
107
|
-
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
|
|
108
|
-
const adapter = createOpenAIAdapter({ client: openai, model: "gpt-4" });
|
|
109
|
-
|
|
110
|
-
const compiler = createCompiler({
|
|
111
|
-
llmAdapter: adapter,
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
await compiler.start({ text: "Track user profiles with name and email..." });
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
> See [GUIDE.md](../../docs/packages/compiler/GUIDE.md) for the full tutorial.
|
|
118
|
-
|
|
119
|
-
---
|
|
120
|
-
|
|
121
52
|
## CLI Usage
|
|
122
53
|
|
|
123
|
-
The compiler includes an interactive CLI tool:
|
|
124
|
-
|
|
125
54
|
```bash
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
# Output to file
|
|
133
|
-
manifesto-compile "Track todos" -o schema.json
|
|
134
|
-
|
|
135
|
-
# Use Anthropic provider
|
|
136
|
-
manifesto-compile --provider anthropic "Create a counter"
|
|
137
|
-
|
|
138
|
-
# Show progress
|
|
139
|
-
manifesto-compile --verbose "Complex requirements..."
|
|
55
|
+
pnpm exec mel check path/to/domain.mel
|
|
56
|
+
pnpm exec mel compile path/to/domain.mel --pretty
|
|
57
|
+
pnpm exec mel compile path/to/domain.mel --stdout
|
|
58
|
+
pnpm exec mel parse path/to/domain.mel
|
|
59
|
+
pnpm exec mel tokens path/to/domain.mel
|
|
140
60
|
```
|
|
141
61
|
|
|
142
|
-
### CLI Options
|
|
143
|
-
|
|
144
|
-
| Option | Description |
|
|
145
|
-
|--------|-------------|
|
|
146
|
-
| `--provider` | LLM provider: `openai` (default) or `anthropic` |
|
|
147
|
-
| `--model` | Model name |
|
|
148
|
-
| `--file` | Read input from file |
|
|
149
|
-
| `--stdin` | Read input from stdin |
|
|
150
|
-
| `-o, --output` | Write result to file |
|
|
151
|
-
| `--verbose` | Show phase progress |
|
|
152
|
-
| `--full` | Show full metrics |
|
|
153
|
-
|
|
154
|
-
> See [GUIDE.md](../../docs/packages/compiler/GUIDE.md#cli-usage) for detailed CLI documentation.
|
|
155
|
-
|
|
156
62
|
---
|
|
157
63
|
|
|
158
|
-
##
|
|
159
|
-
|
|
160
|
-
### Main Exports
|
|
64
|
+
## Node API
|
|
161
65
|
|
|
162
66
|
```typescript
|
|
163
|
-
|
|
164
|
-
function createCompiler(options: CompilerOptions): Compiler;
|
|
165
|
-
|
|
166
|
-
// Compiler interface
|
|
167
|
-
interface Compiler {
|
|
168
|
-
start(input: CompileInput): Promise<void>;
|
|
169
|
-
subscribe(callback: (state: CompilerState) => void): Unsubscribe;
|
|
170
|
-
requestResolution(optionId: string): Promise<void>;
|
|
171
|
-
getState(): CompilerState;
|
|
172
|
-
}
|
|
67
|
+
import { compile, check } from "@manifesto-ai/compiler";
|
|
173
68
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
| "idle"
|
|
181
|
-
| "segmenting"
|
|
182
|
-
| "normalizing"
|
|
183
|
-
| "proposing"
|
|
184
|
-
| "validating"
|
|
185
|
-
| "awaiting_resolution"
|
|
186
|
-
| "success"
|
|
187
|
-
| "discarded";
|
|
188
|
-
|
|
189
|
-
type CompilerState = {
|
|
190
|
-
status: CompilerStatus;
|
|
191
|
-
segments?: string[];
|
|
192
|
-
intents?: NormalizedIntent[];
|
|
193
|
-
draft?: DomainSchema;
|
|
194
|
-
result?: DomainSchema;
|
|
195
|
-
diagnostics?: CompilerDiagnostics;
|
|
196
|
-
resolutionOptions?: ResolutionOption[];
|
|
197
|
-
discardReason?: DiscardReason;
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
interface LLMAdapter {
|
|
201
|
-
segment(input: SegmentInput): Promise<LLMResult<SegmentResult>>;
|
|
202
|
-
normalize(input: NormalizeInput): Promise<LLMResult<NormalizeResult>>;
|
|
203
|
-
propose(input: ProposeInput): Promise<LLMResult<ProposeResult>>;
|
|
69
|
+
const source = `
|
|
70
|
+
domain Counter {
|
|
71
|
+
state { count: number = 0 }
|
|
72
|
+
action increment() {
|
|
73
|
+
when true { patch count = add(count, 1) }
|
|
74
|
+
}
|
|
204
75
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
> See [SPEC.md](../../docs/packages/compiler/SPEC.md) for complete API reference.
|
|
208
|
-
|
|
209
|
-
---
|
|
210
|
-
|
|
211
|
-
## Core Concepts
|
|
212
|
-
|
|
213
|
-
### Pipeline Stages
|
|
214
|
-
|
|
215
|
-
```
|
|
216
|
-
idle → segmenting → normalizing → proposing → validating → success
|
|
217
|
-
↓ ↓
|
|
218
|
-
awaiting_resolution discarded
|
|
219
|
-
```
|
|
76
|
+
`;
|
|
220
77
|
|
|
221
|
-
|
|
222
|
-
2. **Normalizing**: Convert segments to structured NormalizedIntents
|
|
223
|
-
3. **Proposing**: Generate DomainSchema draft via LLM
|
|
224
|
-
4. **Validating**: Validate draft using Builder (the "judge")
|
|
225
|
-
5. **Resolution**: Handle ambiguities (user choice or auto-discard)
|
|
226
|
-
6. **Success/Discarded**: Terminal states
|
|
78
|
+
const result = compile(source, { lowerSystemValues: true });
|
|
227
79
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
80
|
+
if (!result.success) {
|
|
81
|
+
console.error(result.errors);
|
|
82
|
+
} else {
|
|
83
|
+
console.log(result.schema);
|
|
84
|
+
}
|
|
231
85
|
|
|
86
|
+
const errors = check(source);
|
|
232
87
|
```
|
|
233
|
-
LLM (untrusted proposer) → Draft Schema
|
|
234
|
-
↓
|
|
235
|
-
Builder (judge) → Validation
|
|
236
|
-
↓
|
|
237
|
-
Valid? → Success
|
|
238
|
-
Invalid? → Retry or Discard
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
### Custom LLM Adapters
|
|
242
88
|
|
|
243
|
-
|
|
89
|
+
### Compile Options
|
|
244
90
|
|
|
245
91
|
```typescript
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
return { ok: true, data: { segments: [...] } };
|
|
250
|
-
},
|
|
251
|
-
async normalize({ segments, schema, context }) {
|
|
252
|
-
return { ok: true, data: { intents: [...] } };
|
|
253
|
-
},
|
|
254
|
-
async propose({ schema, intents, history, context }) {
|
|
255
|
-
return { ok: true, data: { draft: {...} } };
|
|
256
|
-
},
|
|
92
|
+
type CompileOptions = {
|
|
93
|
+
skipSemanticAnalysis?: boolean;
|
|
94
|
+
lowerSystemValues?: boolean;
|
|
257
95
|
};
|
|
258
96
|
```
|
|
259
97
|
|
|
260
98
|
---
|
|
261
99
|
|
|
262
|
-
## Relationship with Other Packages
|
|
263
|
-
|
|
264
|
-
```
|
|
265
|
-
┌─────────────┐
|
|
266
|
-
│ Your │ ← Uses Compiler for NL→Schema
|
|
267
|
-
│ Tool │
|
|
268
|
-
└──────┬──────┘
|
|
269
|
-
│
|
|
270
|
-
▼
|
|
271
|
-
┌─────────────┐
|
|
272
|
-
│ COMPILER │
|
|
273
|
-
└──────┬──────┘
|
|
274
|
-
│
|
|
275
|
-
▼
|
|
276
|
-
┌─────────────┐
|
|
277
|
-
│ Builder │ ← Validates generated schemas
|
|
278
|
-
└─────────────┘
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
| Relationship | Package | How |
|
|
282
|
-
|--------------|---------|-----|
|
|
283
|
-
| Depends on | `@manifesto-ai/builder` | Validates generated schemas |
|
|
284
|
-
| Depends on | `@manifesto-ai/core` | Uses Core types |
|
|
285
|
-
| Used by | Developer tools | For AI-assisted domain creation |
|
|
286
|
-
|
|
287
|
-
---
|
|
288
|
-
|
|
289
|
-
## When to Use Compiler
|
|
290
|
-
|
|
291
|
-
Use Compiler when:
|
|
292
|
-
- Building AI-assisted domain definition tools
|
|
293
|
-
- Creating no-code/low-code domain builders
|
|
294
|
-
- Prototyping domains from natural language specs
|
|
295
|
-
- Building developer productivity tools
|
|
296
|
-
|
|
297
|
-
For manual domain definition, use [`@manifesto-ai/builder`](../builder/) directly.
|
|
298
|
-
|
|
299
|
-
---
|
|
300
|
-
|
|
301
100
|
## Documentation
|
|
302
101
|
|
|
303
102
|
| Document | Purpose |
|
|
304
|
-
|
|
305
|
-
| [
|
|
306
|
-
| [
|
|
307
|
-
| [
|
|
103
|
+
| --- | --- |
|
|
104
|
+
| [MEL Overview](../../docs/mel/) | What MEL is and how to use it |
|
|
105
|
+
| [MEL Syntax](../../docs/mel/SYNTAX.md) | Grammar and syntax |
|
|
106
|
+
| [MEL Examples](../../docs/mel/EXAMPLES.md) | Example library |
|
|
107
|
+
| [MEL Error Guide](../../docs/mel/ERROR-GUIDE.md) | Error codes and fixes |
|
|
108
|
+
| [Compiler Spec](docs/SPEC.md) | Full compiler and MEL spec |
|
|
109
|
+
| [Compiler FDR](docs/FDR-0.3.3v.md) | Design rationale |
|
|
308
110
|
|
|
309
111
|
---
|
|
310
112
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/analyzer/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/analyzer/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
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;
|
|
77
|
+
//# sourceMappingURL=scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../src/analyzer/scope.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,WAAW,EASZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAIlE;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEjF;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,cAAc,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,qBAAa,KAAK;IAChB,QAAQ,CAAC,MAAM,EAAE,KAAK,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAa;IAClD,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;gBAEjC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,EAAE,MAAM,GAAE,KAAK,GAAG,IAAW;IAK5E;;OAEG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI5B;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAMxC;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAGjC;AAID;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC3B,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B;AAED;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,MAAM,CAAiC;IAC/C,OAAO,CAAC,YAAY,CAAsB;IAC1C,OAAO,CAAC,WAAW,CAAsB;IAEzC;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,mBAAmB;IAclD,OAAO,CAAC,aAAa;IA0CrB,OAAO,CAAC,mBAAmB;IAK3B,OAAO,CAAC,aAAa;IAuBrB,OAAO,CAAC,WAAW;IAgDnB,OAAO,CAAC,WAAW;IAgEnB,OAAO,CAAC,eAAe;IAqBvB,OAAO,CAAC,gBAAgB;IAuCxB,OAAO,CAAC,YAAY;IAiBpB,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,KAAK;CAQd;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,WAAW,GAAG,mBAAmB,CAGtE"}
|