terraphim_agent 1.16.34

Terraphim AI Agent CLI - Command-line interface with interactive REPL and ASCII graph visualization
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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
//! Template registry for quick start configurations
//!
//! Provides embedded JSON templates for common use cases:
//! - Terraphim Engineer (graph embeddings)
//! - LLM Enforcer (bun install KG)
//! - Rust Developer
//! - Local Notes
//! - AI Engineer
//! - Log Analyst

use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
use terraphim_automata::AutomataPath;
use terraphim_config::{Haystack, KnowledgeGraph, KnowledgeGraphLocal, Role, ServiceType};
use terraphim_types::{KnowledgeGraphInputType, RelevanceFunction};

/// A pre-built configuration template for quick start
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConfigTemplate {
    /// Unique identifier for the template
    pub id: String,
    /// Human-readable name
    pub name: String,
    /// Short description of use case
    pub description: String,
    /// Whether this template requires a path parameter
    pub requires_path: bool,
    /// Default path if applicable
    pub default_path: Option<String>,
    /// Whether this template includes LLM configuration
    pub has_llm: bool,
    /// Whether this template includes knowledge graph
    pub has_kg: bool,
}

impl ConfigTemplate {
    /// Build the Role from this template, optionally with a custom path
    pub fn build_role(&self, custom_path: Option<&str>) -> Role {
        match self.id.as_str() {
            "terraphim-engineer" => self.build_terraphim_engineer(custom_path),
            "terraphim-engineer-v2" => self.build_terraphim_engineer_v2(custom_path),
            "llm-enforcer" => self.build_llm_enforcer(custom_path),
            "rust-engineer" => self.build_rust_engineer(),
            "rust-engineer-v2" => self.build_rust_engineer_v2(),
            "local-notes" => self.build_local_notes(custom_path),
            "ai-engineer" => self.build_ai_engineer(custom_path),
            "log-analyst" => self.build_log_analyst(),
            "frontend-engineer" => self.build_frontend_engineer(custom_path),
            "python-engineer" => self.build_python_engineer(custom_path),
            _ => self.build_terraphim_engineer(custom_path), // Default fallback
        }
    }

    fn build_terraphim_engineer(&self, custom_path: Option<&str>) -> Role {
        let location = custom_path
            .map(|s| s.to_string())
            .unwrap_or_else(|| "~/Documents".to_string());

        let mut role = Role::new("Terraphim Engineer");
        role.shortname = Some("terra".to_string());
        role.relevance_function = RelevanceFunction::TerraphimGraph;
        role.terraphim_it = true;
        role.theme = "spacelab".to_string();
        role.kg = Some(KnowledgeGraph {
            automata_path: Some(AutomataPath::Remote(
                "https://system-operator.s3.eu-west-2.amazonaws.com/term_to_id.json".to_string(),
            )),
            knowledge_graph_local: None,
            public: true,
            publish: false,
        });
        role.haystacks = vec![Haystack {
            location,
            service: ServiceType::Ripgrep,
            read_only: true,
            fetch_content: false,
            atomic_server_secret: None,
            extra_parameters: Default::default(),
        }];
        role.llm_enabled = false;
        role
    }

    fn build_terraphim_engineer_v2(&self, custom_path: Option<&str>) -> Role {
        let location = custom_path
            .map(|s| s.to_string())
            .unwrap_or_else(|| "~/projects".to_string());

        let mut role = Role::new("Terraphim Engineer v2");
        role.shortname = Some("terra2".to_string());
        role.relevance_function = RelevanceFunction::TerraphimGraph;
        role.terraphim_it = true;
        role.theme = "spacelab".to_string();
        role.kg = Some(KnowledgeGraph {
            automata_path: Some(AutomataPath::Remote(
                "https://system-operator.s3.eu-west-2.amazonaws.com/term_to_id.json".to_string(),
            )),
            knowledge_graph_local: Some(KnowledgeGraphLocal {
                input_type: KnowledgeGraphInputType::Markdown,
                path: PathBuf::from("docs/terraphim"),
            }),
            public: true,
            publish: false,
        });
        role.haystacks = vec![Haystack {
            location,
            service: ServiceType::Ripgrep,
            read_only: true,
            fetch_content: false,
            atomic_server_secret: None,
            extra_parameters: Default::default(),
        }];
        role.llm_enabled = false;
        role
    }

