use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct VersionInfo {
pub version: String,
pub prerelease: bool,
pub release_date: Option<String>,
pub release_notes: Option<String>,
pub download_url: Option<String>,
pub checksum: Option<String>,
pub file_size: Option<u64>,
pub metadata: HashMap<String, String>,
}
impl VersionInfo {
pub fn new(version: impl Into<String>) -> Self {
Self {
version: version.into(),
prerelease: false,
release_date: None,
release_notes: None,
download_url: None,
checksum: None,
file_size: None,
metadata: HashMap::new(),
}
}
pub fn with_url(version: impl Into<String>, download_url: impl Into<String>) -> Self {
Self {
version: version.into(),
prerelease: false,
release_date: None,
release_notes: None,
download_url: Some(download_url.into()),
checksum: None,
file_size: None,
metadata: HashMap::new(),
}
}
pub fn as_prerelease(mut self) -> Self {
self.prerelease = true;
self
}
pub fn with_release_date(mut self, date: impl Into<String>) -> Self {
self.release_date = Some(date.into());
self
}
pub fn with_release_notes(mut self, notes: impl Into<String>) -> Self {
self.release_notes = Some(notes.into());
self
}
pub fn with_checksum(mut self, checksum: impl Into<String>) -> Self {
self.checksum = Some(checksum.into());
self
}
pub fn with_file_size(mut self, size: u64) -> Self {
self.file_size = Some(size);
self
}
pub fn with_metadata(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.metadata.insert(key.into(), value.into());
self
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PackageSpec {
pub name: String,
pub version: Option<String>,
pub features: Vec<String>,
pub dev_dependency: bool,
pub options: HashMap<String, String>,
}
impl PackageSpec {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
version: None,
features: Vec::new(),
dev_dependency: false,
options: HashMap::new(),
}
}
pub fn with_version(mut self, version: impl Into<String>) -> Self {
self.version = Some(version.into());
self
}
pub fn with_feature(mut self, feature: impl Into<String>) -> Self {
self.features.push(feature.into());
self
}
pub fn as_dev_dependency(mut self) -> Self {
self.dev_dependency = true;
self
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PackageInfo {
pub name: String,
pub version: String,
pub description: Option<String>,
pub dev_dependency: bool,
pub metadata: HashMap<String, String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Ecosystem {
Node,
Python,
Rust,
Go,
Java,
DotNet,
Ruby,
Php,
Generic,
}
impl std::fmt::Display for Ecosystem {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Ecosystem::Node => write!(f, "node"),
Ecosystem::Python => write!(f, "python"),
Ecosystem::Rust => write!(f, "rust"),
Ecosystem::Go => write!(f, "go"),
Ecosystem::Java => write!(f, "java"),
Ecosystem::DotNet => write!(f, "dotnet"),
Ecosystem::Ruby => write!(f, "ruby"),
Ecosystem::Php => write!(f, "php"),
Ecosystem::Generic => write!(f, "generic"),
}
}
}
#[derive(Debug, Clone, Default)]
pub struct ToolContext {
pub working_directory: Option<PathBuf>,
pub environment_variables: HashMap<String, String>,
pub use_system_path: bool,
pub options: HashMap<String, String>,
}
impl ToolContext {
pub fn new() -> Self {
Self::default()
}
pub fn with_working_directory(mut self, dir: PathBuf) -> Self {
self.working_directory = Some(dir);
self
}
pub fn with_env(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.environment_variables.insert(key.into(), value.into());
self
}
pub fn with_system_path(mut self) -> Self {
self.use_system_path = true;
self
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ToolExecutionResult {
pub exit_code: i32,
pub stdout: Option<String>,
pub stderr: Option<String>,
}
impl ToolExecutionResult {
pub fn success() -> Self {
Self {
exit_code: 0,
stdout: None,
stderr: None,
}
}
pub fn failure(exit_code: i32) -> Self {
Self {
exit_code,
stdout: None,
stderr: None,
}
}
pub fn is_success(&self) -> bool {
self.exit_code == 0
}
pub fn with_stdout(mut self, stdout: impl Into<String>) -> Self {
self.stdout = Some(stdout.into());
self
}
pub fn with_stderr(mut self, stderr: impl Into<String>) -> Self {
self.stderr = Some(stderr.into());
self
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ToolStatus {
pub installed: bool,
pub current_version: Option<String>,
pub installed_versions: Vec<String>,
}
impl ToolStatus {
pub fn new() -> Self {
Self {
installed: false,
current_version: None,
installed_versions: Vec::new(),
}
}
pub fn installed_with_versions(versions: Vec<String>, current: Option<String>) -> Self {
Self {
installed: !versions.is_empty(),
current_version: current,
installed_versions: versions,
}
}
}
impl Default for ToolStatus {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ToolMetadata {
pub name: String,
pub description: String,
pub aliases: Vec<String>,
pub platforms: Vec<String>,
pub metadata: HashMap<String, String>,
}
impl ToolMetadata {
pub fn new(name: impl Into<String>, description: impl Into<String>) -> Self {
Self {
name: name.into(),
description: description.into(),
aliases: Vec::new(),
platforms: Vec::new(),
metadata: HashMap::new(),
}
}
pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
self.aliases.push(alias.into());
self
}
pub fn with_platform(mut self, platform: impl Into<String>) -> Self {
self.platforms.push(platform.into());
self
}
pub fn with_metadata(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.metadata.insert(key.into(), value.into());
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PackageManagerConfig {
pub name: String,
pub version: Option<String>,
pub executable_path: Option<PathBuf>,
pub config_files: Vec<PathBuf>,
pub cache_directory: Option<PathBuf>,
pub supports_lockfiles: bool,
pub supports_workspaces: bool,
pub isolation_level: IsolationLevel,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum IsolationLevel {
Global,
User,
#[default]
Project,
Sandbox,
}