use prefix `may_` as indicator for `execute` type fucntions

pull/514/head
sigoden 4 weeks ago
parent 0fc33c819c
commit d7e1c0fe84

@ -1,6 +1,6 @@
use crate::{
config::GlobalConfig,
utils::{dimmed_text, exec_command, indent_text, spawn_command, warning_text},
utils::{dimmed_text, indent_text, run_command, run_command_with_output, warning_text},
};
use anyhow::{anyhow, bail, Context, Result};
@ -38,7 +38,7 @@ pub fn eval_tool_calls(
return Ok(output);
}
calls = ToolCall::dedup(calls);
let parallel = calls.len() > 1 && calls.iter().all(|v| !v.is_execute());
let parallel = calls.len() > 1 && calls.iter().all(|v| !v.is_execute_type());
if parallel {
let (tx, rx) = channel();
let calls_len = calls.len();
@ -237,7 +237,7 @@ impl ToolCall {
} else {
None
};
let output = if self.is_execute() {
let output = if self.is_execute_type() {
let proceed = if stdout().is_terminal() {
Confirm::new(&prompt_text).with_default(true).prompt()?
} else {
@ -247,14 +247,14 @@ impl ToolCall {
if proceed {
#[cfg(windows)]
let name = polyfill_cmd_name(&name, &config.read().function.bin_dir);
spawn_command(&name, &arguments, envs)?;
run_command(&name, &arguments, envs)?;
}
Value::Null
} else {
println!("{}", dimmed_text(&prompt_text));
#[cfg(windows)]
let name = polyfill_cmd_name(&name, &config.read().function.bin_dir);
let (success, stdout, stderr) = exec_command(&name, &arguments, envs)?;
let (success, stdout, stderr) = run_command_with_output(&name, &arguments, envs)?;
if success {
if !stderr.is_empty() {
@ -287,8 +287,8 @@ impl ToolCall {
Ok(output)
}
pub fn is_execute(&self) -> bool {
self.name.starts_with("execute_") || self.name.contains("__execute_")
pub fn is_execute_type(&self) -> bool {
self.name.starts_with("may_") || self.name.contains("__may_")
}
}

@ -21,7 +21,7 @@ use crate::config::{
use crate::function::eval_tool_calls;
use crate::render::{render_error, MarkdownRender};
use crate::repl::Repl;
use crate::utils::{create_abort_signal, extract_block, run_spinner, spawn_command, CODE_BLOCK_RE};
use crate::utils::{create_abort_signal, extract_block, run_command, run_spinner, CODE_BLOCK_RE};
use anyhow::{bail, Result};
use async_recursion::async_recursion;
@ -234,7 +234,7 @@ async fn shell_execute(
match answer {
"✅ Execute" => {
debug!("{} {:?}", shell, &[shell_arg, &eval_str]);
let code = spawn_command(shell, &[shell_arg, &eval_str], None)?;
let code = run_command(shell, &[shell_arg, &eval_str], None)?;
if code != 0 {
process::exit(code);
}

@ -54,7 +54,7 @@ pub fn detect_shell() -> (String, String, &'static str) {
}
}
pub fn spawn_command<T: AsRef<OsStr>>(
pub fn run_command<T: AsRef<OsStr>>(
cmd: &str,
args: &[T],
envs: Option<HashMap<String, String>>,
@ -66,7 +66,7 @@ pub fn spawn_command<T: AsRef<OsStr>>(
Ok(status.code().unwrap_or_default())
}
pub fn exec_command<T: AsRef<OsStr>>(
pub fn run_command_with_output<T: AsRef<OsStr>>(
cmd: &str,
args: &[T],
envs: Option<HashMap<String, String>>,

Loading…
Cancel
Save