pub struct Source {
pub name: String,
pub url: String,
pub description: Option<String>,
pub enabled: bool,
pub local_path: Option<PathBuf>,
}
Expand description
Represents a Git repository source containing Claude Code resources.
A Source
defines a repository location and metadata for accessing Claude Code
resources like agents and snippets. Sources can be remote repositories (GitHub, GitLab, etc.)
or local file paths, and support various authentication mechanisms.
§Fields
name
: Unique identifier for the source (used in manifests and commands)url
: Repository location (HTTPS, SSH, file://, or local path)description
: Optional human-readable descriptionenabled
: Whether this source should be used for operationslocal_path
: Runtime cache location (not serialized, set during sync operations)
§Repository URL Formats
§Remote Repositories
- HTTPS:
https://github.com/owner/repo.git
- SSH:
git@github.com:owner/repo.git
- HTTPS with auth:
https://token@github.com/owner/repo.git
§Local Repositories
- Absolute path:
/path/to/repository
- Relative path:
../relative/path
or./local-path
- File URL:
file:///absolute/path/to/repository
§Security Considerations
Authentication tokens should never be stored in Source
instances that are
serialized to project manifests. Use the global configuration for credentials.
§Examples
use agpm_cli::source::Source;
// Public repository
let source = Source::new(
"community".to_string(),
"https://github.com/example/agpm-community.git".to_string()
).with_description("Community resources".to_string());
// Local development repository
let local = Source::new(
"local-dev".to_string(),
"/path/to/local/repo".to_string()
);
Fields§
§name: String
Unique identifier for this source
url: String
Repository URL or local path
description: Option<String>
Optional human-readable description
enabled: bool
Whether this source is enabled for operations
local_path: Option<PathBuf>
Runtime path to cached repository (not serialized)
Implementations§
Source§impl Source
impl Source
Sourcepub const fn new(name: String, url: String) -> Self
pub const fn new(name: String, url: String) -> Self
Creates a new source with the given name and URL.
The source is created with default settings:
- No description
- Enabled by default
- No local path (will be set during sync operations)
§Arguments
name
- Unique identifier for this sourceurl
- Repository URL or local path
§Examples
use agpm_cli::source::Source;
let source = Source::new(
"official".to_string(),
"https://github.com/example/agpm-official.git".to_string()
);
assert_eq!(source.name, "official");
assert!(source.enabled);
assert!(source.description.is_none());
Sourcepub fn with_description(self, desc: String) -> Self
pub fn with_description(self, desc: String) -> Self
Adds a human-readable description to this source.
This is a builder pattern method that consumes the source and returns it with the description field set. Descriptions help users understand the purpose and contents of each source.
§Arguments
desc
- Human-readable description of the source
§Examples
use agpm_cli::source::Source;
let source = Source::new(
"community".to_string(),
"https://github.com/example/agpm-community.git".to_string()
).with_description("Community-contributed agents and snippets".to_string());
assert_eq!(source.description, Some("Community-contributed agents and snippets".to_string()));
Sourcepub fn cache_dir(&self, base_dir: &Path) -> PathBuf
pub fn cache_dir(&self, base_dir: &Path) -> PathBuf
Generates the cache directory path for this source.
Creates a unique cache directory name based on the repository URL to avoid
conflicts between sources. The directory name follows the pattern {owner}_{repo}
parsed from the Git URL.
§Cache Directory Structure
- For
https://github.com/owner/repo.git
→{base_dir}/sources/owner_repo
- For invalid URLs →
{base_dir}/sources/unknown_{source_name}
§Arguments
base_dir
- Base cache directory (typically~/.agpm/cache
)
§Returns
PathBuf
pointing to the cache directory for this source
§Examples
use agpm_cli::source::Source;
use std::path::Path;
let source = Source::new(
"community".to_string(),
"https://github.com/example/agpm-community.git".to_string()
);
let base_dir = Path::new("/home/user/.agpm/cache");
let cache_dir = source.cache_dir(base_dir);
assert_eq!(
cache_dir,
Path::new("/home/user/.agpm/cache/sources/example_agpm-community")
);