Skip to main content

ai_agent/utils/plugins/
plugin_installation_helpers.rs

1// Source: ~/claudecode/openclaudecode/src/utils/plugins/pluginInstallationHelpers.ts
2#![allow(dead_code)]
3
4use super::schemas::{PluginMarketplaceEntry, PluginScope};
5
6/// Get current ISO timestamp.
7pub fn get_current_timestamp() -> String {
8    chrono::Utc::now().to_rfc3339()
9}
10
11/// Validate that a resolved path stays within a base directory.
12pub fn _validate_path_within_base(
13    base_path: &str,
14    relative_path: &str,
15) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
16    let base = std::fs::canonicalize(base_path)?;
17    let resolved = std::fs::canonicalize(std::path::Path::new(base_path).join(relative_path))?;
18
19    let normalized_base = base.to_string_lossy();
20    let normalized_base_with_sep = format!("{}{}", normalized_base, std::path::MAIN_SEPARATOR);
21
22    if !resolved.starts_with(&normalized_base_with_sep) && resolved != base {
23        return Err(format!(
24            "Path traversal detected: \"{}\" would escape the base directory",
25            relative_path
26        )
27        .into());
28    }
29
30    Ok(resolved.to_string_lossy().to_string())
31}
32
33/// Cache a plugin and add it to installed_plugins.json.
34pub async fn cache_and_register_plugin(
35    _plugin_id: &str,
36    _entry: &PluginMarketplaceEntry,
37    _scope: PluginScope,
38    _project_path: Option<&str>,
39    _local_source_path: Option<&str>,
40) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
41    // Stub: simplified implementation
42    Err("cache_and_register_plugin not fully implemented".into())
43}
44
45/// Register a plugin installation without caching.
46pub fn _register_plugin_installation(
47    _plugin_id: &str,
48    _install_path: &str,
49    _version: Option<&str>,
50    _scope: PluginScope,
51    _project_path: Option<&str>,
52) {
53    // Stub
54}
55
56/// Format a failed ResolutionResult into a user-facing message.
57pub fn _format_resolution_error(_r: &super::dependency_resolver::ResolutionResult) -> String {
58    "Unknown resolution error".to_string()
59}