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
4 changes: 2 additions & 2 deletions docs/desktop-coding.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 10 additions & 10 deletions scripts/check-desktop-history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions scripts/check-desktop-pull-requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,22 +467,22 @@ 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)
subprocess.run(["git", "-C", checkout, "switch", "-q", "review"], check=True)

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")
Expand Down
32 changes: 17 additions & 15 deletions src/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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::<Result<Arc<[_]>, _>>()
});
Expand Down Expand Up @@ -513,12 +518,7 @@ impl Changes {
});
}

fn revert(
&mut self,
targets: RevertTargets,
bulk: bool,
cx: &mut Context<Self>,
) {
fn revert(&mut self, targets: RevertTargets, bulk: bool, cx: &mut Context<Self>) {
if self.mutation.is_some() {
return;
}
Expand All @@ -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());
Expand Down Expand Up @@ -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 }),
Expand Down
92 changes: 81 additions & 11 deletions src/conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self>,
) {
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(&current.id);
}
if !automatic || !matches!(result, Err(huggler::Error::Busy)) {
view.report(result, cx);
}
});
})
.detach();
}

fn report(&mut self, result: huggler::Result<()>, cx: &mut Context<Self>) {
if let Err(error) = result {
self.report_error(error.to_string(), cx);
Expand Down Expand Up @@ -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(());
}
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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(());
}
Expand Down
4 changes: 3 additions & 1 deletion src/conversation/document_tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
23 changes: 18 additions & 5 deletions src/conversation/launch_workspace.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -420,7 +420,10 @@ impl ProjectWorktrees {
report_stage: impl Fn(WorktreeStage),
) -> anyhow::Result<Self> {
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!(
Expand All @@ -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));
}
Expand All @@ -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()))?;
Expand Down Expand Up @@ -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("; ")
)
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/conversation/mcp_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading
Loading