diff --git a/docs/desktop-coding.md b/docs/desktop-coding.md index 8fdb763..760778d 100644 --- a/docs/desktop-coding.md +++ b/docs/desktop-coding.md @@ -98,13 +98,13 @@ Each refresh checks the checkout in a fresh Codex session. Servers that Huggler ## Find a conversation by status -The conversation sidebar is visible when Bear opens. Use the left sidebar button in the workspace header to hide or show conversations independently of Changes. The sidebar updates even while you work in another conversation. Needs attention and Ready sit at the top. Working, Stash, and Settled sit at the bottom. Click a section heading to collapse or expand it. Each section shows its count and lists the most recently active conversations first. +The conversation sidebar is visible when Bear opens. Use the left sidebar button in the workspace header to hide or show conversations independently of Changes. The sidebar updates even while you work in another conversation. Needs attention and Ready sit at the top. Working, Stash, and Archived sit at the bottom. Click a section heading to collapse or expand it. Each section shows its count and lists the most recently active conversations first. - **Needs attention** shows conversations that need an answer or approval, have a paused queue, or ended in an error. The reason appears below the conversation name. - **Ready** shows new conversations and conversations whose work completed or was stopped. - **Working** shows conversations with queued or active work, including running subagents. By default, only your open conversation appears in this group. A request for your input moves the conversation into **Needs attention** automatically. - **Stash** holds local conversations you want to set aside. Hover over an active conversation and click **Stash** (the inbox icon). Work in progress continues, and the conversation stays stashed across restarts. If a stashed run asks for an answer or approval, its conversation appears in **Needs attention** until the request clears. Expand **Stash** and click **Unstash** (the undo arrow) to return the conversation to the group that matches its current activity. -- **Settled** holds conversations you have marked as finished. Hover over an idle conversation and click its checkmark to settle it. Expand **Settled** to browse its history. Hover over a settled conversation and click its undo arrow to unsettle it. Sending a message also reopens the conversation. Settlement persists across restarts. By default, Bear also checks idle conversations every minute and settles them when their branch’s pull request has merged. The checkout must be clean and its current commit must match the merged PR’s head; reused branches with new work stay open. Turn off **Auto-settle merged PRs** in **Settings → General** to disable this behavior. Active or queued work prevents settlement. +- **Archived** keeps conversations you’ve finished. Hover over an idle conversation and click **Archive**. Bear removes an eligible managed worktree when all conversations sharing it are archived. Local edits, ignored files, unpublished commits, and running workspace activity keep the checkout on disk. Use **Reopen conversation** to restore a reclaimed checkout at its saved commit and continue. Bear can also archive idle conversations after verifying their current commit matches a merged pull request. Turn off **Auto-archive merged PRs** in **Settings → General** to disable this behavior. ## Desktop data directory diff --git a/scripts/check-desktop-history.py b/scripts/check-desktop-history.py index 1570128..900a4ce 100644 --- a/scripts/check-desktop-history.py +++ b/scripts/check-desktop-history.py @@ -163,19 +163,19 @@ def main(): ] run_window(executable, starter_state, [ {"resize": [640, 440]}, - {"hover": "thread/" + first}, {"click": "Settle/" + first}, - {"in_lower_half": "section/Settled/1"}, {"absent": "thread/" + first}, - {"hover": "thread/Review my changes"}, {"click": "Settle/Review my changes"}, - {"absent": "section/Ready/1"}, {"in_lower_half": "section/Settled/2"}, - {"hover": "thread/Review my changes"}, {"click": "Unsettle/Review my changes"}, + {"hover": "thread/" + first}, {"click": "Archive/" + first}, + {"in_lower_half": "section/Archived/1"}, {"absent": "thread/" + first}, + {"hover": "thread/Review my changes"}, {"click": "Archive/Review my changes"}, + {"absent": "section/Ready/1"}, {"in_lower_half": "section/Archived/2"}, + {"hover": "thread/Review my changes"}, {"click": "Reopen/Review my changes"}, ], env) run_window(executable, starter_state, [ - {"click": "section/Settled/1"}, {"click": "thread/" + first}, - {"see": "Codex/reply " + first}, {"hover": "thread/" + first}, {"click": "Unsettle/" + first}, - {"see": "Ready/" + first + "/Completed"}, {"hover": "thread/" + first}, {"click": "Settle/" + first}, - {"see": "Settled/" + first + "/Settled"}, *send_message("Continue"), + {"click": "section/Archived/1"}, {"click": "thread/" + first}, + {"see": "Codex/reply " + first}, {"hover": "thread/" + first}, {"click": "Reopen/" + first}, + {"see": "Ready/" + first + "/Completed"}, {"hover": "thread/" + first}, {"click": "Archive/" + first}, + {"see": "Archived/" + first + "/Archived"}, *send_message("Continue"), {"see": "Codex/reply Continue"}, {"see": "Ready/" + first + "/Completed"}, - {"absent": "section/Settled/1"}, + {"absent": "section/Archived/1"}, ], env) attachment = checkout / "notes.txt" attachment.write_text("attachment fixture") diff --git a/scripts/check-desktop-pull-requests.py b/scripts/check-desktop-pull-requests.py index 7058a70..7839445 100644 --- a/scripts/check-desktop-pull-requests.py +++ b/scripts/check-desktop-pull-requests.py @@ -467,11 +467,11 @@ def assert_settled(expected): assert_settled(False) # Exercise the actual preference control and its persisted opt-out. show(pr, {"click": "Settings"}, {"click": "General"}, - {"click": "Auto-settle merged PRs"}) + {"click": "Auto-archive merged PRs"}) assert json.loads(preferences.read_text())["autoSettleMergedPrs"] is True for change in ("edit", "switch"): - show(dict(merged, fixture_change=change), {"see": "Merged"}, {"absent": "section/Settled/2"}) + show(dict(merged, fixture_change=change), {"see": "Merged"}, {"absent": "section/Archived/2"}) assert "fixture_change" not in json.loads(fixture.read_text()) assert_settled(False) (checkout / "new-work.txt").unlink(missing_ok=True) @@ -479,10 +479,10 @@ def assert_settled(expected): show(dict(pr, state="CLOSED"), {"see": "PR closed"}) assert_settled(False) - show(merged, {"see": "section/Settled/2"}) + show(merged, {"see": "section/Archived/2"}) assert_settled(True) show(pr, {"click": "Settings"}, {"click": "General"}, - {"click": "Auto-settle merged PRs"}) + {"click": "Auto-archive merged PRs"}) assert json.loads(preferences.read_text())["autoSettleMergedPrs"] is False with sqlite3.connect(state / "huggler.sqlite3") as db: db.execute("UPDATE thread SET settled=0") diff --git a/src/changes.rs b/src/changes.rs index c6cc06a..4cc9ebb 100644 --- a/src/changes.rs +++ b/src/changes.rs @@ -6,8 +6,8 @@ use crate::{ ui::{hint, keyboard_scroll_viewport, label}, }; use anyhow::Context as _; -pub(crate) use approvals::{ReviewRepository, ReviewRow}; use approvals::{Approval, Approvals}; +pub(crate) use approvals::{ReviewRepository, ReviewRow}; use gpui::{prelude::*, *}; use gpui_component::{ ActiveTheme, Disableable, Icon, IconName, Sizable, WindowExt, @@ -433,10 +433,15 @@ impl Changes { rows.into_iter() .map(|row| { let path = row.workspace_path.display(); - row.repository.checkout(&root) - .and_then(|checkout| PreparedRevert::prepare(&checkout, row.head, row.file)) + row.repository + .checkout(&root) + .and_then(|checkout| { + PreparedRevert::prepare(&checkout, row.head, row.file) + }) .map(|target| (row.repository, Arc::new(target))) - .map_err(|error| format!("Could not prepare to revert {path}. {error:#}")) + .map_err(|error| { + format!("Could not prepare to revert {path}. {error:#}") + }) }) .collect::, _>>() }); @@ -513,12 +518,7 @@ impl Changes { }); } - fn revert( - &mut self, - targets: RevertTargets, - bulk: bool, - cx: &mut Context, - ) { + fn revert(&mut self, targets: RevertTargets, bulk: bool, cx: &mut Context) { if self.mutation.is_some() { return; } @@ -528,7 +528,8 @@ impl Changes { let mut paths = Vec::with_capacity(targets.len()); for (repository, target) in targets.iter() { let path = approvals::workspace_path(&repository.folder, target.path()); - let result = repository.checkout(&root) + let result = repository + .checkout(&root) .and_then(|checkout| git::revert_file(&checkout, target)); if let Err(error) = result { let failure = format!("Could not revert {}. {error:#}", path.display()); @@ -622,11 +623,12 @@ impl Changes { .map(|row| { let path = &row.workspace_path; let fingerprint = git::diff_fingerprint( - &row.repository.checkout(&root)?, &row.base, &row.head, &row.file, + &row.repository.checkout(&root)?, + &row.base, + &row.head, + &row.file, ) - .with_context(|| { - format!("Could not read the diff for {}", path.display()) - })?; + .with_context(|| format!("Could not read the diff for {}", path.display()))?; Ok(( approvals::path_key(path), Some(Approval { scope, fingerprint }), diff --git a/src/conversation.rs b/src/conversation.rs index 7d837f4..8f968c9 100644 --- a/src/conversation.rs +++ b/src/conversation.rs @@ -471,6 +471,80 @@ impl Desktop { view } + fn checkout_unavailable_for(&self, thread: &ThreadId) -> bool { + !self.workspaces[thread].root.is_dir() + || self + .runtime + .thread_checkout_is_archived(thread) + .unwrap_or(false) + } + + fn has_running_workspace_terminal(&self, thread: &ThreadId, cx: &App) -> bool { + #[cfg(target_os = "macos")] + { + let Ok(root) = self.runtime.thread_checkout(thread) else { + return false; + }; + self.workspaces.values().any(|workspace| { + workspace.root.starts_with(&root) && workspace.terminal.has_running_terminal(cx) + }) + } + #[cfg(not(target_os = "macos"))] + { + let _ = (thread, cx); + false + } + } + + fn dispatch_archive_action( + &mut self, + thread: ThreadId, + action: Action, + cx: &mut Context, + ) { + let automatic = matches!( + &action, + Action::ArchiveConversation { + merged_tip: Some(_) + } + ); + if matches!(&action, Action::ArchiveConversation { .. }) + && self.has_running_workspace_terminal(&thread, cx) + { + if !automatic { + self.report_error( + "Close the running workspace terminal before archiving.".into(), + cx, + ); + } + return; + } + let runtime = self.runtime.clone(); + let task = self.executor.spawn_blocking(move || { + runtime + .dispatch(Command { + id: CommandId(Uuid::new_v4().to_string()), + thread_id: thread, + action, + }) + .map(|_| ()) + }); + cx.spawn(async move |view, cx| { + let result = task + .await + .unwrap_or_else(|error| Err(huggler::Error::Worker(error.to_string()))); + let _ = view.update(cx, |view, cx| { + if let Some(current) = &view.current { + view.checkout_unavailable = view.checkout_unavailable_for(¤t.id); + } + if !automatic || !matches!(result, Err(huggler::Error::Busy)) { + view.report(result, cx); + } + }); + }) + .detach(); + } + fn report(&mut self, result: huggler::Result<()>, cx: &mut Context) { if let Err(error) = result { self.report_error(error.to_string(), cx); @@ -598,7 +672,7 @@ impl Desktop { .show_chat(); if self.current.as_ref().is_some_and(|thread| thread.id == id) { self.focus_workspace(window, cx); - self.checkout_unavailable = !self.workspaces[&id].root.is_dir(); + self.checkout_unavailable = self.checkout_unavailable_for(&id); self.watch_pull_request(cx); return Ok(()); } @@ -613,7 +687,7 @@ impl Desktop { self.command_log = None; self.expanded_activity.clear(); self.full_messages.clear(); - self.checkout_unavailable = !self.workspaces[&id].root.is_dir(); + self.checkout_unavailable = self.checkout_unavailable_for(&id); self.prompt = self.workspaces[&id].draft.clone(); self.suggestions = Default::default(); self.model_picker = None; @@ -842,11 +916,7 @@ impl Desktop { .iter() .any(|item| &item.message.id == id) }); - if thread.latest_run.as_ref().map(|r| (&r.id, r.status)) - != old.latest_run.as_ref().map(|r| (&r.id, r.status)) - { - self.checkout_unavailable = !self.workspaces[&thread.id].root.is_dir(); - } + self.checkout_unavailable = self.checkout_unavailable_for(&thread.id); let previous_sequence = old.history.sequence; self.current = Some(thread); self.refresh_traces(Some(previous_sequence)); @@ -1386,10 +1456,10 @@ impl Desktop { return Ok(()); } if thread.foreground_run.is_none() && thread.queued_count == 0 { - let root = &self.workspaces[&thread.id].root; - self.checkout_unavailable = !root.is_dir(); - if self.checkout_unavailable { - // Keep the draft while the user restores the checkout. + let archived = self.runtime.thread_checkout_is_archived(&thread.id)?; + self.checkout_unavailable = archived || !self.workspaces[&thread.id].root.is_dir(); + if self.checkout_unavailable && !archived { + // Keep the draft when the checkout was removed outside Bear. cx.notify(); return Ok(()); } diff --git a/src/conversation/document_tabs.rs b/src/conversation/document_tabs.rs index e169689..3b1d656 100644 --- a/src/conversation/document_tabs.rs +++ b/src/conversation/document_tabs.rs @@ -52,7 +52,9 @@ impl Document { fn matches(&self, other: &Self) -> bool { match (self, other) { (Self::File(a), Self::File(b)) => a == b, - (Self::Diff(a), Self::Diff(b)) => a.workspace_path == b.workspace_path && a.scope == b.scope, + (Self::Diff(a), Self::Diff(b)) => { + a.workspace_path == b.workspace_path && a.scope == b.scope + } (Self::Trace(a), Self::Trace(b)) => a.run_id == b.run_id && a.item.id == b.item.id, _ => false, } diff --git a/src/conversation/launch_workspace.rs b/src/conversation/launch_workspace.rs index 45bcbfe..c522ac5 100644 --- a/src/conversation/launch_workspace.rs +++ b/src/conversation/launch_workspace.rs @@ -1,6 +1,6 @@ use super::*; -use anyhow::{Context as _, ensure}; use crate::changes::ReviewRepository; +use anyhow::{Context as _, ensure}; use gpui_component::{ IndexPath, list::{List, ListDelegate, ListEvent, ListItem}, @@ -420,7 +420,10 @@ impl ProjectWorktrees { report_stage: impl Fn(WorktreeStage), ) -> anyhow::Result { let mut sources = Vec::with_capacity(repositories.len()); - for (root, folder) in repositories.iter().zip(project_checkout_names(repositories)) { + for (root, folder) in repositories + .iter() + .zip(project_checkout_names(repositories)) + { let branches = git::branches(root) .with_context(|| format!("Could not open repository {}", root.display()))?; ensure!( @@ -429,7 +432,10 @@ impl ProjectWorktrees { root.display() ); let base = branches.default.with_context(|| { - format!("Create an initial commit in {} before starting this project.", root.display()) + format!( + "Create an initial commit in {} before starting this project.", + root.display() + ) })?; sources.push((root, folder, base)); } @@ -451,7 +457,11 @@ impl ProjectWorktrees { fn checkout(&mut self, sources: Vec<(&PathBuf, PathBuf, git::Branch)>) -> anyhow::Result<()> { for (source, folder, base) in sources { let path = self.project.root.join(folder); - ensure!(!path.try_exists()?, "Workspace path {} is already in use.", path.display()); + ensure!( + !path.try_exists()?, + "Workspace path {} is already in use.", + path.display() + ); self.checkouts.push((source.clone(), path.clone())); git::add_project_worktree(source, &path, &base.reference) .with_context(|| format!("Could not create a worktree for {}", source.display()))?; @@ -493,7 +503,10 @@ impl ProjectWorktrees { if failures.is_empty() { error } else { - anyhow::anyhow!("{error:#}. Workspace cleanup failed: {}", failures.join("; ")) + anyhow::anyhow!( + "{error:#}. Workspace cleanup failed: {}", + failures.join("; ") + ) } } } diff --git a/src/conversation/mcp_status.rs b/src/conversation/mcp_status.rs index 66b5658..7626eac 100644 --- a/src/conversation/mcp_status.rs +++ b/src/conversation/mcp_status.rs @@ -63,10 +63,17 @@ impl Desktop { } else { let root = source.1.clone(); let command = command.to_owned(); + let runtime = self.runtime.clone(); if let Err(error) = cx.open_window(WindowOptions::default(), move |window, cx| { window.set_window_title("MCP authentication"); - let shell = super::terminal::TerminalView::start(&root, Some(&command), window, cx) - .map_err(|error| format!("{error:#}")); + let shell = super::terminal::TerminalView::start( + &runtime, + &root, + Some(&command), + window, + cx, + ) + .map_err(|error| format!("{error:#}")); if let Ok(shell) = &shell { shell.read(cx).focus(window); } diff --git a/src/conversation/project_actions.rs b/src/conversation/project_actions.rs index a4ec370..3efb481 100644 --- a/src/conversation/project_actions.rs +++ b/src/conversation/project_actions.rs @@ -179,11 +179,14 @@ impl Desktop { thread: Some(target), root, }; - checkout.has_current_merged_pr().await.then_some(sequence) + checkout + .current_merged_pr_tip() + .await + .map(|tip| (sequence, tip)) }) .await .unwrap_or(None); - if let Some(sequence) = checked_sequence + if let Some((sequence, tip)) = checked_sequence && view .update(cx, |view, cx| { if view.settings.read(cx).preferences().auto_settle_merged_prs @@ -199,15 +202,13 @@ impl Desktop { .detail(&id, None, "", 1) .is_ok_and(|thread| thread.history.sequence == sequence) { - // Busy means work arrived after the list snapshot; retry next poll. - if let Err(error) = view.runtime.dispatch(Command { - id: CommandId(Uuid::new_v4().to_string()), - thread_id: id, - action: Action::SetSettled { settled: true }, - }) && !matches!(error, huggler::Error::Busy) - { - view.report(Err(error), cx); - } + view.dispatch_archive_action( + id, + Action::ArchiveConversation { + merged_tip: Some(tip), + }, + cx, + ); } }) .is_err() diff --git a/src/conversation/projects.rs b/src/conversation/projects.rs index 39e8b20..eccea09 100644 --- a/src/conversation/projects.rs +++ b/src/conversation/projects.rs @@ -127,9 +127,9 @@ impl ListDelegate for ProjectPicker { .enumerate() .filter_map(|(index, project)| { (project.name.to_lowercase().contains(&query) - || project.checkouts().any(|root| { - root.to_string_lossy().to_lowercase().contains(&query) - })) + || project + .checkouts() + .any(|root| root.to_string_lossy().to_lowercase().contains(&query))) .then_some(index) }) .collect(); @@ -295,7 +295,11 @@ impl Desktop { .icon(IconName::Minus) .label("Start without a project") .on_click(cx.listener(|view, _, window, cx| { - view.choose_checkout(CheckoutSelection::Checkout(PathBuf::new()), window, cx); + view.choose_checkout( + CheckoutSelection::Checkout(PathBuf::new()), + window, + cx, + ); })) )), ), @@ -387,10 +391,12 @@ impl Desktop { view.report_error(format!("{error:#}"), cx); } else { let selection = if save { - let project = view.settings.read(cx).saved_checkout_project(root); - CheckoutSelection::Project( - project.map_or_else(|| root.clone(), |project| project.root.clone()), - ) + let project = + view.settings.read(cx).saved_checkout_project(root); + CheckoutSelection::Project(project.map_or_else( + || root.clone(), + |project| project.root.clone(), + )) } else { CheckoutSelection::Checkout(root.clone()) }; diff --git a/src/conversation/sidebar.rs b/src/conversation/sidebar.rs index a982359..525131b 100644 --- a/src/conversation/sidebar.rs +++ b/src/conversation/sidebar.rs @@ -140,7 +140,7 @@ pub(super) enum Section { Attention, Ready, Working, - Settled, + Archived, Stash, } @@ -150,7 +150,7 @@ impl Section { Self::Attention => "Needs attention", Self::Ready => "Ready", Self::Working => "Working", - Self::Settled => "Settled", + Self::Archived => "Archived", Self::Stash => "Stash", } } @@ -160,7 +160,7 @@ impl Section { Self::Attention => (IconName::TriangleAlert, 0x9a470c, 0xf6aa61), Self::Ready => (IconName::ArrowRight, 0x177243, 0x63ce91), Self::Working => (IconName::LoaderCircle, 0x285eaa, 0x7fb3ff), - Self::Settled => (IconName::Check, 0x5d6576, 0xaaa7bc), + Self::Archived => (IconName::Check, 0x5d6576, 0xaaa7bc), Self::Stash => { return Icon::new(IconName::Inbox) .small() @@ -184,7 +184,7 @@ fn activity(thread: &ConversationSummary, stashed: bool) -> (Section, &'static s return (Section::Stash, "Stashed"); } if thread.settled { - return (Section::Settled, "Settled"); + return (Section::Archived, "Archived"); } match thread.status { Some(RunStatus::Failed) => (Section::Attention, "Run failed"), @@ -251,7 +251,7 @@ impl Desktop { Section::Ready, Section::Working, Section::Stash, - Section::Settled, + Section::Archived, ] { // Keep the space above the lower groups even when Working is empty. if section == Section::Working { @@ -378,7 +378,7 @@ impl Desktop { ) }); let settled = thread.settled; - let action = if settled { "Unsettle" } else { "Settle" }; + let action = if settled { "Reopen" } else { "Archive" }; let group = "conversation-row"; let enabled = settled || (!thread.needs_approval @@ -434,15 +434,12 @@ impl Desktop { .disabled(!enabled) .on_click(cx.listener(move |view, _, _, cx| { cx.stop_propagation(); - let result = view - .runtime - .dispatch(Command { - id: CommandId(Uuid::new_v4().to_string()), - thread_id: target.clone(), - action: Action::SetSettled { settled: !settled }, - }) - .map(|_| ()); - view.report(result, cx); + let action = if settled { + Action::SetSettled { settled: false } + } else { + Action::ArchiveConversation { merged_tip: None } + }; + view.dispatch_archive_action(target.clone(), action, cx); })) ); control!( diff --git a/src/conversation/suggestions.rs b/src/conversation/suggestions.rs index 08dee5e..c7b1eb6 100644 --- a/src/conversation/suggestions.rs +++ b/src/conversation/suggestions.rs @@ -198,9 +198,12 @@ fn checkout_paths( fn project_paths(repositories: &[PathBuf]) -> anyhow::Result> { let mut matches = Vec::new(); - for (source, folder) in repositories - .iter() - .zip(super::launch_workspace::project_checkout_names(repositories)) + for (source, folder) in + repositories + .iter() + .zip(super::launch_workspace::project_checkout_names( + repositories, + )) { let base = git::branches(source)?.default; let Some(base) = base else { continue }; @@ -601,7 +604,8 @@ impl Desktop { } else { let kind = menu.trigger.kind; let starter = self.current.is_none(); - let repositories = self.launch_project(cx) + let repositories = self + .launch_project(cx) .filter(|project| starter && !project.repositories.is_empty()) .map(|project| project.checkouts().cloned().collect::>()) .unwrap_or_default(); diff --git a/src/conversation/terminal.rs b/src/conversation/terminal.rs index 1cbbc64..e37a5ed 100644 --- a/src/conversation/terminal.rs +++ b/src/conversation/terminal.rs @@ -40,10 +40,12 @@ struct Session { _reader: Task<()>, _writer: Task<()>, pty: Pty, + _checkout_lease: huggler::services::CheckoutLease, } impl TerminalView { pub(super) fn start( + runtime: &huggler::Huggler, root: &Path, command: Option<&str>, window: &mut Window, @@ -59,6 +61,7 @@ impl TerminalView { let mut emulator = Emulator::new(size.cols, size.rows)?; palette.apply(&mut emulator); + let checkout_lease = runtime.lease_checkout(root)?; let (pty, io) = Pty::spawn(root, size, command)?; Ok(cx.new(move |cx: &mut Context| { let (input, writes) = channel::bounded::>(128); @@ -188,6 +191,7 @@ impl TerminalView { _reader: reader, _writer: writer, pty, + _checkout_lease: checkout_lease, }), status: None, composition: String::new(), diff --git a/src/conversation/terminal_pane.rs b/src/conversation/terminal_pane.rs index c4f5df4..ea92746 100644 --- a/src/conversation/terminal_pane.rs +++ b/src/conversation/terminal_pane.rs @@ -44,6 +44,14 @@ impl TerminalPane { self.active = None; } + pub(super) fn has_running_terminal(&self, cx: &App) -> bool { + self.tabs.iter().any(|tab| { + tab.shell + .as_ref() + .is_ok_and(|terminal| terminal.read(cx).is_running()) + }) + } + pub(super) fn is_focused(&self, window: &Window, cx: &App) -> bool { self.active_tab() .and_then(|tab| tab.shell.as_ref().ok()) @@ -105,7 +113,7 @@ impl Desktop { TerminalLaunch::Action(command) => Some(command), _ => None, }; - let shell = TerminalView::start(&workspace.root, command, window, cx) + let shell = TerminalView::start(&self.runtime, &workspace.root, command, window, cx) .map_err(|error| format!("{error:#}")); if let Ok(terminal) = &shell { cx.subscribe(terminal, |_, _, _: &StatusChanged, cx| cx.notify()) diff --git a/src/conversation/transcript.rs b/src/conversation/transcript.rs index 2b8b723..d826cbe 100644 --- a/src/conversation/transcript.rs +++ b/src/conversation/transcript.rs @@ -504,7 +504,36 @@ impl Desktop { .filter(|(_, error)| error.after.is_none()) .map(|error| error_row(error, cx)), ); - if self.checkout_unavailable { + if self.checkout_unavailable + && self + .runtime + .thread_checkout_is_archived(&thread.id) + .unwrap_or(false) + { + let id = thread.id.clone(); + let reopen = control!( + "Reopen conversation", + Button::new("reopen-archived-conversation") + .label("Reopen conversation") + .on_click(cx.listener(move |view, _, _, cx| { + view.dispatch_archive_action( + id.clone(), + Action::SetSettled { settled: false }, + cx, + ); + })) + ); + tail.push( + v_flex() + .w(response_width) + .gap_2() + .child(hint( + "Reopen to restore the workspace and continue this conversation.", + cx, + )) + .child(h_flex().child(reopen)), + ); + } else if self.checkout_unavailable { tail.push( v_flex() .w(response_width) diff --git a/src/github.rs b/src/github.rs index 6fbecb8..a3e89bb 100644 --- a/src/github.rs +++ b/src/github.rs @@ -274,14 +274,15 @@ impl PullRequestTarget { impl Checkout { /// Recheck the local checkout after the network lookup before applying policy. - pub async fn has_current_merged_pr(&self) -> bool { + pub async fn current_merged_pr_tip(&self) -> Option { let Status::Found { branch, pr, .. } = self.status().await else { - return false; + return None; }; - pr.state() == PullRequestState::Merged + (pr.state() == PullRequestState::Merged && pr.head_commit() == branch.local_oid && git::has_uncommitted_changes(&self.root).is_ok_and(|dirty| !dirty) - && git::github_branch(&self.root).is_ok_and(|current| current.same_target(&branch)) + && git::github_branch(&self.root).is_ok_and(|current| current.same_target(&branch))) + .then_some(branch.local_oid) } pub async fn status(&self) -> Status { diff --git a/src/settings/general.rs b/src/settings/general.rs index 9bbd776..975987d 100644 --- a/src/settings/general.rs +++ b/src/settings/general.rs @@ -98,9 +98,9 @@ impl Settings { }); v_flex() .child(setting( - "Auto-settle merged PRs", - "Move idle conversations to Settled when their pull request is merged. Checks all conversations every minute.", - control!("Auto-settle merged PRs", toggle("auto-settle-merged-prs", "Auto-settle merged PRs", self.prefs.auto_settle_merged_prs) + "Auto-archive merged PRs", + "Archive idle conversations when their pull request is merged and remove eligible worktrees.", + control!("Auto-archive merged PRs", toggle("auto-settle-merged-prs", "Auto-archive merged PRs", self.prefs.auto_settle_merged_prs) .on_click(cx.listener(|view, _, _, cx| { let mut prefs = view.prefs.clone(); prefs.auto_settle_merged_prs = !prefs.auto_settle_merged_prs;