diff --git a/crates/forge_main/src/ui.rs b/crates/forge_main/src/ui.rs index f5954dbb91..7a0bf8276b 100644 --- a/crates/forge_main/src/ui.rs +++ b/crates/forge_main/src/ui.rs @@ -3736,6 +3736,12 @@ impl A + Send + Sync> UI { let workspace_info = self.api.get_workspace_info(path.clone()).await?; if workspace_info.is_none() { self.on_workspace_init(path.clone()).await?; + // If the workspace still does not exist after init (e.g. user + // declined the consent prompt), abort the sync. + let workspace_info = self.api.get_workspace_info(path.clone()).await?; + if workspace_info.is_none() { + return Ok(()); + } } } @@ -4090,6 +4096,21 @@ impl A + Send + Sync> UI { /// Initialize workspace for a directory without syncing files async fn on_workspace_init(&mut self, path: std::path::PathBuf) -> anyhow::Result<()> { + // Ask for user consent before syncing and sharing directory contents + // with the ForgeCode Service. + let display_path = path.display().to_string(); + let confirmed = ForgeWidget::confirm(format!( + "This will sync and share the contents of '{}' with ForgeCode Services. Do you wish to continue?", + display_path + )) + .with_default(true) + .prompt()?; + + if !confirmed.unwrap_or(false) { + self.writeln_title(TitleFormat::info("Workspace initialization cancelled"))?; + return Ok(()); + } + // Check if auth already exists and create if needed if !self.api.is_authenticated().await? { self.init_forge_services().await?; diff --git a/shell-plugin/lib/actions/config.zsh b/shell-plugin/lib/actions/config.zsh index 4cff73a498..c7869e3c2a 100644 --- a/shell-plugin/lib/actions/config.zsh +++ b/shell-plugin/lib/actions/config.zsh @@ -242,16 +242,18 @@ function _forge_action_suggest_model() { # Action handler: Sync workspace for codebase search function _forge_action_sync() { echo - # Execute sync with stdin redirected to prevent hanging - # Sync doesn't need interactive input, so close stdin immediately + # Use _forge_exec_interactive so that the consent prompt (and any other + # interactive prompts) can access /dev/tty even though ZLE owns the + # terminal's stdin/stdout pipes. # --init initializes the workspace first if it has not been set up yet - _forge_exec workspace sync --init