Architecture Overview
Intend is not a typical transpiler. It is a probabilistic compiler.
Traditional compilers allow for only one correct output for a given input. Intend allows for many correct implementation outputs for a given intent, constrained by strict safety contracts.
High-Level Data Flow
graph TD
A[Source .intent] -->|Lexing/Parsing| B(AST)
B -->|Content Hash| C{CAS Cache}
C -->|Hit| D[Cached Output]
C -->|Miss| E[AI Code Generator]
E -->|Prompt Engineering| F[LLM (Gemini/Ollama)]
F -->|Raw Response| G[Code Extraction]
G -->|TypeScript Compiler| H{Validation}
H -->|Success| I[Final .ts Output]
H -->|Errors| J[Self-Healing Loop]
J -->|Diagnostics| ECore Components
1. The Parser (Deterministic)
We use Chevrotain to lex and parse the Intent DSL into a structured Abstract Syntax Tree (AST). This phase is 100% deterministic. If your intent has invalid syntax, it fails fast before touching any AI.
2. The Content Addressable Storage (CAS)
To ensure speed, we hash the input file content and the build configuration. We verify if this exact state has been built before. If so, code generation is skipped entirely.
3. The AI Generator (Probabilistic)
This is the "backend" of the compiler. It accepts an AST and context (imports), constructs a sophisticated prompt, and queries the configured Provider (Gemini or Ollama).
4. The Validation Loop (Self-Healing)
Generated code is never trusted blindly. It passes through a validation layer:
- Syntax Check: Uses the TypeScript compiler API to verify the code is valid TS.
- Logic Review: (Optional) A second AI pass to audit the code against invariants.
If validation fails, the error is fed back into the generator for a "fix" attempt.