Skip to content

Commit 4fd31e1

Browse files
committed
fix: decoupled runtime.Command from SSHConnection
1 parent fdabf85 commit 4fd31e1

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

src/runtime/cmd.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use std::{collections::BTreeMap, fmt};
22

3-
use super::SSHConnection;
4-
53
#[derive(Debug)]
64
pub struct CommandLine {
75
pub sudo: bool,
@@ -111,12 +109,7 @@ impl CommandLine {
111109
args
112110
}
113111

114-
pub async fn execute(&self, ssh: Option<SSHConnection>) -> anyhow::Result<String> {
115-
// execyte via ssh
116-
if let Some(ssh) = ssh {
117-
return ssh.execute(self.sudo, &self.app, &self.args).await;
118-
}
119-
112+
pub async fn execute(&self) -> anyhow::Result<String> {
120113
log::debug!("executing command: {}", self);
121114
log::debug!("full command details: {:?}", self);
122115

@@ -226,7 +219,7 @@ mod tests {
226219
env: BTreeMap::new(),
227220
temp_env_file: None,
228221
};
229-
let result = cmd.execute(None).await.unwrap();
222+
let result = cmd.execute().await.unwrap();
230223
assert_eq!(result, "Hello, World!");
231224
}
232225

@@ -240,7 +233,7 @@ mod tests {
240233
env: BTreeMap::new(),
241234
temp_env_file: None,
242235
};
243-
let result = cmd.execute(None).await.unwrap();
236+
let result = cmd.execute().await.unwrap();
244237
assert!(result.contains("EXIT CODE:"));
245238
assert!(result.contains("ERROR:"));
246239
}
@@ -258,7 +251,7 @@ mod tests {
258251
env: BTreeMap::new(),
259252
temp_env_file: None,
260253
};
261-
let result = cmd.execute(None).await.unwrap();
254+
let result = cmd.execute().await.unwrap();
262255
assert!(result.contains("Hello"));
263256
assert!(result.contains("Error"));
264257
}
@@ -273,7 +266,7 @@ mod tests {
273266
env: BTreeMap::new(),
274267
temp_env_file: None,
275268
};
276-
let result = cmd.execute(None).await;
269+
let result = cmd.execute().await;
277270
assert!(result.is_err());
278271
}
279272

src/runtime/mod.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ pub(crate) async fn execute_call(
8686
let mut needs_container = false;
8787
let mut can_ssh = false;
8888

89+
// if --ssh was provided
8990
if let Some(ssh) = ssh.as_ref() {
90-
// if ssh is set we don't need a container
91+
// check if the app is in $PATH on the ssh host
9192
can_ssh = ssh.app_in_path(&command_line.app).await?;
9293
if !can_ssh {
9394
log::warn!(
@@ -112,6 +113,7 @@ pub(crate) async fn execute_call(
112113
}
113114
}
114115

116+
// wrap the command line in a container if needed
115117
let command_line = if needs_container {
116118
let container = match container {
117119
Some(c) => c,
@@ -159,12 +161,17 @@ pub(crate) async fn execute_call(
159161
}
160162

161163
// finally execute the command line
162-
let content = command_line
163-
.execute(match can_ssh {
164-
true => ssh,
165-
false => None,
166-
})
167-
.await?;
164+
let content = if can_ssh {
165+
// execute via ssh
166+
ssh.as_ref()
167+
.unwrap()
168+
.execute(command_line.sudo, &command_line.app, &command_line.args)
169+
.await?
170+
} else {
171+
// execute locally
172+
command_line.execute().await?
173+
};
174+
168175
Ok(openai::CallResultMessage {
169176
role: "tool".to_string(),
170177
call_id: call.id.clone(),

0 commit comments

Comments
 (0)