hlx 1.2.5

Configuration language designed specifically for ml/ai/data systems
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
use std::path::PathBuf;
use std::fs;
use anyhow::{Result, Context};

pub fn generate_code(
    template: String,
    output: Option<PathBuf>,
    name: Option<String>,
    force: bool,
    verbose: bool,
) -> Result<()> {
    if verbose {
        println!("🔧 Generating code:");
        println!("  Template: {}", template);
        println!(
            "  Output: {}", output.as_ref().map(| p | p.display().to_string())
            .unwrap_or_else(|| "current directory".to_string())
        );
        println!("  Name: {}", name.as_deref().unwrap_or("generated"));
    }
    let project_dir = find_project_root()?;
    let output_path = output.unwrap_or_else(|| project_dir.join("src"));
    fs::create_dir_all(&output_path).context("Failed to create output directory")?;
    match template.as_str() {
        "agent" => generate_agent_template(&output_path, name, force, verbose)?,
        "workflow" => generate_workflow_template(&output_path, name, force, verbose)?,
        "crew" => generate_crew_template(&output_path, name, force, verbose)?,
        "context" => generate_context_template(&output_path, name, force, verbose)?,
        "test" => generate_test_template(&output_path, name, force, verbose)?,
        "benchmark" => generate_benchmark_template(&output_path, name, force, verbose)?,
        _ => {
            return Err(
                anyhow::anyhow!(
                    "Unknown template '{}'. Available templates: agent, workflow, crew, context, test, benchmark",
                    template
                ),
            );
        }
    }
    println!("✅ Generated {} template successfully!", template);
    Ok(())
}
fn generate_agent_template(
    output_path: &PathBuf,
    name: Option<String>,
    force: bool,
    verbose: bool,
) -> Result<()> {
    let agent_name = name.unwrap_or_else(|| "MyAgent".to_string());
    let filename = format!("{}.hlx", agent_name.to_lowercase());
    let file_path = output_path.join(&filename);
    if file_path.exists() && !force {
        return Err(
            anyhow::anyhow!(
                "File '{}' already exists. Use --force to overwrite.", file_path
                .display()
            ),
        );
    }
    let template = format!(
        r#"// {} - AI Agent Configuration
// Generated by HELIX Compiler

agent {} {{
    name: "{}"
    description: "AI agent for {}"
    model: "gpt-4"
    temperature: 0.7
    max_tokens: 2048
    
    system_prompt: |
        You are {}, a specialized AI agent.
        Your role is to assist with {}.
        
        Guidelines:
        - Be helpful and accurate
        - Provide clear explanations
        - Ask clarifying questions when needed
    
    capabilities: [
        "reasoning"
        "analysis"
        "communication"
    ]
    
    tools: [
        // Add tool configurations here
    ]
    
    constraints: [
        "Always be truthful"
        "Respect user privacy"
        "Provide helpful responses"
    ]
    
    examples: [
        {{
            input: "Example input"
            output: "Expected output"
        }}
    ]
}}
"#,
        agent_name, agent_name, agent_name, agent_name.to_lowercase(), agent_name,
        agent_name.to_lowercase()
    );
    fs::write(&file_path, template).context("Failed to write agent template")?;
    if verbose {
        println!("  Created: {}", file_path.display());
    }
    Ok(())
}
fn generate_workflow_template(
    output_path: &PathBuf,
    name: Option<String>,
    force: bool,
    verbose: bool,
) -> Result<()> {
    let workflow_name = name.unwrap_or_else(|| "MyWorkflow".to_string());
    let filename = format!("{}.hlx", workflow_name.to_lowercase());
    let file_path = output_path.join(&filename);
    if file_path.exists() && !force {
        return Err(
            anyhow::anyhow!(
                "File '{}' already exists. Use --force to overwrite.", file_path
                .display()
            ),
        );
    }
    let template = format!(
        r#"// {} - Workflow Configuration
// Generated by HELIX Compiler

workflow {} {{
    name: "{}"
    description: "Workflow for {}"
    
    triggers: [
        {{
            type: "manual"
            description: "Manual execution"
        }}
    ]
    
    steps: [
        {{
            name: "step1"
            agent: "MyAgent"
            input: {{
                prompt: "Process the input data"
            }}
            output: "processed_data"
        }}
        {{
            name: "step2"
            agent: "MyAgent"
            input: {{
                data: "{{processed_data}}"
                prompt: "Analyze the processed data"
            }}
            output: "analysis_result"
        }}
    ]
    
    error_handling: {{
        retry_count: 3
        retry_delay: 1000
        fallback_action: "notify_admin"
    }}
    
    monitoring: {{
        enabled: true
        metrics: ["execution_time", "success_rate", "error_count"]
    }}
}}
"#,
        workflow_name, workflow_name, workflow_name, workflow_name.to_lowercase()
    );
    fs::write(&file_path, template).context("Failed to write workflow template")?;
    if verbose {
        println!("  Created: {}", file_path.display());
    }
    Ok(())
}
fn generate_crew_template(
    output_path: &PathBuf,
    name: Option<String>,
    force: bool,
    verbose: bool,
) -> Result<()> {
    let crew_name = name.unwrap_or_else(|| "MyCrew".to_string());
    let filename = format!("{}.hlx", crew_name.to_lowercase());
    let file_path = output_path.join(&filename);
    if file_path.exists() && !force {
        return Err(
            anyhow::anyhow!(
                "File '{}' already exists. Use --force to overwrite.", file_path
                .display()
            ),
        );
    }
    let template = format!(
        r#"// {} - Crew Configuration
// Generated by HELIX Compiler

crew {} {{
    name: "{}"
    description: "Crew for {}"
    
    agents: [
        {{
            name: "Agent1"
            role: "Primary Agent"
            specialization: "main_task"
        }}
        {{
            name: "Agent2"
            role: "Support Agent"
            specialization: "support_task"
        }}
    ]
    
    collaboration: {{
        mode: "sequential"
        communication: "structured"
        decision_making: "consensus"
    }}
    
    workflow: {{
        name: "MyWorkflow"
        steps: [
            "Agent1 processes input"
            "Agent2 reviews and validates"
            "Both agents collaborate on final output"
        ]
    }}
    
    performance: {{
        target_accuracy: 0.95
        max_execution_time: 30000
        quality_threshold: 0.8
    }}
}}
"#,
        crew_name, crew_name, crew_name, crew_name.to_lowercase()
    );
    fs::write(&file_path, template).context("Failed to write crew template")?;
    if verbose {
        println!("  Created: {}", file_path.display());
    }
    Ok(())
}
fn generate_context_template(
    output_path: &PathBuf,
    name: Option<String>,
    force: bool,
    verbose: bool,
) -> Result<()> {
    let context_name = name.unwrap_or_else(|| "MyContext".to_string());
    let filename = format!("{}.hlx", context_name.to_lowercase());
    let file_path = output_path.join(&filename);
    if file_path.exists() && !force {
        return Err(
            anyhow::anyhow!(
                "File '{}' already exists. Use --force to overwrite.", file_path
                .display()
            ),
        );
    }
    let template = format!(
        r#"// {} - Context Configuration
// Generated by HELIX Compiler

context {} {{
    name: "{}"
    description: "Context for {}"
    
    variables: {{
        api_key: "{{env.API_KEY}}"
        base_url: "https:
        timeout: 30000
        retry_count: 3
    }}
    
    resources: [
        {{
            name: "database"
            type: "postgresql"
            connection_string: "{{env.DATABASE_URL}}"
        }}
        {{
            name: "cache"
            type: "redis"
            connection_string: "{{env.REDIS_URL}}"
        }}
    ]
    
    environment: {{
        development: {{
            debug: true
            log_level: "debug"
        }}
        production: {{
            debug: false
            log_level: "info"
        }}
    }}
    
    security: {{
        encryption: true
        authentication: "bearer_token"
        rate_limiting: {{
            requests_per_minute: 100
            burst_limit: 200
        }}
    }}
}}
"#,
        context_name, context_name, context_name, context_name.to_lowercase()
    );
    fs::write(&file_path, template).context("Failed to write context template")?;
    if verbose {
        println!("  Created: {}", file_path.display());
    }
    Ok(())
}
fn generate_test_template(
    output_path: &PathBuf,
    name: Option<String>,
    force: bool,
    verbose: bool,
) -> Result<()> {
    let test_name = name.unwrap_or_else(|| "MyTest".to_string());
    let filename = format!("test_{}.hlx", test_name.to_lowercase());
    let file_path = output_path.join(&filename);
    if file_path.exists() && !force {
        return Err(
            anyhow::anyhow!(
                "File '{}' already exists. Use --force to overwrite.", file_path
                .display()
            ),
        );
    }
    let template = format!(
        r#"

test {} {{
    name: "{}"
    description: "Test for {}"
    
    setup: {{
        
        mock_data: true
        test_environment: "development"
    }}
    
    test_cases: [
        {{
            name: "basic_functionality"
            input: {{
                message: "Hello, world!"
            }}
            expected_output: {{
                response: "Hello, world!"
                status: "success"
            }}
        }}
        {{
            name: "error_handling"
            input: {{
                message: ""
            }}
            expected_output: {{
                error: "Invalid input"
                status: "error"
            }}
        }}
    ]
    
    assertions: [
        "response.status == 'success'"
        "response.time < 1000"
        "response.accuracy > 0.9"
    ]
    
    cleanup: {{
        
        remove_temp_files: true
        reset_state: true
    }}
}}
"#,
        test_name, test_name, test_name
    );
    fs::write(&file_path, template).context("Failed to write test template")?;
    if verbose {
        println!("  Created: {}", file_path.display());
    }
    Ok(())
}
fn generate_benchmark_template(
    output_path: &PathBuf,
    name: Option<String>,
    force: bool,
    verbose: bool,
) -> Result<()> {
    let benchmark_name = name.unwrap_or_else(|| "MyBenchmark".to_string());
    let filename = format!("bench_{}.hlx", benchmark_name.to_lowercase());
    let file_path = output_path.join(&filename);
    if file_path.exists() && !force {
        return Err(
            anyhow::anyhow!(
                "File '{}' already exists. Use --force to overwrite.", file_path
                .display()
            ),
        );
    }
    let template = format!(
        r#"

benchmark {} {{
    name: "{}"
    description: "Benchmark for {}"
    
    configuration: {{
        iterations: 1000
        warmup_iterations: 100
        timeout: 30000
        parallel: false
    }}
    
    test_data: [
        {{
            name: "small_input"
            size: "1KB"
            data: "Small test data"
        }}
        {{
            name: "medium_input"
            size: "10KB"
            data: "Medium test data with more content"
        }}
        {{
            name: "large_input"
            size: "100KB"
            data: "Large test data with extensive content"
        }}
    ]
    
    metrics: [
        "execution_time"
        "memory_usage"
        "cpu_usage"
        "throughput"
    ]
    
    thresholds: {{
        max_execution_time: 1000
        max_memory_usage: 50MB
        min_throughput: 100
    }}
    
    reporting: {{
        format: "json"
        include_details: true
        save_results: true
    }}
}}
"#,
        benchmark_name, benchmark_name, benchmark_name
    );
    fs::write(&file_path, template).context("Failed to write benchmark template")?;
    if verbose {
        println!("  Created: {}", file_path.display());
    }
    Ok(())
}
fn find_project_root() -> Result<PathBuf> {
    let mut current_dir = std::env::current_dir()
        .context("Failed to get current directory")?;
    loop {
        let manifest_path = current_dir.join("project.hlx");
        if manifest_path.exists() {
            return Ok(current_dir);
        }
        if let Some(parent) = current_dir.parent() {
            current_dir = parent.to_path_buf();
        } else {
            break;
        }
    }
    Err(anyhow::anyhow!("No HELIX project found. Run 'helix init' first."))
}