intent_implement/lib.rs
1//! AI-powered full implementation generation from IntentLang specifications.
2//!
3//! This crate translates parsed `.intent` specs into complete, working
4//! implementations using an LLM. It builds on `intent-codegen` (skeleton stubs)
5//! and `intent-gen` (LLM client) to produce contract-aware code.
6//!
7//! The generation pipeline:
8//! 1. Format the spec, generate skeleton code, extract contracts
9//! 2. Send to LLM with implementation-focused system prompt
10//! 3. Validate the output (expected names, balanced delimiters, no stubs)
11//! 4. Retry with error feedback if validation fails
12
13pub mod context;
14pub mod prompt;
15pub mod validate;
16
17pub use intent_codegen::Language;
18pub use validate::ImplementError;
19
20/// Options for implementation generation.
21pub struct ImplementOptions {
22 /// Target language.
23 pub language: Language,
24 /// Maximum number of validation retries (default: 2).
25 pub max_retries: u32,
26 /// Print raw LLM responses to stderr for debugging.
27 pub debug: bool,
28}
29
30impl Default for ImplementOptions {
31 fn default() -> Self {
32 Self {
33 language: Language::Rust,
34 max_retries: 2,
35 debug: false,
36 }
37 }
38}
39
40/// Generate a full implementation from a parsed `.intent` AST.
41///
42/// Returns the complete source code for the target language on success.
43pub fn implement(
44 client: &intent_gen::LlmClient,
45 file: &intent_parser::ast::File,
46 options: &ImplementOptions,
47) -> Result<String, ImplementError> {
48 validate::implement_with_retry(client, file, options)
49}