ai_agent/utils/plugins/
plugin_versioning.rs1#![allow(dead_code)]
3
4use std::path::Path;
5
6use super::schemas::PluginManifest;
7
8fn _git_head_stub(_dir_path: &str) -> Option<String> {
10 None
11}
12
13pub async fn calculate_plugin_version(
15 plugin_id: &str,
16 _source: &super::schemas::PluginSource,
17 manifest: Option<&PluginManifest>,
18 install_path: Option<&str>,
19 provided_version: Option<&str>,
20 git_commit_sha: Option<&str>,
21) -> String {
22 if let Some(m) = manifest {
24 if let Some(ref v) = m.version {
25 log::debug!("Using manifest version for {}: {}", plugin_id, v);
26 return v.clone();
27 }
28 }
29
30 if let Some(v) = provided_version {
32 log::debug!("Using provided version for {}: {}", plugin_id, v);
33 return v.to_string();
34 }
35
36 if let Some(sha) = git_commit_sha {
38 let short_sha = &sha[..sha.len().min(12)];
39 log::debug!(
40 "Using pre-resolved git SHA for {}: {}",
41 plugin_id,
42 short_sha
43 );
44 return short_sha.to_string();
45 }
46
47 if let Some(path) = install_path {
49 if let Ok(Some(sha)) = get_git_commit_sha(path) {
50 let short_sha = &sha[..sha.len().min(12)];
51 log::debug!("Using git SHA for {}: {}", plugin_id, short_sha);
52 return short_sha.to_string();
53 }
54 }
55
56 log::debug!("No version found for {}, using 'unknown'", plugin_id);
58 "unknown".to_string()
59}
60
61pub fn get_git_commit_sha(
63 _dir_path: &str,
64) -> Result<Option<String>, Box<dyn std::error::Error + Send + Sync>> {
65 Ok(None)
66}
67
68pub fn get_version_from_path(install_path: &str) -> Option<String> {
70 let parts: Vec<&str> = install_path.split('/').filter(|p| !p.is_empty()).collect();
71
72 let cache_index = parts.iter().position(|&p| p == "cache");
73
74 if let Some(idx) = cache_index {
75 let components_after_cache = &parts[idx + 1..];
76 if components_after_cache.len() >= 3 {
77 return Some(components_after_cache[2].to_string());
78 }
79 }
80
81 None
82}
83
84pub fn is_versioned_path(path: &str) -> bool {
86 get_version_from_path(path).is_some()
87}