Core compiler and AI integration for the Intend programming language
npm install @intend-it/core@intend-it/core is the heart of the Intend compiler. It takes parsed AST from @intend-it/parser and generates production-ready TypeScript code using AI (Google Gemini or Ollama).
context keyword
bash
npm install @intend-it/core @intend-it/parser
or
bun add @intend-it/core @intend-it/parser
`
Usage
$3
`typescript
import { AICodeGenerator } from "@intend-it/core";
import { parseToAST } from "@intend-it/parser";
const source =
;
const { ast } = parseToAST(source);
const generator = new AICodeGenerator({
provider: "gemini",
geminiConfig: {
apiKey: process.env.GEMINI_API_KEY!,
model: "gemini-2.0-flash"
}
});
const result = await generator.generate(ast);
console.log(result.code);
// export function Add(a: number, b: number): number {
// const result = a + b;
// if (typeof result !== 'number') throw new Error(...);
// return result;
// }
`
$3
`typescript
const generator = new AICodeGenerator({
provider: "ollama",
ollamaConfig: {
model: "llama3",
baseUrl: "http://localhost:11434",
num_thread: 4 // Optional: limit CPU usage
}
});
`
$3
`typescript
import { generateTypeScript } from "@intend-it/core";
const result = generateTypeScript(ast);
// Generates template with // TODO comments
`
Configuration Options
`typescript
interface AIGeneratorOptions {
provider: "gemini" | "ollama";
geminiConfig?: {
apiKey: string;
model?: string; // Default: "gemini-2.0-flash"
temperature?: number; // Default: 0.2
};
ollamaConfig?: {
model?: string; // Default: "llama3"
baseUrl?: string; // Default: "http://localhost:11434"
temperature?: number;
num_thread?: number; // CPU thread limit
};
maxAttempts?: number; // Auto-correction retries (default: 5)
}
`
š Build Determinism & Lockfiles
The core package includes a LockfileManager that ensures generated code is deterministic and reusable.
`typescript
import { LockfileManager, computeHash } from "@intend-it/core";
const lockManager = new LockfileManager("./intend.lock");
// Calculate hashes
const sourceHash = computeHash(intentSource);
const configHash = computeHash(JSON.stringify(config));
// Try to get from lockfile
const cachedCode = lockManager.getEntry(relativePath, sourceHash, configHash);
if (cachedCode) {
return cachedCode; // Instant build!
}
// Generate new code and save to lockfile
const result = await generator.generate(ast);
lockManager.setEntry(relativePath, sourceHash, configHash, result.code, {
model: "gemini-2.0-flash",
provider: "gemini"
});
lockManager.save();
`
$3
- Determinism: Prevents minor AI fluctuations from changing your production code.
- Performance: Skips expensive LLM calls for unchanged intentions.
- Auditability: Changes to generated code appear in your git diffs, making it easy to review what the AI has changed.
Architecture
`
āāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāā
ā .intent file ā āāā¶ ā Parser ā āāā¶ ā AST ā
āāāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāā āāāāāāāāāā¬āāāāāāāāā
ā
āāāāāāāāāāāāāāāā ā¼
ā AI Provider ā āāā āāāāāāāāāāāāāāāāāāā
ā (Gemini/Ollama)ā ā Prompt Builder ā
āāāāāāāāā¬āāāāāāāā āāāāāāāāāāāāāāāāāāā
ā
ā¼
āāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāā
ā Validator ā āāā¶ ā TypeScript.ts ā
ā (auto-retry) ā āāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāā
`
Related Packages
- @intend-it/parser - Lexer and parser
- @intend-it/cli` - Command-line interface