pub mod builtin;
mod execute;
mod expand;
mod fetch;
mod plan;
pub use execute::*;
pub use expand::*;
pub use fetch::{fetch_github, read_collection_spec};
pub use plan::*;
use std::path::PathBuf;
use crate::spec::{AgentName, OnTargetModified, Ownership, Source};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DeploymentStatus {
Create,
Update,
Conflict { reason: String },
Orphan,
UpToDate,
}
#[derive(Debug, Clone)]
pub struct PlannedDeployment {
pub rule_id: String,
pub agent: AgentName,
pub source: Source,
pub source_hash: String,
pub target_path: PathBuf,
pub rendered_content: String,
pub status: DeploymentStatus,
}
#[derive(Debug)]
pub struct Plan {
pub items: Vec<PlannedDeployment>,
pub owners: Vec<Ownership>,
}
impl Plan {
pub fn is_clean(&self) -> bool {
self.items
.iter()
.all(|d| d.status == DeploymentStatus::UpToDate)
}
pub fn has_conflicts(&self) -> bool {
self.items
.iter()
.any(|d| matches!(d.status, DeploymentStatus::Conflict { .. }))
}
pub fn has_orphans(&self) -> bool {
self.items
.iter()
.any(|d| d.status == DeploymentStatus::Orphan)
}
}
#[derive(Debug, Clone)]
pub struct ExpandedItem {
pub rule_id: String,
pub source: Source,
pub source_content: String,
pub source_hash: String,
pub kind: ExpandedKind,
}
#[derive(Debug, Clone)]
pub enum ExpandedKind {
Skill(crate::agent::Skill),
Agent(crate::agent::Agent),
System(SystemFile),
}
#[derive(Debug, Clone)]
pub struct SystemFile {
pub file: PathBuf,
pub body: String,
}
#[derive(Debug, Clone)]
pub struct RenderedTarget {
pub rule_id: String,
pub agent: AgentName,
pub source: Source,
pub source_hash: String,
pub target_path: PathBuf,
pub content: String,
pub content_hash: String,
}
pub fn hash_content(content: &str) -> String {
blake3::hash(content.as_bytes()).to_hex().to_string()
}
pub fn effective_policy(
rule_policy: Option<OnTargetModified>,
default: OnTargetModified,
) -> OnTargetModified {
rule_policy.unwrap_or(default)
}