use std::path::PathBuf;
use std::sync::Arc;
use tokio::sync::mpsc;
use crate::provider::ProviderRegistry;
use crate::session::{ImageAttachment, Session, SessionEvent};
use super::merge::push_or_merge;
use super::worktree::WorktreeState;
pub(super) async fn run_prompt(
session: &mut Session,
prompt: &str,
images: Vec<ImageAttachment>,
event_tx: mpsc::Sender<SessionEvent>,
registry: Arc<ProviderRegistry>,
original_dir: Option<PathBuf>,
) -> anyhow::Result<Session> {
session
.prompt_with_events_and_images(prompt, images, event_tx, registry)
.await
.map(|_| {
session.metadata.directory = original_dir;
session.clone()
})
}
pub(super) async fn handle_worktree_result(
result: &anyhow::Result<Session>,
worktree: Option<WorktreeState>,
prompt: Option<&str>,
) {
let Some((mgr, wt, base_branch)) = worktree else {
return;
};
if result.is_ok() {
push_or_merge(&mgr, &wt, base_branch.as_deref(), prompt).await;
}
if let Err(e) = mgr.cleanup(&wt.name).await {
tracing::warn!(error = %e, "Failed to cleanup TUI worktree");
}
}