Skip to content

Commit 64abe8a

Browse files
committed
refactor(agent): remove dead code and integrate McpToolsHandler
Remove dead code warnings and properly integrate McpToolsHandler: - Remove #[allow(dead_code)] from McpToolsHandler (now actively used) - Integrate McpToolsHandler into ReplHandler for MCP commands - Refactor wizard to use into_result() pattern (cleaner error handling) - Remove unused error variants: PathNotFound, Config, RoleExists, Network - Remove unused functions: prompt_confirm, prompt_input - Gate test-only function is_first_run with #[cfg(test)] Changes: - mcp_tools.rs: Remove dead_code attributes, simplify error handling - handler.rs: Add mcp_handler field, use in MCP command handlers - wizard.rs: Use into_result() instead of manual match blocks - mod.rs: Remove unused OnboardingError variants - validation.rs: Remove PathNotFound variant - prompts.rs: Remove unused utility functions - service.rs: Remove dead_code attributes from now-used methods Verification: - All 134 unit tests pass - All 11 integration tests pass - No breaking changes - Code quality improved
1 parent 521888a commit 64abe8a

File tree

7 files changed

+83
-235
lines changed

7 files changed

+83
-235
lines changed

crates/terraphim_agent/src/onboarding/mod.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ pub enum OnboardingError {
4343
#[error("Validation failed: {0}")]
4444
Validation(String),
4545

46-
/// Configuration error from terraphim_config
47-
#[error("Configuration error: {0}")]
48-
Config(String),
49-
5046
/// IO error during file operations
5147
#[error("IO error: {0}")]
5248
Io(#[from] std::io::Error),
@@ -55,22 +51,10 @@ pub enum OnboardingError {
5551
#[error("Not a TTY - interactive mode requires a terminal. Use --template for non-interactive mode.")]
5652
NotATty,
5753

58-
/// Role with this name already exists
59-
#[error("Role already exists: {0}")]
60-
RoleExists(String),
61-
6254
/// JSON serialization/deserialization error
6355
#[error("JSON error: {0}")]
6456
Json(#[from] serde_json::Error),
6557

66-
/// Network error during URL validation
67-
#[error("Network error: {0}")]
68-
Network(String),
69-
70-
/// Path does not exist
71-
#[error("Path does not exist: {0}")]
72-
PathNotFound(String),
73-
7458
/// User went back in wizard navigation
7559
#[error("User navigated back")]
7660
NavigateBack,

crates/terraphim_agent/src/onboarding/prompts.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -572,27 +572,6 @@ pub fn prompt_knowledge_graph() -> Result<PromptResult<Option<KnowledgeGraph>>,
572572
}
573573
}
574574

575-
/// Prompt for confirmation with custom message
576-
pub fn prompt_confirm(message: &str, default: bool) -> Result<bool, OnboardingError> {
577-
let theme = ColorfulTheme::default();
578-
Ok(Confirm::with_theme(&theme)
579-
.with_prompt(message)
580-
.default(default)
581-
.interact()?)
582-
}
583-
584-
/// Prompt for simple text input
585-
pub fn prompt_input(message: &str, default: Option<&str>) -> Result<String, OnboardingError> {
586-
let theme = ColorfulTheme::default();
587-
let mut input = Input::with_theme(&theme).with_prompt(message);
588-
589-
if let Some(d) = default {
590-
input = input.default(d.to_string());
591-
}
592-
593-
Ok(input.interact_text()?)
594-
}
595-
596575
#[cfg(test)]
597576
mod tests {
598577
use super::*;

crates/terraphim_agent/src/onboarding/validation.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ pub enum ValidationError {
2626
#[error("Service {0} requires: {1}")]
2727
ServiceRequirement(String, String),
2828

29-
/// Path does not exist on filesystem
30-
#[error("Path does not exist: {0}")]
31-
PathNotFound(String),
32-
3329
/// URL is malformed
3430
#[error("Invalid URL: {0}")]
3531
InvalidUrl(String),

crates/terraphim_agent/src/onboarding/wizard.rs

Lines changed: 32 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
//! Provides the interactive setup wizard flow for first-time users
44
//! and add-role capability for extending existing configurations.
55
6-
use std::path::PathBuf;
7-
86
use dialoguer::{theme::ColorfulTheme, Confirm, Select};
7+
use std::path::PathBuf;
98
use terraphim_config::Role;
109
use terraphim_types::RelevanceFunction;
1110

1211
use super::prompts::{
1312
prompt_haystacks, prompt_knowledge_graph, prompt_llm_config, prompt_relevance_function,
14-
prompt_role_basics, prompt_theme, PromptResult,
13+
prompt_role_basics, prompt_theme,
1514
};
1615
use super::templates::{ConfigTemplate, TemplateRegistry};
1716
use super::validation::validate_role;
@@ -110,6 +109,7 @@ impl QuickStartChoice {
110109
}
111110

112111
/// Check if this is a first run (no existing configuration)
112+
#[cfg(test)]
113113
pub fn is_first_run(config_path: &PathBuf) -> bool {
114114
!config_path.exists()
115115
}
@@ -312,7 +312,7 @@ fn prompt_path_for_template(
312312
.map_err(|_| OnboardingError::Cancelled)?;
313313

314314
if !proceed {
315-
return Err(OnboardingError::PathNotFound(expanded));
315+
return Err(OnboardingError::Cancelled);
316316
}
317317
}
318318

@@ -328,84 +328,53 @@ fn custom_wizard(theme: &ColorfulTheme) -> Result<Role, OnboardingError> {
328328
println!();
329329

330330
// Step 1: Role basics (name and shortname)
331-
let (name, shortname) = match prompt_role_basics()? {
332-
PromptResult::Value(v) => v,
333-
PromptResult::Back => return Err(OnboardingError::NavigateBack),
334-
};
331+
let (name, shortname) = prompt_role_basics()?.into_result()?;
335332

336333
let mut role = Role::new(name);
337334
role.shortname = shortname;
338335

339336
// Step 2: Theme selection
340-
role.theme = match prompt_theme()? {
341-
PromptResult::Value(t) => t,
342-
PromptResult::Back => {
343-
// Go back to role basics - restart wizard
344-
return Err(OnboardingError::NavigateBack);
345-
}
346-
};
337+
role.theme = prompt_theme()?.into_result()?;
347338

348339
// Step 3: Relevance function
349-
let relevance = match prompt_relevance_function()? {
350-
PromptResult::Value(r) => r,
351-
PromptResult::Back => {
352-
// Go back - restart wizard
353-
return Err(OnboardingError::NavigateBack);
354-
}
355-
};
340+
let relevance = prompt_relevance_function()?.into_result()?;
356341
role.relevance_function = relevance;
357342
// Set terraphim_it based on relevance function (TerraphimGraph requires it)
358343
role.terraphim_it = matches!(relevance, RelevanceFunction::TerraphimGraph);
359344

360345
// Step 4: Haystacks
361-
role.haystacks = match prompt_haystacks()? {
362-
PromptResult::Value(haystacks) => haystacks,
363-
PromptResult::Back => {
364-
return Err(OnboardingError::NavigateBack);
365-
}
366-
};
346+
role.haystacks = prompt_haystacks()?.into_result()?;
367347

368348
// Step 5: LLM configuration (optional)
369-
match prompt_llm_config()? {
370-
PromptResult::Value(llm_config) => {
371-
if let Some(provider) = llm_config.provider {
372-
role.llm_enabled = true;
373-
role.extra.insert(
374-
"llm_provider".to_string(),
375-
serde_json::Value::String(provider),
376-
);
377-
if let Some(model) = llm_config.model {
378-
role.extra
379-
.insert("ollama_model".to_string(), serde_json::Value::String(model));
380-
}
381-
if let Some(base_url) = llm_config.base_url {
382-
role.extra.insert(
383-
"ollama_base_url".to_string(),
384-
serde_json::Value::String(base_url),
385-
);
386-
}
387-
if let Some(api_key) = llm_config.api_key {
388-
role.extra.insert(
389-
"openrouter_api_key".to_string(),
390-
serde_json::Value::String(api_key),
391-
);
392-
}
393-
} else {
394-
role.llm_enabled = false;
395-
}
349+
let llm_config = prompt_llm_config()?.into_result()?;
350+
if let Some(provider) = llm_config.provider {
351+
role.llm_enabled = true;
352+
role.extra.insert(
353+
"llm_provider".to_string(),
354+
serde_json::Value::String(provider),
355+
);
356+
if let Some(model) = llm_config.model {
357+
role.extra
358+
.insert("ollama_model".to_string(), serde_json::Value::String(model));
359+
}
360+
if let Some(base_url) = llm_config.base_url {
361+
role.extra.insert(
362+
"ollama_base_url".to_string(),
363+
serde_json::Value::String(base_url),
364+
);
396365
}
397-
PromptResult::Back => {
398-
return Err(OnboardingError::NavigateBack);
366+
if let Some(api_key) = llm_config.api_key {
367+
role.extra.insert(
368+
"openrouter_api_key".to_string(),
369+
serde_json::Value::String(api_key),
370+
);
399371
}
372+
} else {
373+
role.llm_enabled = false;
400374
}
401375

402376
// Step 6: Knowledge graph (optional)
403-
role.kg = match prompt_knowledge_graph()? {
404-
PromptResult::Value(kg) => kg,
405-
PromptResult::Back => {
406-
return Err(OnboardingError::NavigateBack);
407-
}
408-
};
377+
role.kg = prompt_knowledge_graph()?.into_result()?;
409378

410379
// Validate the complete role
411380
validate_role(&role).map_err(|errors| {

0 commit comments

Comments
 (0)