Skip to content

Commit 20e07cd

Browse files
committed
fix: fallback to default behaviour if app not in PATH on the ssh host
1 parent b1653f8 commit 20e07cd

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

src/runtime/mod.rs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,34 @@ pub(crate) async fn execute_call(
8383

8484
// validate runtime requirements
8585
let container = function.function.container.as_ref();
86-
let needs_container = ssh.is_none() // if ssh is set we don't need a container
87-
&& (
86+
let mut needs_container = false;
87+
let mut can_ssh = false;
88+
89+
if let Some(ssh) = ssh.as_ref() {
90+
// if ssh is set we don't need a container
91+
can_ssh = ssh.app_in_path(&command_line.app).await?;
92+
if !can_ssh {
93+
log::warn!(
94+
"{} not found in $PATH on {}",
95+
command_line.app,
96+
ssh.to_string()
97+
);
98+
}
99+
}
100+
101+
// we are not going to use ssh, so we need to check if we need a container
102+
if !can_ssh {
103+
if command_line.sudo && !interactive {
88104
// we're running in non-interactive mode, can't sudo
89-
(command_line.sudo && !interactive)
90-
// app not in $PATH
91-
|| !command_line.app_in_path
105+
needs_container = true;
106+
} else if !command_line.app_in_path {
107+
// app not in $PATH, we need a container
108+
needs_container = true;
109+
} else if container.is_some() && container.unwrap().force {
92110
// forced container use
93-
|| (container.is_some() && container.unwrap().force)
94-
);
111+
needs_container = true;
112+
}
113+
}
95114

96115
let command_line = if needs_container {
97116
let container = match container {
@@ -116,7 +135,7 @@ pub(crate) async fn execute_call(
116135
command_line
117136
};
118137

119-
if ssh.is_some() {
138+
if can_ssh {
120139
log::warn!(
121140
"executing (as {}): {}",
122141
ssh.as_ref().unwrap().to_string(),
@@ -140,7 +159,12 @@ pub(crate) async fn execute_call(
140159
}
141160

142161
// finally execute the command line
143-
let content = command_line.execute(ssh).await?;
162+
let content = command_line
163+
.execute(match can_ssh {
164+
true => ssh,
165+
false => None,
166+
})
167+
.await?;
144168
Ok(openai::CallResultMessage {
145169
role: "tool".to_string(),
146170
call_id: call.id.clone(),

src/runtime/ssh.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ impl SSHConnection {
139139

140140
Ok(())
141141
}
142+
143+
pub(crate) async fn app_in_path(&self, app: &str) -> anyhow::Result<bool> {
144+
let result = self
145+
.client()
146+
.await?
147+
.execute(&format!("which {}", app))
148+
.await?;
149+
150+
Ok(result.exit_status == 0)
151+
}
142152
}
143153

144154
impl std::fmt::Display for SSHConnection {

0 commit comments

Comments
 (0)