    fn build_llm_enforcer(&self, custom_path: Option<&str>) -> Role {
        let kg_path = custom_path
            .map(|s| s.to_string())
            .unwrap_or_else(|| "docs/src/kg".to_string());

        let mut role = Role::new("LLM Enforcer");
        role.shortname = Some("enforce".to_string());
        role.relevance_function = RelevanceFunction::TitleScorer;
        role.terraphim_it = true;
        role.theme = "darkly".to_string();
        role.kg = Some(KnowledgeGraph {
            automata_path: None,
            knowledge_graph_local: Some(KnowledgeGraphLocal {
                input_type: KnowledgeGraphInputType::Markdown,
                path: PathBuf::from(kg_path),
            }),
            public: false,
            publish: false,
        });
        role.haystacks = vec![Haystack {
            location: ".".to_string(),
            service: ServiceType::Ripgrep,
            read_only: true,
            fetch_content: false,
            atomic_server_secret: None,
            extra_parameters: Default::default(),
        }];
        role.llm_enabled = false;
        role
    }

    fn build_rust_engineer(&self) -> Role {
        let mut role = Role::new("Rust Engineer");
        role.shortname = Some("rust".to_string());
        role.relevance_function = RelevanceFunction::TitleScorer;
        role.terraphim_it = false;
        role.theme = "cosmo".to_string();
        role.kg = None;
        role.haystacks = vec![Haystack {
            location: "https://query.rs".to_string(),
            service: ServiceType::QueryRs,
            read_only: true,
            fetch_content: false,
            atomic_server_secret: None,
            extra_parameters: Default::default(),
        }];
        role.llm_enabled = false;
        role
    }

    fn build_rust_engineer_v2(&self) -> Role {
        let mut role = Role::new("Rust Engineer v2");
        role.shortname = Some("rust2".to_string());
        role.relevance_function = RelevanceFunction::TitleScorer;
        role.terraphim_it = false;
        role.theme = "cosmo".to_string();
        role.kg = None;
        role.haystacks = vec![
            Haystack {
                location: "https://query.rs".to_string(),
                service: ServiceType::QueryRs,
                read_only: true,
                fetch_content: false,
                atomic_server_secret: None,
                extra_parameters: Default::default(),
            },
            Haystack {
                location: "~/projects".to_string(),
                service: ServiceType::Ripgrep,
                read_only: true,
                fetch_content: false,
                atomic_server_secret: None,
                extra_parameters: Default::default(),
            },
        ];
        role.llm_enabled = false;
        role
    }

    fn build_local_notes(&self, custom_path: Option<&str>) -> Role {
        let location = custom_path
            .map(|s| s.to_string())
            .unwrap_or_else(|| ".".to_string());

        let mut role = Role::new("Local Notes");
        role.shortname = Some("notes".to_string());
        role.relevance_function = RelevanceFunction::TitleScorer;
        role.terraphim_it = false;
        role.theme = "lumen".to_string();
        role.kg = None;
        role.haystacks = vec![Haystack {
            location,
            service: ServiceType::Ripgrep,
            read_only: true,
            fetch_content: false,
            atomic_server_secret: None,
            extra_parameters: Default::default(),
        }];
        role.llm_enabled = false;
        role
    }

    fn build_ai_engineer(&self, custom_path: Option<&str>) -> Role {
        let location = custom_path
            .map(|s| s.to_string())
            .unwrap_or_else(|| "~/Documents".to_string());

        let mut role = Role::new("AI Engineer");
        role.shortname = Some("ai".to_string());
        role.relevance_function = RelevanceFunction::TerraphimGraph;
        role.terraphim_it = true;
        role.theme = "united".to_string();
        role.kg = Some(KnowledgeGraph {
            automata_path: Some(AutomataPath::Remote(
                "https://system-operator.s3.eu-west-2.amazonaws.com/term_to_id.json".to_string(),
            )),
            knowledge_graph_local: None,
            public: true,
            publish: false,
        });
        role.haystacks = vec![Haystack {
            location,
            service: ServiceType::Ripgrep,
            read_only: true,
            fetch_content: false,
            atomic_server_secret: None,
            extra_parameters: Default::default(),
        }];
        // AI Engineer has Ollama LLM configured
        role.llm_enabled = true;
        role.extra.insert(
            "llm_provider".to_string(),
            serde_json::Value::String("ollama".to_string()),
        );
        role.extra.insert(
            "ollama_base_url".to_string(),
            serde_json::Value::String("http://127.0.0.1:11434".to_string()),
        );
        role.extra.insert(
            "ollama_model".to_string(),
            serde_json::Value::String("llama3.2:3b".to_string()),
        );
        role
    }

