Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ winreg = "0.55.0"
schemars = "1.0.4"
jsonschema = "0.30.0"
zip = "2.2.0"
rmcp = { version = "0.7.0", features = ["client", "transport-sse-client-reqwest", "reqwest", "transport-streamable-http-client-reqwest", "transport-child-process", "tower", "auth"] }
rmcp = { version = "0.8.0", features = ["client", "transport-sse-client-reqwest", "reqwest", "transport-streamable-http-client-reqwest", "transport-child-process", "tower", "auth"] }

[workspace.lints.rust]
future_incompatible = "warn"
Expand Down
15 changes: 2 additions & 13 deletions crates/chat-cli/src/cli/agent/root_command_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,8 @@ impl AgentArgs {
Some(AgentSubcommands::Create { name, directory, from }) => {
let mut agents = Agents::load(os, None, true, &mut stderr, mcp_enabled).await.0;
let path_with_file_name = create_agent(os, &mut agents, name.clone(), directory, from).await?;
let editor_cmd = std::env::var("EDITOR").unwrap_or_else(|_| "vi".to_string());
let mut cmd = std::process::Command::new(editor_cmd);

let status = cmd.arg(&path_with_file_name).status()?;
if !status.success() {
bail!("Editor process did not exit with success");
}
crate::util::editor::launch_editor(&path_with_file_name)?;

let Ok(content) = os.fs.read(&path_with_file_name).await else {
bail!(
Expand All @@ -148,13 +143,7 @@ impl AgentArgs {
let _agents = Agents::load(os, None, true, &mut stderr, mcp_enabled).await.0;
let (_agent, path_with_file_name) = Agent::get_agent_by_name(os, &name).await?;

let editor_cmd = std::env::var("EDITOR").unwrap_or_else(|_| "vi".to_string());
let mut cmd = std::process::Command::new(editor_cmd);

let status = cmd.arg(&path_with_file_name).status()?;
if !status.success() {
bail!("Editor process did not exit with success");
}
crate::util::editor::launch_editor(&path_with_file_name)?;

let Ok(content) = os.fs.read(&path_with_file_name).await else {
bail!(
Expand Down
17 changes: 4 additions & 13 deletions crates/chat-cli/src/cli/chat/cli/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,9 @@ impl AgentSubcommand {
let path_with_file_name = create_agent(os, &mut agents, name.clone(), directory, from)
.await
.map_err(|e| ChatError::Custom(Cow::Owned(e.to_string())))?;
let editor_cmd = std::env::var("EDITOR").unwrap_or_else(|_| "vi".to_string());
let mut cmd = std::process::Command::new(editor_cmd);

let status = cmd.arg(&path_with_file_name).status()?;
if !status.success() {
return Err(ChatError::Custom("Editor process did not exit with success".into()));
}
crate::util::editor::launch_editor(&path_with_file_name)
.map_err(|e| ChatError::Custom(Cow::Owned(e.to_string())))?;

let new_agent = Agent::load(
os,
Expand Down Expand Up @@ -253,13 +249,8 @@ impl AgentSubcommand {
.await
.map_err(|e| ChatError::Custom(Cow::Owned(e.to_string())))?;

let editor_cmd = std::env::var("EDITOR").unwrap_or_else(|_| "vi".to_string());
let mut cmd = std::process::Command::new(editor_cmd);

let status = cmd.arg(&path_with_file_name).status()?;
if !status.success() {
return Err(ChatError::Custom("Editor process did not exit with success".into()));
}
crate::util::editor::launch_editor(&path_with_file_name)
.map_err(|e| ChatError::Custom(Cow::Owned(e.to_string())))?;

let updated_agent = Agent::load(
os,
Expand Down
7 changes: 6 additions & 1 deletion crates/chat-cli/src/cli/chat/tools/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,17 @@ pub async fn spawn_agent_process(os: &Os, agent: &str, task: &str) -> Result<Age

// Run Q chat with specific agent in background, non-interactive
let mut cmd = tokio::process::Command::new("q");
cmd.args(["chat", "--agent", agent, task]);
cmd.args(["chat", "--non-interactive"]);
if agent == DEFAULT_AGENT_NAME {
cmd.arg("--trust-all-tools");
}
cmd.args(["--agent", agent, task]);

// Redirect to capture output (runs silently)
cmd.stdout(std::process::Stdio::piped());
cmd.stderr(std::process::Stdio::piped());
cmd.stdin(std::process::Stdio::null()); // No user input
cmd.envs(std::env::vars());

#[cfg(not(windows))]
cmd.process_group(0);
Expand Down
47 changes: 44 additions & 3 deletions crates/chat-cli/src/cli/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use clap::{
Args,
Subcommand,
};
use crossterm::style::Stylize;
use eyre::{
Result,
WrapErr,
Expand Down Expand Up @@ -37,15 +38,15 @@ pub enum SettingsSubcommands {
#[derive(Clone, Debug, Args, PartialEq, Eq)]
#[command(subcommand_negates_reqs = true)]
#[command(args_conflicts_with_subcommands = true)]
#[command(group(ArgGroup::new("vals").requires("key").args(&["value", "delete", "format"])))]
#[command(group(ArgGroup::new("vals").requires("key").args(&["value", "format"])))]
pub struct SettingsArgs {
#[command(subcommand)]
cmd: Option<SettingsSubcommands>,
/// key
key: Option<String>,
/// value
value: Option<String>,
/// Delete a value
/// Delete a key (No value needed)
#[arg(long, short)]
delete: bool,
/// Format of the output
Expand Down Expand Up @@ -87,11 +88,26 @@ impl SettingsArgs {
},
None => {
let Some(key) = &self.key else {
if self.delete {
return Err(eyre::eyre!(
"the argument {} requires a {}\n Usage: q settings {} {}",
"'--delete'".yellow(),
"<KEY>".green(),
"--delete".yellow(),
"<KEY>".green()
));
}
return Ok(ExitCode::SUCCESS);
};

let key = Setting::try_from(key.as_str())?;
match (&self.value, self.delete) {
(Some(_), true) => Err(eyre::eyre!(
"the argument {} cannot be used with {}\n Usage: q settings {} {key}",
"'--delete'".yellow(),
"'[VALUE]'".yellow(),
"--delete".yellow()
)),
(None, false) => match os.database.settings.get(key) {
Some(value) => {
match self.format {
Expand Down Expand Up @@ -147,9 +163,34 @@ impl SettingsArgs {

Ok(ExitCode::SUCCESS)
},
_ => Ok(ExitCode::SUCCESS),
}
},
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[tokio::test]
async fn test_delete_with_value_error() {
let mut os = Os::new().await.unwrap();

let settings_args = SettingsArgs {
cmd: None,
key: Some("chat.defaultAgent".to_string()),
value: Some("test_value".to_string()),
delete: true,
format: OutputFormat::Plain,
};

let result = settings_args.execute(&mut os).await;

assert!(result.is_err());
let error_msg = result.unwrap_err().to_string();
assert!(error_msg.contains("the argument"));
assert!(error_msg.contains("--delete"));
assert!(error_msg.contains("Usage:"));
}
}
39 changes: 39 additions & 0 deletions crates/chat-cli/src/util/editor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use std::path::Path;
use std::process::Command;

/// Launch the user's preferred editor with the given file path.
///
/// This function properly parses the EDITOR environment variable to handle
/// editors that require arguments (e.g., "emacsclient -nw").
///
/// # Arguments
/// * `file_path` - Path to the file to open in the editor
///
/// # Returns
/// * `Ok(())` if the editor was launched successfully and exited with success
/// * `Err` if the editor failed to launch or exited with an error
pub fn launch_editor(file_path: &Path) -> eyre::Result<()> {
let editor_cmd = std::env::var("EDITOR").unwrap_or_else(|_| "vi".to_string());

// Parse the editor command to handle arguments
let mut parts = shlex::split(&editor_cmd).ok_or_else(|| eyre::eyre!("Failed to parse EDITOR command"))?;

if parts.is_empty() {
eyre::bail!("EDITOR environment variable is empty");
}

let editor_bin = parts.remove(0);

let mut cmd = Command::new(editor_bin);
for arg in parts {
cmd.arg(arg);
}

let status = cmd.arg(file_path).status()?;

if !status.success() {
eyre::bail!("Editor process did not exit with success");
}

Ok(())
}
1 change: 1 addition & 0 deletions crates/chat-cli/src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod consts;
pub mod directories;
pub mod editor;
pub mod knowledge_store;
pub mod open;
pub mod pattern_matching;
Expand Down