Skip to content

Commit 1782df6

Browse files
tdiclaude
andcommitted
Fix code formatting issues
- Apply rustfmt to all source files - Fix formatting violations that caused CI failures - Ensure consistent code style across the project 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 156e14b commit 1782df6

File tree

18 files changed

+479
-394
lines changed

18 files changed

+479
-394
lines changed

build.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ fn main() {
3636
if let Some(describe) = git_describe {
3737
println!("cargo:rustc-env=GIT_DESCRIBE={}", describe);
3838
}
39-
39+
4040
if let Some(hash) = git_hash {
4141
println!("cargo:rustc-env=GIT_HASH={}", hash);
4242
}
43-
43+
4444
println!("cargo:rustc-env=BUILD_TIMESTAMP={}", build_timestamp);
45-
45+
4646
// Rebuild if git HEAD changes
4747
println!("cargo:rerun-if-changed=.git/HEAD");
48-
}
48+
}

src/agent.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,21 @@ impl Agent {
3636

3737
pub fn from_url(url: &str) -> anyhow::Result<Self> {
3838
let parsed_url = url::Url::parse(url)?;
39-
39+
4040
// Extract agent name from URL
4141
let name = if parsed_url.host_str() == Some("github.com") {
42-
let segments: Vec<&str> = parsed_url.path()
42+
let segments: Vec<&str> = parsed_url
43+
.path()
4344
.trim_start_matches('/')
4445
.split('/')
4546
.filter(|s| !s.is_empty())
4647
.collect();
47-
48+
4849
// We only support file URLs (with /blob/)
4950
if segments.len() >= 5 && segments[2] == "blob" {
5051
// Use the filename
51-
segments.last()
52+
segments
53+
.last()
5254
.ok_or_else(|| anyhow::anyhow!("No filename in URL"))?
5355
.to_string()
5456
} else {
@@ -98,7 +100,7 @@ mod tests {
98100
"test-agent".to_string(),
99101
AgentSource::Local(PathBuf::from("path/to/agent")),
100102
);
101-
103+
102104
assert_eq!(agent.name, "test-agent");
103105
assert!(agent.enabled);
104106
matches!(agent.source, AgentSource::Local(_));
@@ -108,10 +110,10 @@ mod tests {
108110
fn test_agent_from_path() {
109111
let path = Path::new("test-agent.md");
110112
let agent = Agent::from_path(path).unwrap();
111-
113+
112114
assert_eq!(agent.name, "test-agent.md");
113115
assert!(agent.enabled);
114-
116+
115117
if let AgentSource::Local(p) = &agent.source {
116118
assert_eq!(p, Path::new("test-agent.md"));
117119
} else {
@@ -123,27 +125,30 @@ mod tests {
123125
fn test_agent_from_github_repo_url_fails() {
124126
let url = "https://github.com/user/agent-repo";
125127
let result = Agent::from_url(url);
126-
128+
127129
assert!(result.is_err());
128-
assert!(result.unwrap_err().to_string().contains("Only direct file links"));
130+
assert!(result
131+
.unwrap_err()
132+
.to_string()
133+
.contains("Only direct file links"));
129134
}
130135

131136
#[test]
132137
fn test_agent_from_github_repo_with_git_suffix_fails() {
133138
let url = "https://github.com/user/agent-repo.git";
134139
let result = Agent::from_url(url);
135-
140+
136141
assert!(result.is_err());
137142
}
138143

139144
#[test]
140145
fn test_agent_from_github_file_url() {
141146
let url = "https://github.com/user/repo/blob/main/agents/backend-developer.md";
142147
let agent = Agent::from_url(url).unwrap();
143-
148+
144149
assert_eq!(agent.name, "backend-developer.md");
145150
assert!(agent.enabled);
146-
151+
147152
if let AgentSource::GitHub(u) = &agent.source {
148153
assert_eq!(u, url);
149154
} else {
@@ -155,7 +160,7 @@ mod tests {
155160
fn test_agent_from_github_nested_file_url() {
156161
let url = "https://github.com/vijaythecoder/awesome-claude-agents/blob/main/agents/universal/backend-developer.md";
157162
let agent = Agent::from_url(url).unwrap();
158-
163+
159164
assert_eq!(agent.name, "backend-developer.md");
160165
}
161166

@@ -166,7 +171,7 @@ mod tests {
166171
AgentSource::Local(PathBuf::from("relative/path")),
167172
);
168173
let project_root = Path::new("/project");
169-
174+
170175
assert_eq!(
171176
agent.get_local_path(project_root),
172177
PathBuf::from("/project/relative/path")
@@ -180,7 +185,7 @@ mod tests {
180185
AgentSource::Local(PathBuf::from("/absolute/path")),
181186
);
182187
let project_root = Path::new("/project");
183-
188+
184189
assert_eq!(
185190
agent.get_local_path(project_root),
186191
PathBuf::from("/absolute/path")
@@ -194,7 +199,7 @@ mod tests {
194199
AgentSource::GitHub("https://github.com/user/repo".to_string()),
195200
);
196201
let project_root = Path::new("/project");
197-
202+
198203
assert_eq!(
199204
agent.get_local_path(project_root),
200205
PathBuf::from("/project/.ccagents/repo-name")
@@ -208,7 +213,7 @@ mod tests {
208213
AgentSource::Local(PathBuf::from("path")),
209214
);
210215
let project_root = Path::new("/project");
211-
216+
212217
assert_eq!(
213218
agent.get_link_path(project_root),
214219
PathBuf::from("/project/.claude/agents/test-agent")
@@ -220,4 +225,4 @@ mod tests {
220225
let result = Agent::from_url("not-a-url");
221226
assert!(result.is_err());
222227
}
223-
}
228+
}

src/commands/add.rs

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::agent::{Agent, AgentSource};
2-
use crate::config::{ensure_ccagents_dir, ensure_claude_agents_dir, get_project_root, AgentsConfig};
2+
use crate::config::{
3+
ensure_ccagents_dir, ensure_claude_agents_dir, get_project_root, AgentsConfig,
4+
};
35
use crate::downloader::download_from_github;
46
use crate::linker::create_symlink;
57
use anyhow::Result;
@@ -10,23 +12,23 @@ use std::path::{Path, PathBuf};
1012
pub async fn execute(source: &str) -> Result<()> {
1113
let project_root = get_project_root()?;
1214
let mut config = AgentsConfig::load(&project_root)?;
13-
15+
1416
println!("{} agent from {}", "Adding".cyan().bold(), source);
15-
17+
1618
// Determine if source is a URL or local path
1719
let agent = if source.starts_with("http://") || source.starts_with("https://") {
1820
// Handle GitHub URL
1921
if !source.contains("github.com") {
2022
return Err(anyhow::anyhow!("Only GitHub URLs are currently supported"));
2123
}
22-
24+
2325
let agent = Agent::from_url(source)?;
24-
26+
2527
// Download the agent
2628
let ccagents_dir = ensure_ccagents_dir(&project_root)?;
2729
println!(" {} from GitHub...", "Downloading".yellow());
2830
download_from_github(source, &ccagents_dir).await?;
29-
31+
3032
agent
3133
} else {
3234
// Handle local path
@@ -36,89 +38,93 @@ pub async fn execute(source: &str) -> Result<()> {
3638
} else {
3739
project_root.join(&path)
3840
};
39-
41+
4042
if !absolute_path.exists() {
4143
return Err(anyhow::anyhow!("Path does not exist: {:?}", absolute_path));
4244
}
43-
45+
4446
// If the path is outside the project, copy it to .ccagents
4547
let agent = if !absolute_path.starts_with(&project_root) {
4648
let ccagents_dir = ensure_ccagents_dir(&project_root)?;
4749
let agent_name = absolute_path
4850
.file_name()
4951
.and_then(|n| n.to_str())
5052
.ok_or_else(|| anyhow::anyhow!("Invalid path"))?;
51-
53+
5254
let target_path = ccagents_dir.join(agent_name);
53-
55+
5456
println!(" {} agent to .ccagents/...", "Copying".yellow());
55-
57+
5658
// Check if source is a file or directory
5759
if absolute_path.is_file() {
5860
fs::copy(&absolute_path, &target_path)?;
5961
} else if absolute_path.is_dir() {
6062
copy_dir_all(&absolute_path, &target_path)?;
6163
} else {
62-
return Err(anyhow::anyhow!("Path is neither a file nor a directory: {:?}", absolute_path));
64+
return Err(anyhow::anyhow!(
65+
"Path is neither a file nor a directory: {:?}",
66+
absolute_path
67+
));
6368
}
64-
69+
6570
// Use relative path for portability
6671
let relative_target = target_path
6772
.strip_prefix(&project_root)
6873
.unwrap_or(&target_path)
6974
.to_path_buf();
70-
71-
Agent::new(
72-
agent_name.to_string(),
73-
AgentSource::Local(relative_target),
74-
)
75+
76+
Agent::new(agent_name.to_string(), AgentSource::Local(relative_target))
7577
} else {
7678
// Use relative path for agents within the project
7779
let relative_path = absolute_path
7880
.strip_prefix(&project_root)
7981
.unwrap_or(&absolute_path)
8082
.to_path_buf();
81-
83+
8284
Agent::from_path(&relative_path)?
8385
};
84-
86+
8587
agent
8688
};
87-
89+
8890
// Add to config
8991
config.add_agent(agent.clone())?;
9092
config.save(&project_root)?;
91-
93+
9294
// Create symlink if enabled
9395
if agent.enabled {
9496
let _claude_agents_dir = ensure_claude_agents_dir(&project_root)?;
9597
let local_path = agent.get_local_path(&project_root);
9698
let link_path = agent.get_link_path(&project_root);
97-
99+
98100
create_symlink(&local_path, &link_path)?;
99101
println!(" {} symlink in .claude/agents/", "Created".green());
100102
}
101-
102-
println!("\n{} Agent '{}' added successfully!", "✓".green().bold(), agent.name);
103-
103+
104+
println!(
105+
"\n{} Agent '{}' added successfully!",
106+
"✓".green().bold(),
107+
agent.name
108+
);
109+
104110
Ok(())
105111
}
106112

107113
fn copy_dir_all(src: &Path, dst: &Path) -> Result<()> {
108114
fs::create_dir_all(dst)?;
109-
115+
110116
for entry in fs::read_dir(src)? {
111117
let entry = entry?;
112118
let ty = entry.file_type()?;
113119
let src_path = entry.path();
114120
let dst_path = dst.join(entry.file_name());
115-
121+
116122
if ty.is_dir() {
117123
copy_dir_all(&src_path, &dst_path)?;
118124
} else {
119125
fs::copy(&src_path, &dst_path)?;
120126
}
121127
}
122-
128+
123129
Ok(())
124-
}
130+
}

0 commit comments

Comments
 (0)