use std::collections::HashMap;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
#[serde(transparent)]
pub struct AgentId(String);
impl AgentId {
#[must_use]
pub fn new(id: impl Into<String>) -> Self {
Self(id.into())
}
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for AgentId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.0)
}
}
impl<S: Into<String>> From<S> for AgentId {
fn from(s: S) -> Self {
Self(s.into())
}
}
#[derive(Debug, Clone)]
pub struct AgentConfig {
pub name: AgentId,
pub display_name: String,
pub skills_dir: String,
pub global_skills_dir: Option<PathBuf>,
pub detect_paths: Vec<PathBuf>,
pub show_in_universal_list: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Skill {
pub name: String,
pub description: String,
pub path: PathBuf,
#[serde(skip_serializing_if = "Option::is_none")]
pub raw_content: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub plugin_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<HashMap<String, serde_yml::Value>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RemoteSkill {
pub name: String,
pub description: String,
pub content: String,
pub install_name: String,
pub source_url: String,
pub provider_id: String,
pub source_identifier: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<HashMap<String, serde_yml::Value>>,
}
#[derive(Debug, Clone)]
pub struct WellKnownSkill {
pub remote: RemoteSkill,
pub files: HashMap<String, String>,
pub index_entry: WellKnownSkillEntry,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WellKnownSkillEntry {
pub name: String,
pub description: String,
pub files: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WellKnownIndex {
pub skills: Vec<WellKnownSkillEntry>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum SourceType {
Github,
Gitlab,
Git,
Local,
WellKnown,
}
impl std::fmt::Display for SourceType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Github => write!(f, "github"),
Self::Gitlab => write!(f, "gitlab"),
Self::Git => write!(f, "git"),
Self::Local => write!(f, "local"),
Self::WellKnown => write!(f, "well-known"),
}
}
}
#[derive(Debug, Clone)]
pub struct ParsedSource {
pub source_type: SourceType,
pub url: String,
pub subpath: Option<String>,
pub local_path: Option<PathBuf>,
pub git_ref: Option<String>,
pub skill_filter: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum InstallMode {
#[default]
Symlink,
Copy,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum InstallScope {
#[default]
Project,
Global,
}
#[derive(Debug, Clone)]
pub struct InstallResult {
pub path: PathBuf,
pub canonical_path: Option<PathBuf>,
pub mode: InstallMode,
pub symlink_failed: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InstalledSkill {
pub name: String,
pub description: String,
pub path: PathBuf,
pub canonical_path: PathBuf,
pub scope: InstallScope,
pub agents: Vec<AgentId>,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct DiscoverOptions {
pub include_internal: bool,
pub full_depth: bool,
}
#[derive(Debug, Clone, Default)]
pub struct InstallOptions {
pub scope: InstallScope,
pub mode: InstallMode,
pub cwd: Option<PathBuf>,
}
#[derive(Debug, Clone, Default)]
pub struct ListOptions {
pub scope: Option<InstallScope>,
pub agent_filter: Vec<AgentId>,
pub cwd: Option<PathBuf>,
}
#[derive(Debug, Clone, Default)]
pub struct RemoveOptions {
pub scope: InstallScope,
pub agents: Vec<AgentId>,
pub cwd: Option<PathBuf>,
}
pub const AGENTS_DIR: &str = ".agents";
pub const SKILLS_SUBDIR: &str = "skills";
pub const UNIVERSAL_SKILLS_DIR: &str = ".agents/skills";