    fn build_log_analyst(&self) -> Role {
        let mut role = Role::new("Log Analyst");
        role.shortname = Some("logs".to_string());
        role.relevance_function = RelevanceFunction::BM25;
        role.terraphim_it = false;
        role.theme = "darkly".to_string();
        role.kg = None;
        role.haystacks = vec![Haystack {
            location: "http://localhost:7280".to_string(),
            service: ServiceType::Quickwit,
            read_only: true,
            fetch_content: false,
            atomic_server_secret: None,
            extra_parameters: Default::default(),
        }];
        role.llm_enabled = false;
        role
    }

    fn build_frontend_engineer(&self, custom_path: Option<&str>) -> Role {
        let location = custom_path
            .map(|s| s.to_string())
            .unwrap_or_else(|| "~/projects".to_string());

        let mut role = Role::new("FrontEnd Engineer");
        role.shortname = Some("frontend".to_string());
        role.relevance_function = RelevanceFunction::BM25Plus;
        role.terraphim_it = false;
        role.theme = "yeti".to_string();
        role.kg = Some(KnowledgeGraph {
            automata_path: None,
            knowledge_graph_local: Some(KnowledgeGraphLocal {
                input_type: KnowledgeGraphInputType::Markdown,
                path: PathBuf::from("docs/frontend"),
            }),
            public: false,
            publish: false,
        });
        role.haystacks = vec![
            Haystack {
                location,
                service: ServiceType::Ripgrep,
                read_only: true,
                fetch_content: false,
                atomic_server_secret: None,
                extra_parameters: Default::default(),
            },
            Haystack {
                location: "https://grep.app".to_string(),
                service: ServiceType::GrepApp,
                read_only: true,
                fetch_content: false,
                atomic_server_secret: None,
                extra_parameters: {
                    let mut params = HashMap::new();
                    params.insert("language".to_string(), "javascript".to_string());
                    params
                },
            },
        ];
        role.llm_enabled = false;
        role
    }

    fn build_python_engineer(&self, custom_path: Option<&str>) -> Role {
        let location = custom_path
            .map(|s| s.to_string())
            .unwrap_or_else(|| "~/projects".to_string());

        let mut role = Role::new("Python Engineer");
        role.shortname = Some("python".to_string());
        role.relevance_function = RelevanceFunction::BM25F;
        role.terraphim_it = false;
        role.theme = "sandstone".to_string();
        role.kg = Some(KnowledgeGraph {
            automata_path: None,
            knowledge_graph_local: Some(KnowledgeGraphLocal {
                input_type: KnowledgeGraphInputType::Markdown,
                path: PathBuf::from("docs/python"),
            }),
            public: false,
            publish: false,
        });
        role.haystacks = vec![
            Haystack {
                location,
                service: ServiceType::Ripgrep,
                read_only: true,
                fetch_content: false,
                atomic_server_secret: None,
                extra_parameters: Default::default(),
            },
            Haystack {
                location: "https://grep.app".to_string(),
                service: ServiceType::GrepApp,
                read_only: true,
                fetch_content: false,
                atomic_server_secret: None,
                extra_parameters: {
                    let mut params = HashMap::new();
                    params.insert("language".to_string(), "python".to_string());
                    params
                },
            },
        ];
        role.llm_enabled = false;
        role
    }
}

/// Registry of all available templates
#[derive(Debug, Clone)]
pub struct TemplateRegistry {
    templates: Vec<ConfigTemplate>,
}

impl Default for TemplateRegistry {
    fn default() -> Self {
        Self::new()
    }
}

