Skip to main content

agent_hub_runtime/commands/
skills_diff_metadata.rs

1use crate::core::{skill_metadata, skill_versions::compare_versions};
2use serde::Serialize;
3use std::path::Path;
4
5/// Whole-directory diff between the central copy (`original`) and the source
6/// (`updated`), covering the same file scope that drives the update badge so
7/// the diff can never come back empty while the badge says "update available".
8#[derive(Debug, Serialize)]
9pub struct SkillSourceDiffDto {
10    pub skill_id: String,
11    pub source_label: String,
12    pub revision: String,
13    pub central_path: String,
14    pub source_path: String,
15    pub central_version: Option<String>,
16    pub source_version: Option<String>,
17    /// "central_newer" | "source_newer" | "same_version" | "unknown"
18    pub version_comparison: String,
19    pub entries: Vec<SkillSourceDiffEntryDto>,
20}
21
22#[derive(Debug, Serialize)]
23pub struct SkillSourceDiffEntryDto {
24    pub relative_path: String,
25    /// "added" | "removed" | "modified"
26    pub status: String,
27    /// "text" | "binary" | "too_large" | "permission_only"
28    pub content_kind: String,
29    /// Present only when `content_kind == "text"`.
30    pub original_text: Option<String>,
31    pub updated_text: Option<String>,
32    pub executable_before: bool,
33    pub executable_after: bool,
34}
35
36impl SkillSourceDiffDto {
37    /// Describe the compared directories using persistent locations, never a temporary clone.
38    pub(super) fn from_directories(
39        skill_id: String,
40        source_label: String,
41        revision: String,
42        central_dir: &Path,
43        source_dir: &Path,
44        source_path: String,
45        entries: Vec<SkillSourceDiffEntryDto>,
46    ) -> Self {
47        let central_version = skill_metadata::parse_skill_md(central_dir).version;
48        let source_version = skill_metadata::parse_skill_md(source_dir).version;
49        let version_comparison =
50            compare_versions(central_version.as_deref(), source_version.as_deref());
51        Self {
52            skill_id,
53            source_label,
54            revision,
55            central_path: central_dir.to_string_lossy().into_owned(),
56            source_path,
57            central_version,
58            source_version,
59            version_comparison: version_comparison.to_string(),
60            entries,
61        }
62    }
63}
64
65#[cfg(test)]
66mod tests;