Skip to content

fix: use chat within bundle instead of .local/bin on MacOS #1839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2025
Merged
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
25 changes: 21 additions & 4 deletions crates/q_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ use fig_util::{
system_info,
};
use internal::InternalSubcommand;
use macos_utils::bundle::get_bundle_path_for_executable;
use serde::Serialize;
use tokio::signal::ctrl_c;
use tracing::{
Expand Down Expand Up @@ -195,15 +196,16 @@ pub enum CliRootCommands {
/// Open the dashboard
Dashboard,
/// AI assistant in your terminal
#[command(disable_help_flag = true)]
Chat {
/// Args for the chat command
/// Args for the chat subcommand
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
/// Model Context Protocol (MCP)
#[command(disable_help_flag = true)]
Mcp {
/// Args for the MCP subcommand (passed through to `qchat mcp …`)
/// Args for the MCP subcommand
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},
Expand Down Expand Up @@ -352,11 +354,18 @@ impl Cli {
CliRootCommands::Telemetry(subcommand) => subcommand.execute().await,
CliRootCommands::Version { changelog } => Self::print_version(changelog),
CliRootCommands::Dashboard => launch_dashboard(false).await,
CliRootCommands::Chat { args } => Self::execute_chat("chat", Some(args), true).await,
CliRootCommands::Chat { args } => {
if args.iter().any(|arg| ["--help", "-h"].contains(&arg.as_str())) {
return Self::execute_chat("chat", Some(vec!["--help".to_owned()]), false).await;
}

Self::execute_chat("chat", Some(args), true).await
},
CliRootCommands::Mcp { args } => {
if args.iter().any(|arg| ["--help", "-h"].contains(&arg.as_str())) {
return Self::execute_chat("mcp", Some(vec!["--help".to_owned()]), false).await;
}

Self::execute_chat("mcp", Some(args), true).await
},
CliRootCommands::Inline(subcommand) => subcommand.execute(&cli_context).await,
Expand All @@ -367,6 +376,14 @@ impl Cli {
}

pub async fn execute_chat(subcmd: &str, args: Option<Vec<String>>, enforce_login: bool) -> Result<ExitCode> {
cfg_if::cfg_if! {
if #[cfg(target_os = "macos")] {
let path = get_bundle_path_for_executable(CHAT_BINARY_NAME).unwrap_or(home_local_bin()?.join(CHAT_BINARY_NAME));
} else {
let path = home_local_bin()?.join(CHAT_BINARY_NAME);
}
}

if enforce_login {
assert_logged_in().await?;
}
Expand All @@ -382,7 +399,7 @@ impl Cli {
}
}

let mut cmd = tokio::process::Command::new(home_local_bin()?.join(CHAT_BINARY_NAME));
let mut cmd = tokio::process::Command::new(&path);
cmd.arg(subcmd);
if let Some(args) = args {
cmd.args(args);
Expand Down
21 changes: 8 additions & 13 deletions crates/q_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,6 @@ fn main() -> Result<ExitCode> {
Some("init" | "_" | "internal" | "completion" | "hook" | "chat")
);

let runtime = if multithread {
tokio::runtime::Builder::new_multi_thread()
} else {
tokio::runtime::Builder::new_current_thread()
}
.enable_all()
.build()?;

// Hack as clap doesn't expose a custom command help.
if subcommand.as_deref() == Some("chat") && args.any(|arg| ["--help", "-h"].contains(&arg.as_str())) {
runtime.block_on(cli::Cli::execute_chat("chat", Some(vec!["--help".to_owned()]), true))?;
}

let parsed = match cli::Cli::try_parse() {
Ok(cli) => cli,
Err(err) => {
Expand Down Expand Up @@ -73,6 +60,14 @@ fn main() -> Result<ExitCode> {

let verbose = parsed.verbose > 0;

let runtime = if multithread {
tokio::runtime::Builder::new_multi_thread()
} else {
tokio::runtime::Builder::new_current_thread()
}
.enable_all()
.build()?;

let result = runtime.block_on(async {
let result = parsed.execute().await;
fig_telemetry::finish_telemetry().await;
Expand Down
Loading