impl TemplateRegistry {
    /// Create a new registry with all embedded templates
    pub fn new() -> Self {
        let templates = vec![
            ConfigTemplate {
                id: "terraphim-engineer".to_string(),
                name: "Terraphim Engineer".to_string(),
                description: "Full-featured semantic search with knowledge graph embeddings"
                    .to_string(),
                requires_path: false,
                default_path: Some("~/Documents".to_string()),
                has_llm: false,
                has_kg: true,
            },
            ConfigTemplate {
                id: "llm-enforcer".to_string(),
                name: "LLM Enforcer".to_string(),
                description: "AI agent hooks with bun install knowledge graph for npm replacement"
                    .to_string(),
                requires_path: false,
                default_path: Some("docs/src/kg".to_string()),
                has_llm: false,
                has_kg: true,
            },
            ConfigTemplate {
                id: "rust-engineer".to_string(),
                name: "Rust Developer".to_string(),
                description: "Search Rust docs and crates.io via QueryRs".to_string(),
                requires_path: false,
                default_path: None,
                has_llm: false,
                has_kg: false,
            },
            ConfigTemplate {
                id: "local-notes".to_string(),
                name: "Local Notes".to_string(),
                description: "Search markdown files in a local folder".to_string(),
                requires_path: true,
                default_path: None,
                has_llm: false,
                has_kg: false,
            },
            ConfigTemplate {
                id: "ai-engineer".to_string(),
                name: "AI Engineer".to_string(),
                description: "Local Ollama LLM with knowledge graph support".to_string(),
                requires_path: false,
                default_path: Some("~/Documents".to_string()),
                has_llm: true,
                has_kg: true,
            },
            ConfigTemplate {
                id: "log-analyst".to_string(),
                name: "Log Analyst".to_string(),
                description: "Quickwit integration for log analysis".to_string(),
                requires_path: false,
                default_path: None,
                has_llm: false,
                has_kg: false,
            },
            ConfigTemplate {
                id: "frontend-engineer".to_string(),
                name: "FrontEnd Engineer".to_string(),
                description: "JavaScript/TypeScript/CSS development with BM25Plus ranking"
                    .to_string(),
                requires_path: true,
                default_path: Some("~/projects".to_string()),
                has_llm: false,
                has_kg: true,
            },
            ConfigTemplate {
                id: "python-engineer".to_string(),
                name: "Python Engineer".to_string(),
                description: "Python development with BM25F field-weighted ranking".to_string(),
                requires_path: true,
                default_path: Some("~/projects".to_string()),
                has_llm: false,
                has_kg: true,
            },
            ConfigTemplate {
                id: "rust-engineer-v2".to_string(),
                name: "Rust Engineer v2".to_string(),
                description: "Rust development with docs.rs + local code search".to_string(),
                requires_path: false,
                default_path: None,
                has_llm: false,
                has_kg: false,
            },
            ConfigTemplate {
                id: "terraphim-engineer-v2".to_string(),
                name: "Terraphim Engineer v2".to_string(),
                description: "Enhanced semantic search with knowledge graph and LLM integration"
                    .to_string(),
                requires_path: false,
                default_path: Some("~/Documents".to_string()),
                has_llm: true,
                has_kg: true,
            },
        ];

        Self { templates }
    }

    /// Get a template by its ID
    pub fn get(&self, id: &str) -> Option<&ConfigTemplate> {
        self.templates.iter().find(|t| t.id == id)
    }

