style: Applied consistent formatting to agent changes

This commit is contained in:
2025-10-10 14:48:10 -06:00
parent 4bf338f91a
commit f822546971
3 changed files with 82 additions and 77 deletions
+41 -39
View File
@@ -7,9 +7,9 @@ use crate::{
use anyhow::{Context, Result};
use inquire::{validator::Validation, Text};
use std::{fs::read_to_string, path::Path};
use rust_embed::Embed;
use serde::{Deserialize, Serialize};
use std::{fs::read_to_string, path::Path};
const DEFAULT_AGENT_NAME: &str = "rag";
@@ -33,34 +33,36 @@ pub struct Agent {
}
impl Agent {
pub fn install_builtin_agents() -> Result<()> {
info!("Installing built-in agents in {}", Config::agents_data_dir().display());
pub fn install_builtin_agents() -> Result<()> {
info!(
"Installing built-in agents in {}",
Config::agents_data_dir().display()
);
for file in AgentAssets::iter() {
debug!("Processing agent file: {}", file.as_ref());
for file in AgentAssets::iter() {
debug!("Processing agent file: {}", file.as_ref());
let embedded_file = AgentAssets::get(&file).ok_or_else(|| {
anyhow!(
"Failed to load embedded agent file: {}",
file.as_ref()
)
})?;
let content = unsafe { std::str::from_utf8_unchecked(&embedded_file.data) };
let file_path = Config::agents_data_dir().join(file.as_ref());
let embedded_file = AgentAssets::get(&file)
.ok_or_else(|| anyhow!("Failed to load embedded agent file: {}", file.as_ref()))?;
let content = unsafe { std::str::from_utf8_unchecked(&embedded_file.data) };
let file_path = Config::agents_data_dir().join(file.as_ref());
if file_path.exists() {
debug!("Agent file already exists, skipping: {}", file_path.display());
continue;
}
if file_path.exists() {
debug!(
"Agent file already exists, skipping: {}",
file_path.display()
);
continue;
}
ensure_parent_exists(&file_path)?;
info!("Creating agent file: {}", file_path.display());
let mut agent_file = File::create(&file_path)?;
agent_file.write_all(content.as_bytes())?;
}
ensure_parent_exists(&file_path)?;
info!("Creating agent file: {}", file_path.display());
let mut agent_file = File::create(&file_path)?;
agent_file.write_all(content.as_bytes())?;
}
Ok(())
}
Ok(())
}
pub async fn init(
config: &GlobalConfig,
@@ -563,23 +565,23 @@ pub struct AgentVariable {
}
pub fn list_agents() -> Vec<String> {
let agents_data_dir = Config::agents_data_dir();
if !agents_data_dir.exists() {
return vec![];
}
let agents_data_dir = Config::agents_data_dir();
if !agents_data_dir.exists() {
return vec![];
}
let mut agents = Vec::new();
if let Ok(entries) = read_dir(agents_data_dir) {
for entry in entries.flatten() {
if entry.path().is_dir() {
if let Some(name) = entry.file_name().to_str() {
agents.push(name.to_string());
}
}
}
}
let mut agents = Vec::new();
if let Ok(entries) = read_dir(agents_data_dir) {
for entry in entries.flatten() {
if entry.path().is_dir() {
if let Some(name) = entry.file_name().to_str() {
agents.push(name.to_string());
}
}
}
}
agents
agents
}
pub fn complete_agent_variables(agent_name: &str) -> Vec<(String, Option<String>)> {