Skip to content
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
21 changes: 21 additions & 0 deletions crates/forge_main/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3736,6 +3736,12 @@ impl<A: API + ConsoleWriter + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
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(());
}
}
}

Expand Down Expand Up @@ -4090,6 +4096,21 @@ impl<A: API + ConsoleWriter + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {

/// 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?;
Expand Down
10 changes: 6 additions & 4 deletions shell-plugin/lib/actions/config.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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 </dev/null
_forge_exec_interactive workspace sync --init
}

# Action handler: inits workspace for codebase search
function _forge_action_sync_init() {
echo
_forge_exec workspace init </dev/null
# Use _forge_exec_interactive so that the consent prompt can access /dev/tty
_forge_exec_interactive workspace init
}

# Action handler: Show sync status of workspace files
Expand Down
Loading