    /// List all available templates
    pub fn list(&self) -> &[ConfigTemplate] {
        &self.templates
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_template_registry_has_terraphim_engineer() {
        let registry = TemplateRegistry::new();
        let template = registry.get("terraphim-engineer");
        assert!(template.is_some());
        let t = template.unwrap();
        assert_eq!(t.name, "Terraphim Engineer");
        assert!(t.has_kg);
    }

    #[test]
    fn test_template_registry_has_llm_enforcer() {
        let registry = TemplateRegistry::new();
        let template = registry.get("llm-enforcer");
        assert!(template.is_some());
        let t = template.unwrap();
        assert_eq!(t.name, "LLM Enforcer");
        assert!(t.has_kg);
        assert_eq!(t.default_path, Some("docs/src/kg".to_string()));
    }

    #[test]
    fn test_template_registry_has_all_ten_templates() {
        let registry = TemplateRegistry::new();
        assert_eq!(registry.list().len(), 10);

        // Existing
        assert!(registry.get("terraphim-engineer").is_some());
        assert!(registry.get("llm-enforcer").is_some());
        assert!(registry.get("rust-engineer").is_some());
        assert!(registry.get("local-notes").is_some());
        assert!(registry.get("ai-engineer").is_some());
        assert!(registry.get("log-analyst").is_some());

        // New
        assert!(registry.get("frontend-engineer").is_some());
        assert!(registry.get("python-engineer").is_some());
        assert!(registry.get("rust-engineer-v2").is_some());
        assert!(registry.get("terraphim-engineer-v2").is_some());
    }

    #[test]
    fn test_ranking_diversity() {
        let registry = TemplateRegistry::new();

        // Collect all relevance functions used
        let mut functions: Vec<RelevanceFunction> = Vec::new();

        for template in registry.list() {
            let role = template.build_role(None);
            if !functions.contains(&role.relevance_function) {
                functions.push(role.relevance_function);
            }
        }

        // Check that BM25Plus and BM25F are used (new diversity)
        assert!(
            functions.contains(&RelevanceFunction::BM25Plus),
            "BM25Plus not used"
        );
        assert!(
            functions.contains(&RelevanceFunction::BM25F),
            "BM25F not used"
        );
    }

    #[test]
    fn test_local_notes_requires_path() {
        let registry = TemplateRegistry::new();
        let template = registry.get("local-notes").unwrap();
        assert!(template.requires_path);
    }

    #[test]
    fn test_build_terraphim_engineer_role() {
        let registry = TemplateRegistry::new();
        let template = registry.get("terraphim-engineer").unwrap();
        let role = template.build_role(None);

        assert_eq!(role.name.to_string(), "Terraphim Engineer");
        assert_eq!(role.shortname, Some("terra".to_string()));
        assert_eq!(role.relevance_function, RelevanceFunction::TerraphimGraph);
        assert!(role.kg.is_some());
        assert!(!role.haystacks.is_empty());
    }

    #[test]
    fn test_build_terraphim_engineer_with_custom_path() {
        let registry = TemplateRegistry::new();
        let template = registry.get("terraphim-engineer").unwrap();
        let role = template.build_role(Some("/custom/path"));

        assert_eq!(role.haystacks[0].location, "/custom/path");
    }

    #[test]
    fn test_build_llm_enforcer_has_local_kg() {
        let registry = TemplateRegistry::new();
        let template = registry.get("llm-enforcer").unwrap();
        let role = template.build_role(None);

        assert!(role.kg.is_some());
        let kg = role.kg.unwrap();
        assert!(kg.knowledge_graph_local.is_some());
        assert!(kg.automata_path.is_none());
    }

    #[test]
    fn test_build_ai_engineer_has_ollama() {
        let registry = TemplateRegistry::new();
        let template = registry.get("ai-engineer").unwrap();
        let role = template.build_role(None);

        assert!(role.llm_enabled);
        assert!(role.extra.contains_key("llm_provider"));
        assert!(role.extra.contains_key("ollama_model"));
    }

    #[test]
    fn test_build_frontend_engineer() {
        let registry = TemplateRegistry::new();
        let template = registry.get("frontend-engineer").unwrap();
        let role = template.build_role(None);

        assert_eq!(role.name.to_string(), "FrontEnd Engineer");
        assert_eq!(role.shortname, Some("frontend".to_string()));
        assert_eq!(role.relevance_function, RelevanceFunction::BM25Plus);
        assert!(role.kg.is_some());

        // Verify dual haystack configuration
        assert_eq!(role.haystacks.len(), 2);
        assert_eq!(role.haystacks[0].service, ServiceType::Ripgrep);
        assert_eq!(role.haystacks[1].service, ServiceType::GrepApp);
        assert_eq!(
            role.haystacks[1].extra_parameters.get("language"),
            Some(&"javascript".to_string())
        );
    }

    #[test]
    fn test_build_python_engineer() {
        let registry = TemplateRegistry::new();
        let template = registry.get("python-engineer").unwrap();
        let role = template.build_role(None);

        assert_eq!(role.name.to_string(), "Python Engineer");
        assert_eq!(role.shortname, Some("python".to_string()));
        assert_eq!(role.relevance_function, RelevanceFunction::BM25F);
        assert!(role.kg.is_some());

        // Verify dual haystack configuration
        assert_eq!(role.haystacks.len(), 2);
        assert_eq!(role.haystacks[0].service, ServiceType::Ripgrep);
        assert_eq!(role.haystacks[1].service, ServiceType::GrepApp);
        assert_eq!(
            role.haystacks[1].extra_parameters.get("language"),
            Some(&"python".to_string())
        );
    }

    #[test]
    fn test_build_rust_engineer_v2() {
        let registry = TemplateRegistry::new();
        let template = registry.get("rust-engineer-v2").unwrap();
        let role = template.build_role(None);

        assert_eq!(role.name.to_string(), "Rust Engineer v2");
        assert_eq!(role.shortname, Some("rust2".to_string()));
        assert_eq!(role.haystacks.len(), 2); // Dual haystack
    }

    #[test]
    fn test_build_terraphim_engineer_v2() {
        let registry = TemplateRegistry::new();
        let template = registry.get("terraphim-engineer-v2").unwrap();
        let role = template.build_role(None);

        assert_eq!(role.name.to_string(), "Terraphim Engineer v2");
        assert_eq!(role.shortname, Some("terra2".to_string()));
        assert_eq!(role.relevance_function, RelevanceFunction::TerraphimGraph);

        // Check hybrid KG
        let kg = role.kg.unwrap();
        assert!(kg.automata_path.is_some()); // Remote
        assert!(kg.knowledge_graph_local.is_some()); // Local
    }
}