From 4e707ae08e5cb826101e7a510eadee1164341c3c Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Fri, 10 Oct 2025 15:30:58 -0600 Subject: [PATCH] bug: Automatically mark all extracted tools as executable --- src/config/agent.rs | 14 +++++++++++++- src/function.rs | 11 +++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/config/agent.rs b/src/config/agent.rs index 4de8950..db79209 100644 --- a/src/config/agent.rs +++ b/src/config/agent.rs @@ -9,7 +9,8 @@ use anyhow::{Context, Result}; use inquire::{validator::Validation, Text}; use rust_embed::Embed; use serde::{Deserialize, Serialize}; -use std::{fs::read_to_string, path::Path}; +use std::{fs, fs::read_to_string, path::Path}; +use std::ffi::OsStr; const DEFAULT_AGENT_NAME: &str = "rag"; @@ -46,6 +47,11 @@ impl Agent { .ok_or_else(|| anyhow!("Failed to load embedded agent file: {}", file.as_ref()))?; let content = unsafe { std::str::from_utf8_unchecked(&embedded_file.data) }; let file_path = Config::agents_data_dir().join(file.as_ref()); + let file_extension = file_path + .extension() + .and_then(OsStr::to_str) + .map(|s| s.to_lowercase()); + let is_script = matches!(file_extension.as_deref(), Some("sh") | Some("py")); if file_path.exists() { debug!( @@ -59,6 +65,12 @@ impl Agent { info!("Creating agent file: {}", file_path.display()); let mut agent_file = File::create(&file_path)?; agent_file.write_all(content.as_bytes())?; + + #[cfg(unix)] + if is_script { + use std::os::unix::fs::PermissionsExt; + fs::set_permissions(&file_path, fs::Permissions::from_mode(0o755))?; + } } Ok(()) diff --git a/src/function.rs b/src/function.rs index cae2df0..e48672f 100644 --- a/src/function.rs +++ b/src/function.rs @@ -137,6 +137,11 @@ impl Functions { })?; let content = unsafe { std::str::from_utf8_unchecked(&embedded_file.data) }; let file_path = Config::functions_dir().join(file.as_ref()); + let file_extension = file_path + .extension() + .and_then(OsStr::to_str) + .map(|s| s.to_lowercase()); + let is_script = matches!(file_extension.as_deref(), Some("sh") | Some("py")); if file_path.exists() { debug!( @@ -150,6 +155,12 @@ impl Functions { info!("Creating function file: {}", file_path.display()); let mut function_file = File::create(&file_path)?; function_file.write_all(content.as_bytes())?; + + #[cfg(unix)] + if is_script { + use std::os::unix::fs::PermissionsExt; + fs::set_permissions(&file_path, fs::Permissions::from_mode(0o755))?; + } } Ok(())