diff --git a/crates/agentdeck-gui/src/api.rs b/crates/agentdeck-gui/src/api.rs index faf493d..e394602 100644 --- a/crates/agentdeck-gui/src/api.rs +++ b/crates/agentdeck-gui/src/api.rs @@ -596,6 +596,8 @@ pub(crate) mod fake { made: Mutex, /// Why the next write fails, if it should. failure: Mutex>, + /// Why the next snapshot read fails, if it should. + read_failure: Mutex>, /// The workspaces asked for, in order. pub made_workspaces: Mutex>, /// The PR syncs asked for, in order: whether each was full. @@ -708,6 +710,11 @@ pub(crate) mod fake { *self.failure.lock().unwrap() = Some(anyhow::Error::msg(reason.to_owned())); } + /// Fails the next snapshot read with `reason`. + pub fn fail_next_read(&self, reason: &str) { + *self.read_failure.lock().unwrap() = Some(anyhow::Error::msg(reason.to_owned())); + } + /// Fails the next write as the daemon refuses one: `message`, with `code`. pub fn refuse_next(&self, code: &str, message: &str) { let refusal = ApiError { @@ -930,6 +937,9 @@ pub(crate) mod fake { impl Api for FakeApi { fn snapshot(&self, _cx: &App) -> Task> { *self.reads.lock().unwrap() += 1; + if let Some(err) = self.read_failure.lock().unwrap().take() { + return Task::ready(Err(err)); + } Task::ready(Ok(self.snapshot.lock().unwrap().clone())) } diff --git a/crates/agentdeck-gui/src/delete_workspace.rs b/crates/agentdeck-gui/src/delete_workspace.rs index d255c7c..aec2623 100644 --- a/crates/agentdeck-gui/src/delete_workspace.rs +++ b/crates/agentdeck-gui/src/delete_workspace.rs @@ -3,7 +3,8 @@ //! //! It says what deleting does when the workspace has any: its Repositories are unlinked and //! its running panes stopped. No folder is touched: a workspace has none. Delete workspace -//! stays disabled until the name is typed exactly. It emits [`DeleteEvent`] for the window. +//! stays disabled until the name is typed exactly. Once deleted, the GUI forgets what it kept +//! of the workspace in its own state ([`gui_state`]). It emits [`DeleteEvent`] for the window. use std::sync::Arc; @@ -21,6 +22,7 @@ use gpui::{ use gpui_base::input::InputEvent; use crate::api::Api; +use crate::gui_state; use crate::overview::Snapshot; use crate::workspace::failed; @@ -155,6 +157,8 @@ impl DeleteWorkspaceDialog { this.deleting = false; match deleted { Ok(()) => { + // What the GUI kept of it would never be read again. + gui_state::forget_workspace(cx, target.id); this.handle.close(window, cx); cx.emit(DeleteEvent::Deleted(target.id)); } @@ -294,13 +298,17 @@ impl Render for DeleteWorkspaceDialog { #[cfg(test)] mod tests { use std::cell::RefCell; + use std::collections::BTreeSet; + use std::path::PathBuf; use std::rc::Rc; + use agentdeck_core::RepositoryId; use brrritscold_core_gpui::Root; use gpui::{TestAppContext, VisualTestContext}; use super::*; use crate::api::fake::FakeApi; + use crate::gui_state::{self, GuiState, Side}; use crate::notice; use crate::overview::fixtures::{id, workspace}; @@ -484,6 +492,53 @@ mod tests { assert_eq!(shown.last().unwrap().title, "Couldn't delete tabs-a11y"); } + /// A side, a collapsed group and a dismissal for each of Workspaces `ns`, saved to a + /// `gui.json` the GUI reads and writes; the temp dir holds it. + fn remember(ns: &[u32], cx: &mut TestAppContext) -> (tempfile::TempDir, PathBuf) { + let dir = tempfile::tempdir().expect("a temp dir"); + let path = dir.path().join(gui_state::FILE); + gui_state::save(&path, &remembering(ns)).expect("save"); + cx.update(|cx| gui_state::init(Some(path.clone()), cx)); + (dir, path) + } + + fn remembering(ns: &[u32]) -> GuiState { + let mut state = GuiState::default(); + for &n in ns { + state.set_side(id(n), Side::PullRequests); + (state.collapsed).set_workspace(id(n), RepositoryId::from(7), true); + state.dismiss(id(n), RepositoryId::from(8)); + } + state + } + + #[gpui::test] + fn should_forget_what_the_gui_kept_of_the_deleted_workspace(cx: &mut TestAppContext) { + let (_dir, path) = remember(&[1, 2], cx); + let (harness, cx) = Harness::new(Arc::new(FakeApi::with(snapshot())), cx); + harness.open(cx); + harness.type_name("tabs-a11y", cx); + + harness.delete(cx); + + assert_eq!(gui_state::load(&path), remembering(&[2])); + let kept = cx.update(|_, cx| gui_state::read(cx, GuiState::workspaces)); + assert_eq!(kept, BTreeSet::from([id(2)])); + } + + #[gpui::test] + fn should_forget_nothing_when_the_delete_fails(cx: &mut TestAppContext) { + let (_dir, path) = remember(&[1, 2], cx); + let (harness, cx) = Harness::new(Arc::new(FakeApi::with(snapshot())), cx); + harness.open(cx); + harness.type_name("tabs-a11y", cx); + harness.api.fail_next("connection refused"); + + harness.delete(cx); + + assert_eq!(gui_state::load(&path), remembering(&[1, 2])); + } + #[gpui::test] fn should_close_and_ask_for_an_archive_instead(cx: &mut TestAppContext) { let (harness, cx) = Harness::new(Arc::new(FakeApi::with(snapshot())), cx); diff --git a/crates/agentdeck-gui/src/gui_state.rs b/crates/agentdeck-gui/src/gui_state.rs index 0953a2f..7ecddfa 100644 --- a/crates/agentdeck-gui/src/gui_state.rs +++ b/crates/agentdeck-gui/src/gui_state.rs @@ -11,6 +11,10 @@ //! The state is a GPUI [`Global`] that `main` sets with [`init`]; a view reads it with //! [`read`] and changes it with [`update`], which writes the file at once. Without [`init`] //! (a view test that doesn't ask for it) the state lives in memory only. +//! +//! What it keeps by Workspace id goes with the Workspace: [`forget_workspace`] once the GUI +//! deletes one, [`keep_workspaces`] once a read lists them all. Repository ids stay, since a +//! Repository comes back with the same GitHub id once linked again. use std::collections::{BTreeMap, BTreeSet}; use std::path::{Path, PathBuf}; @@ -34,7 +38,8 @@ pub struct GuiState { /// The side each Workspace showed last; a Workspace not named here opens on its Panes. pub last_side: BTreeMap, /// The Repositories each Workspace's Suggestions leave out, by GitHub's id: told Not now, - /// or unlinked in the GUI. Never forgotten; the picker's Suggested section ignores them. + /// or unlinked in the GUI. Forgotten only with the Workspace; the picker's Suggested + /// section ignores them. pub dismissed: BTreeMap>, } @@ -85,6 +90,22 @@ impl GuiState { pub fn is_dismissed(&self, workspace: WorkspaceId, repository: RepositoryId) -> bool { (self.dismissed.get(&workspace)).is_some_and(|ids| ids.contains(&repository)) } + + /// The Workspaces it remembers anything of. + pub fn workspaces(&self) -> BTreeSet { + let sides = self.last_side.keys(); + let collapsed = self.collapsed.workspaces.keys(); + let dismissed = self.dismissed.keys(); + sides.chain(collapsed).chain(dismissed).copied().collect() + } + + /// Forgets all it remembers of `workspace`: its side, its collapsed groups and its + /// dismissed Suggestions. + pub fn forget_workspace(&mut self, workspace: WorkspaceId) { + self.last_side.remove(&workspace); + self.collapsed.workspaces.remove(&workspace); + self.dismissed.remove(&workspace); + } } /// The Repository groups collapsed in each view that groups PRs by Repository. A group is @@ -199,6 +220,31 @@ pub fn update(cx: &mut App, f: impl FnOnce(&mut GuiState)) { } } +/// Forgets `workspace`, once it is deleted. +pub fn forget_workspace(cx: &mut App, workspace: WorkspaceId) { + forget_workspaces(cx, BTreeSet::from([workspace])); +} + +/// Forgets every Workspace `listed` doesn't hold: those deleted since. `listed` must be a +/// successful read of every Workspace, archived ones included. The file is written only when +/// a Workspace was forgotten. +pub fn keep_workspaces(cx: &mut App, listed: &BTreeSet) { + let gone = read(cx, |state| &state.workspaces() - listed); + forget_workspaces(cx, gone); +} + +/// Forgets each of `gone`, writing the file once; not at all when it remembers none of them. +fn forget_workspaces(cx: &mut App, gone: BTreeSet) { + if read(cx, |state| state.workspaces().is_disjoint(&gone)) { + return; + } + update(cx, |state| { + for workspace in gone { + state.forget_workspace(workspace); + } + }); +} + #[cfg(test)] mod tests { use gpui::TestAppContext; @@ -281,10 +327,6 @@ mod tests { mod side { use super::*; - fn ws(n: u32) -> WorkspaceId { - format!("00000000-0000-7000-8000-{n:012}").parse().unwrap() - } - #[test] fn should_open_a_workspace_not_seen_before_on_its_panes() { assert_eq!(GuiState::default().side(ws(1)), Side::Panes); @@ -320,10 +362,6 @@ mod tests { mod dismissed { use super::*; - fn ws(n: u32) -> WorkspaceId { - format!("00000000-0000-7000-8000-{n:012}").parse().unwrap() - } - #[test] fn should_dismiss_a_repository_for_one_workspace_only() { let mut state = GuiState::default(); @@ -370,6 +408,51 @@ mod tests { } } + /// Workspace `n`'s id. + fn ws(n: u32) -> WorkspaceId { + format!("00000000-0000-7000-8000-{n:012}").parse().unwrap() + } + + /// What the GUI keeps for Workspaces `ns`: a side, a collapsed group and a dismissal + /// each, beside a collapsed group on the Pull requests view and Show finished. + fn remembering(ns: &[u32]) -> GuiState { + let mut state = collapsed(&[7]); + state.show_finished = true; + for &n in ns { + state.set_side(ws(n), Side::PullRequests); + state + .collapsed + .set_workspace(ws(n), RepositoryId::from(7), true); + state.dismiss(ws(n), RepositoryId::from(8)); + } + state + } + + mod forget_workspace { + use super::*; + + #[test] + fn should_forget_its_side_collapsed_groups_and_dismissals_only() { + let mut state = remembering(&[1, 2]); + + state.forget_workspace(ws(1)); + + assert_eq!(state, remembering(&[2])); + } + + #[test] + fn should_name_every_workspace_it_remembers_anything_of() { + let mut state = remembering(&[]); + state.set_side(ws(1), Side::PullRequests); + state + .collapsed + .set_workspace(ws(2), RepositoryId::from(7), true); + state.dismiss(ws(3), RepositoryId::from(8)); + + assert_eq!(state.workspaces(), BTreeSet::from([ws(1), ws(2), ws(3)])); + } + } + mod save { use super::*; @@ -414,6 +497,45 @@ mod tests { assert_eq!(read_back, collapsed(&[7])); } + #[gpui::test] + fn should_write_the_file_back_without_a_forgotten_workspace(cx: &mut TestAppContext) { + let dir = tempfile::tempdir().expect("a temp dir"); + let path = dir.path().join(FILE); + save(&path, &remembering(&[1, 2])).expect("save"); + cx.update(|cx| init(Some(path.clone()), cx)); + + cx.update(|cx| forget_workspace(cx, ws(1))); + + assert_eq!(load(&path), remembering(&[2])); + } + + #[gpui::test] + fn should_write_the_file_back_with_only_the_workspaces_listed(cx: &mut TestAppContext) { + let dir = tempfile::tempdir().expect("a temp dir"); + let path = dir.path().join(FILE); + save(&path, &remembering(&[1, 2, 3])).expect("save"); + cx.update(|cx| init(Some(path.clone()), cx)); + + cx.update(|cx| keep_workspaces(cx, &BTreeSet::from([ws(2), ws(4)]))); + + assert_eq!(load(&path), remembering(&[2])); + assert_eq!(cx.read(|cx| read(cx, Clone::clone)), remembering(&[2])); + } + + #[gpui::test] + fn should_not_write_when_every_workspace_is_listed(cx: &mut TestAppContext) { + let dir = tempfile::tempdir().expect("a temp dir"); + let path = dir.path().join(FILE); + cx.update(|cx| init(Some(path.clone()), cx)); + + cx.update(|cx| keep_workspaces(cx, &BTreeSet::from([ws(1)]))); + + assert!( + !path.exists(), + "nothing was forgotten, so nothing is written" + ); + } + #[gpui::test] fn should_keep_changes_in_memory_without_a_file(cx: &mut TestAppContext) { cx.update(|cx| { diff --git a/crates/agentdeck-gui/src/sidebar.rs b/crates/agentdeck-gui/src/sidebar.rs index b658343..a2745ce 100644 --- a/crates/agentdeck-gui/src/sidebar.rs +++ b/crates/agentdeck-gui/src/sidebar.rs @@ -8,7 +8,9 @@ //! //! It reads a [`Snapshot`] through the session's [`Api`] when it opens and again whenever the //! daemon reports a `changed`; `state` and `exit` messages patch pane states in place. What -//! changed that the user should hear about goes to the window as [`Alerts`] (spec §11). +//! changed that the user should hear about goes to the window as [`Alerts`] (spec §11). Each +//! successful read makes the GUI forget, in its own state ([`gui_state`]), the Workspaces it no +//! longer lists: deleted from the CLI, another client, or while the GUI was closed. //! //! The workspace list draws only the rows in view, through GPUI's [`list`]: drawing every row //! made each redraw cost more the more workspaces there were (#199). The window follows its @@ -33,6 +35,7 @@ use gpui::{ use crate::api::Api; use crate::connection::{Connection, DaemonEvent}; use crate::count::Count; +use crate::gui_state; use crate::notifications::{self, Alert, PrBatch, Reattached}; use crate::overview::{Counts, Overview, Snapshot}; use crate::rereads::Rereads; @@ -299,6 +302,10 @@ impl SidebarView { let now = cx.background_executor().now(); this.reattached.retain(&mut alerts, &snapshot, now); alerts.extend(this.prs.read(&this.snapshot, &snapshot)); + // Only a read that succeeded lists every Workspace, so only it can tell + // which ones were deleted, wherever that happened. + let listed = (snapshot.workspaces.iter()).map(|w| w.id).collect(); + gui_state::keep_workspaces(cx, &listed); this.overview = snapshot.overview(); this.snapshot = snapshot; this.error = None; @@ -662,6 +669,7 @@ impl Render for SidebarView { #[cfg(test)] mod tests { + use std::path::PathBuf; use std::rc::Rc; use std::time::Duration; @@ -719,8 +727,12 @@ mod tests { /// Opens a `Root` window on a sidebar whose daemon answers with `snapshot`. fn open(snapshot: Snapshot, cx: &mut TestAppContext) -> Open { + open_over(Arc::new(FakeApi::with(snapshot)), cx) + } + + /// Opens a `Root` window on a sidebar over `api`. + fn open_over(api: Arc, cx: &mut TestAppContext) -> Open { cx.update(brrritscold_core_gpui::init); - let api = Arc::new(FakeApi::with(snapshot)); let connector = Rc::new(FakeConnector::default()); let remote = connector.then_connect_to(api.clone()); let (connection, sidebar) = cx.update(|cx| { @@ -1198,6 +1210,118 @@ mod tests { } } + /// What the GUI keeps for each Workspace in its own state (spec §11): forgotten once a + /// read no longer lists the Workspace, and only then. + mod gui_state { + use std::collections::BTreeSet; + + use agentdeck_client::types::Workspace; + use agentdeck_core::RepositoryId; + + use super::*; + use crate::gui_state::{self, GuiState, Side}; + + /// A side, a collapsed group and a dismissal for each of Workspaces `ns`. + fn remembering(ns: &[u32]) -> GuiState { + let mut state = GuiState::default(); + for &n in ns { + state.set_side(id(n), Side::PullRequests); + (state.collapsed).set_workspace(id(n), RepositoryId::from(7), true); + state.dismiss(id(n), RepositoryId::from(8)); + } + state + } + + /// Saves `state` to a `gui.json` the GUI then reads and writes; the temp dir holds it. + fn remember(state: &GuiState, cx: &mut TestAppContext) -> (tempfile::TempDir, PathBuf) { + let dir = tempfile::tempdir().expect("a temp dir"); + let path = dir.path().join(gui_state::FILE); + gui_state::save(&path, state).expect("save"); + cx.update(|cx| gui_state::init(Some(path.clone()), cx)); + (dir, path) + } + + fn remembered(open: &mut Open) -> BTreeSet { + open.cx + .update(|_, cx| gui_state::read(cx, GuiState::workspaces)) + } + + #[gpui::test] + fn should_forget_on_its_first_read_the_workspaces_deleted_meanwhile( + cx: &mut TestAppContext, + ) { + let (_dir, path) = remember(&remembering(&[1, 2, 3]), cx); + + let mut open = open(two_workspaces(), cx); + + assert_eq!(remembered(&mut open), BTreeSet::from([id(1), id(2)])); + assert_eq!(gui_state::load(&path), remembering(&[1, 2])); + } + + #[gpui::test] + fn should_forget_a_workspace_deleted_elsewhere_on_the_next_read(cx: &mut TestAppContext) { + let (_dir, path) = remember(&remembering(&[1, 2]), cx); + let mut open = open(two_workspaces(), cx); + let mut without_b = two_workspaces(); + without_b.workspaces.pop(); + open.api.set(without_b); + + open.send(ServerMessage::Changed { + entity: Changed::Workspace, + id: id::(2).to_string(), + }); + + assert_eq!(remembered(&mut open), BTreeSet::from([id(1)])); + assert_eq!(gui_state::load(&path), remembering(&[1])); + } + + #[gpui::test] + fn should_keep_an_archived_workspace(cx: &mut TestAppContext) { + let (_dir, path) = remember(&remembering(&[1, 3]), cx); + let mut snapshot = two_workspaces(); + snapshot.workspaces.push(Workspace { + archived_at: Some("2026-11-13T00:00:00Z".into()), + ..workspace(3, "old") + }); + + let mut open = open(snapshot, cx); + + assert_eq!(remembered(&mut open), BTreeSet::from([id(1), id(3)])); + assert_eq!(gui_state::load(&path), remembering(&[1, 3])); + } + + #[gpui::test] + fn should_forget_nothing_before_its_first_read_succeeds(cx: &mut TestAppContext) { + let (_dir, path) = remember(&remembering(&[1, 2]), cx); + let api = FakeApi::with(Snapshot::default()); + api.fail_next_read("connection refused"); + let api = Arc::new(api); + + let mut open = open_over(api, cx); + + assert!(open.sidebar.read_with(open.cx, |s, _| s.error.is_some())); + assert_eq!(remembered(&mut open), BTreeSet::from([id(1), id(2)])); + assert_eq!(gui_state::load(&path), remembering(&[1, 2])); + } + + #[gpui::test] + fn should_forget_nothing_on_a_failed_read(cx: &mut TestAppContext) { + let (_dir, path) = remember(&remembering(&[1, 2]), cx); + let mut open = open(two_workspaces(), cx); + open.api.set(Snapshot::default()); + open.api.fail_next_read("connection refused"); + + open.send(ServerMessage::Changed { + entity: Changed::Workspace, + id: id::(2).to_string(), + }); + + assert!(open.sidebar.read_with(open.cx, |s, _| s.error.is_some())); + assert_eq!(remembered(&mut open), BTreeSet::from([id(1), id(2)])); + assert_eq!(gui_state::load(&path), remembering(&[1, 2])); + } + } + mod archived { use agentdeck_client::types::Workspace; diff --git a/docs/spec.md b/docs/spec.md index 2c87e81..54631f6 100644 --- a/docs/spec.md +++ b/docs/spec.md @@ -424,7 +424,7 @@ Built on `brrritscold-core-gpui` (`init`, `Root`, theme preference, toasts). Scr - **Older daemon:** while the daemon is older than the app (§2), a banner sits over the window's body, under the title bar: the Pull requests view's logged-out banner (a default alert with the `Info` icon, `space.6` across and `space.4` down, a separator under it) with an outline sm **Restart** as its action, the failure alert's. "agentdeck's background service is older than this app" / "Restart it to use new features. Your agents resume after the restart." Restart restarts the daemon (§2); meanwhile the window shows "Restarting agentdeck's background service…" in place of its body, then the new daemon's views. A failed restart shows the connection failure alert, "Couldn't restart agentdeckd: ", with Retry. Penpot "Screens · Daemon" → "Older daemon". - **Title bar:** the window asks for the compositor's frame. Where the compositor draws none (GNOME's Mutter on Wayland), the app draws a 32px title bar across the top: drag to move, double-click to maximize, right-click for the window menu, minimize / maximize / close at the right. 4px resize strips run along the window's inside edges, except on a tiled side. Everything else sits under it. - **Window:** it opens at 1440×900, the design's size, centred on the primary display and shrunk to fit its work area, but never below its minimum size, 1030×600. That is the narrowest layout that fits without clipping, derived from the narrowest PR table in Select mode: the sidebar (260) and its separator, the Pull requests view's `space.6` padding either side and its table in Select mode at its least (716: every column, the title at 160), 1025 rounded up (Penpot "Screens · Main" → "Pull requests · select · 1030"). The Pull requests view's header fits there too, its description wrapping, and so does a workspace view's 560px pane header. 600 high holds the tallest dialog under the title bar. The window can't be resized below it, and saved bounds smaller than it grow to it. Its size, position and maximized state are kept across restarts in `$XDG_STATE_HOME/agentdeck/window.json` (GUI-only, apart from `config.toml`), written once a resize or move settles and on quit. A missing or unreadable file, or saved bounds whose centre is on no connected display, opens at the default instead. -- **GUI state:** what the GUI remembers of itself, beside `window.json` in `$XDG_STATE_HOME/agentdeck/gui.json` (GUI-only too): the Repository groups collapsed per view, by GitHub's Repository id, so a rename keeps a group collapsed: on the Pull requests view (`{"collapsed": {"pull_requests": [1296269]}}`) and on each Workspace's Pull requests, by the Workspace's id (`{"collapsed": {"workspaces": {"": [1296269]}}}`); Show finished (`{"show_finished": true}`), one preference for every PR list, off by default; and each Workspace's last side, by its id (`{"last_side": {"": "pull_requests"}}`), Panes, the default, written as nothing; and the dismissed Suggestions, by Workspace id and GitHub's Repository id (`{"dismissed": {"": [1296269]}}`), each added by Not now on the Suggestions strip or by an unlink made in the GUI (Edit workspace's Save, a group's Unlink from this workspace), never by `agentdeck repo unlink`, and never forgotten. It is written at once, through a temp file, on each change. Every field is optional and a field the GUI doesn't know is skipped, so later versions add theirs beside it, and a missing or broken file reads as nothing remembered. Without a state dir it is kept in memory only. +- **GUI state:** what the GUI remembers of itself, beside `window.json` in `$XDG_STATE_HOME/agentdeck/gui.json` (GUI-only too): the Repository groups collapsed per view, by GitHub's Repository id, so a rename keeps a group collapsed: on the Pull requests view (`{"collapsed": {"pull_requests": [1296269]}}`) and on each Workspace's Pull requests, by the Workspace's id (`{"collapsed": {"workspaces": {"": [1296269]}}}`); Show finished (`{"show_finished": true}`), one preference for every PR list, off by default; and each Workspace's last side, by its id (`{"last_side": {"": "pull_requests"}}`), Panes, the default, written as nothing; and the dismissed Suggestions, by Workspace id and GitHub's Repository id (`{"dismissed": {"": [1296269]}}`), each added by Not now on the Suggestions strip or by an unlink made in the GUI (Edit workspace's Save, a group's Unlink from this workspace), never by `agentdeck repo unlink`, and never forgotten while the Workspace exists. What it keeps by Workspace id (its collapsed groups, last side and dismissals) is forgotten once the Workspace is deleted: at once when the Delete workspace dialog deletes it, and otherwise on the sidebar's next successful read (§11 Sidebar) that doesn't list it, archived Workspaces being listed, so a Workspace deleted from the CLI, another client or while the GUI was closed goes too. Nothing is forgotten before the first read succeeds or on a failed one: a read is all or nothing, so only a whole list of Workspaces says one is gone. Repository ids are never forgotten, under a Workspace that stays or on the Pull requests view: a Repository deleted when its last link goes comes back with the same GitHub id once linked again, and a dismissal names a Repository the daemon may never hold. It is written at once, through a temp file, on each change, and not at all when a read finds nothing to forget. Every field is optional and a field the GUI doesn't know is skipped, so later versions add theirs beside it, and a missing or broken file reads as nothing remembered. Without a state dir it is kept in memory only. - **Quitting while agents run** (Penpot "Screens · Dialogs" → "Quit · agents running"): agents keep running after the GUI quits (§2, §8), so closing the window (the title bar's close button or the compositor's) and Quit ask first while at least one agent runs: an agent pane whose process hasn't exited, or a shell pane hosting an agent. Plain shells don't count. With none running, or `gui.confirm_quit` off (§2), they quit at once. - An `AlertDialog` titled "Quit agentdeck?", with "1 agent is still running. They keep running in the background, and reopening agentdeck reconnects to them." ("N agents are still running" for more). Under it, two horizontal Fields, `space.3` apart: a Checkbox "Don't ask again", then a Checkbox "Stop the agents" (Penpot "Quit · agents running · stop ticked" shows it ticked), each unticked each time the dialog opens; clicking a label ticks its box too. While Stop the agents is ticked the description reads "N agents are still running. They'll be stopped; Restart agent on each pane starts them again." ("1 agent is still running. It'll be stopped; Restart agent on its pane starts it again." for one). The footer is Cancel (outline) and **Quit** (default), `space.6` below the Fields. - Quit, or Enter, quits; with Don't ask again ticked it first saves `gui.confirm_quit = false` with `PATCH /v1/settings` and quits once that lands, whether or not it saved. Cancel, or Escape, keeps the app. Settings' General section turns it back on. @@ -564,7 +564,7 @@ Built on `brrritscold-core-gpui` (`init`, `Root`, theme preference, toasts). Scr | Tier | Where | What | |---|---|---| -| unit | `agentdeck-core`, GUI views (`#[gpui::test]`), daemon pure parts | rules with recorded output (the Copy PR details text among them, one PR's and several joined by a blank line), why a PR is yours (`why_yours`: its author, review requests and assignees against your login, ignoring case), which open PRs an incremental sync fetches again, layout tree, snapshot encode/decode round-trip, env allowlist, `openapi.json` staleness; GUI views over a fake API and a fake notifier, asserting what a user sees (the Pull requests view's groups and their order, collapse and Show finished kept in the GUI state file, Finished rows hidden until Show finished and showing GitHub's state, the row's link and menu, Sync now, the banner, the empty state, Unreachable rows, an Unreachable Repository's header in place of its Workspaces on both views; Select mode: entering and leaving it, picking by row click, group checkbox (folded too) and select-all, which rows can be picked (open and reachable, Finished-but-open included; not merged, closed or Unreachable), the bar's count and order, Copy PR details joined in the list's order, Close PRs asking then closing by reference, a PR that didn't close kept picked and marked with why, a closed PR shown closed at once, "Closing N of M…", and Select disabled on the empty view; the header and the table fitting the narrowest window in Select mode, and that window's minimum fitting the narrowest PR table in Select mode; the sidebar's entries and counts, Finished PRs left out, no Inbox or Tasks entry, each Workspace's count over its linked Repositories, none on an archived row, the no-Workspaces hint and its New workspace, Pull requests the fallback selection; linked groups first, then Not in a workspace, each alphabetical, a group's header naming its linking Workspaces as links that open their Pull requests, Archived Workspaces absent from headers and order; the group `…` menu on every group of both views, in the rows' `…` column: Open on GitHub opening the Repository's page, Link to a workspace offering the Workspaces that aren't archived and don't link it in the sidebar's order then New workspace, New workspace alone when none is eligible, New workspace opening the dialog with the Repository picked, a link applied at once by GitHub's id with "Linked owner/name to " and an Undo that unlinks, Unlink from this workspace only on a Workspace's Pull requests, applied at once with "Unlinked owner/name from " and its open PRs (singular, plural, none, and where they went when no other Workspace links it), its Undo linking again by id once the unlink deleted the Repository, and failures toasted; a Workspace's side switch with its count, `secondary-shift-p`, each Workspace's side remembered across a restart and opened from its sidebar row, a new one on its Panes; a Workspace's Pull requests: only its linked Repositories, "No open PRs", Select, Show finished and Edit workspace with no sync controls, the banner, collapse kept apart from the Pull requests view's, the no-Repositories state whose Link repository opens Edit workspace with its picker focused and open; Edit workspace and New workspace: the linked rows with their Unlink, lock and Unreachable badge, staging until Save (one request with the name, applied to the fake, none before), Save enabled by a staged change alone, Undo, the leaving note and its singular and its absence at 0, Cancel discarding what was staged, a refusal under the picker keeping the dialog open, an archived workspace linked, the picker's From your pull requests (no linked, picked or Unreachable Repository; the lock), local filtering ignoring case and by a pasted URL, picking (the field cleared), Enter picking the first row, the typed row only for an unlisted name, GitHub showing it (staged under GitHub's name, private kept) or not ("GitHub can't see …" under the field, the list closed, cleared by typing), signed out (no typed row, "Sign in to GitHub to find more repositories."), and New workspace linking what was picked on create; the picker's Suggested section first, ignoring dismissals, its rows left out of From your pull requests, filtered as typed, picked by click or Enter; its All your repositories after the other sections (none listed above, linked or Unreachable; the lock), filtered as typed, picked by click or Enter, no typed row for a name it lists, a refresh asked each time it opens, the rows loaded so far with "Loading your repositories… N of about M" under them (and with no count before page 1, and still in view under rows that scroll), read again on `changed github_repositories`, "Couldn't load your repositories." with Retry (GitHub's failure or the daemon unreadable) keeping the other sections and typed names, Retry loading again, "Sign in to GitHub…" in its place signed out (PR status or the list's `signed_out`), and only the rows in view drawn for 1,100; the loading line's count and rounding; the sidebar not reading again for a `github_repositories` event; the Suggestions strip on a Workspace's Pull requests (one row alone, several stacked in one strip under the header and over the table, none on the Pull requests view, an archived Workspace or for what it links by now), Link at once by GitHub's id with "Linked owner/name to ", the row gone and the group shown once read, its Undo unlinking without dismissing and a failure toasted with the row kept, Not now taking the row away for that Workspace only and kept across a restart in the GUI state file, the strip under Link repository on a Workspace with no Repositories, and an unlink from the group menu or Edit workspace's Save recording a dismissal (a failed one none); the GUI state's dismissed pairs, written by id; the picker's offer read from a snapshot (linked ones, Unreachable included; Suggestions but what the Workspace links by now; your PRs' reachable Repositories; open PRs counted as the sidebar does; signed out only while the token is logged out); the archived screen with no switch; a pane notifying while its workspace shows its Pull requests; New workspace's Name field and optional picker; New agent's Folder select (where a new pane starts first, the other panes' folders, then `~`, each once) and a new pane starting in `~` in a workspace with none; the Delete workspace dialog's lines (its Repositories unlinked, its running panes stopped, each left out at 0); the archive toast; the top bar's name, centred, before its side switch; a Pane alert's body, " · ", and the pane header's parts; PR alerts over the fake notifier: each trigger, only PRs you authored (one you review, are assigned, or both, never alerts), one alert per PR replaced on a new change, a click landing on the row with its group opened, a Finished row shown with Show finished left off, scrolled to and highlighted until the highlight fades, "N PRs changed" opening the view, an alert withdrawn once the view shows, and the mute rule with every linking Workspace muted, one unmuted, only Archived muted ones, and none); the PR alert mute rule and the GitHub remote parser (https, ssh and scp-like URLs, for Suggestions) in `agentdeck-core`; the daemon's git config reader for Suggestions (each remote's first URL by name, sections and keys ignoring case, the old dotted header, comments and quotes, `upstream` on GitHub over `origin`, no other remote; a folder deep in a repo, a worktree's `.git` file and `commondir`, a relative `gitdir`, none outside a repo) and which events make Suggestions due | +| unit | `agentdeck-core`, GUI views (`#[gpui::test]`), daemon pure parts | rules with recorded output (the Copy PR details text among them, one PR's and several joined by a blank line), why a PR is yours (`why_yours`: its author, review requests and assignees against your login, ignoring case), which open PRs an incremental sync fetches again, layout tree, snapshot encode/decode round-trip, env allowlist, `openapi.json` staleness; GUI views over a fake API and a fake notifier, asserting what a user sees (the Pull requests view's groups and their order, collapse and Show finished kept in the GUI state file, Finished rows hidden until Show finished and showing GitHub's state, the row's link and menu, Sync now, the banner, the empty state, Unreachable rows, an Unreachable Repository's header in place of its Workspaces on both views; Select mode: entering and leaving it, picking by row click, group checkbox (folded too) and select-all, which rows can be picked (open and reachable, Finished-but-open included; not merged, closed or Unreachable), the bar's count and order, Copy PR details joined in the list's order, Close PRs asking then closing by reference, a PR that didn't close kept picked and marked with why, a closed PR shown closed at once, "Closing N of M…", and Select disabled on the empty view; the header and the table fitting the narrowest window in Select mode, and that window's minimum fitting the narrowest PR table in Select mode; the sidebar's entries and counts, Finished PRs left out, no Inbox or Tasks entry, each Workspace's count over its linked Repositories, none on an archived row, the no-Workspaces hint and its New workspace, Pull requests the fallback selection; linked groups first, then Not in a workspace, each alphabetical, a group's header naming its linking Workspaces as links that open their Pull requests, Archived Workspaces absent from headers and order; the group `…` menu on every group of both views, in the rows' `…` column: Open on GitHub opening the Repository's page, Link to a workspace offering the Workspaces that aren't archived and don't link it in the sidebar's order then New workspace, New workspace alone when none is eligible, New workspace opening the dialog with the Repository picked, a link applied at once by GitHub's id with "Linked owner/name to " and an Undo that unlinks, Unlink from this workspace only on a Workspace's Pull requests, applied at once with "Unlinked owner/name from " and its open PRs (singular, plural, none, and where they went when no other Workspace links it), its Undo linking again by id once the unlink deleted the Repository, and failures toasted; a Workspace's side switch with its count, `secondary-shift-p`, each Workspace's side remembered across a restart and opened from its sidebar row, a new one on its Panes; a Workspace's Pull requests: only its linked Repositories, "No open PRs", Select, Show finished and Edit workspace with no sync controls, the banner, collapse kept apart from the Pull requests view's, the no-Repositories state whose Link repository opens Edit workspace with its picker focused and open; Edit workspace and New workspace: the linked rows with their Unlink, lock and Unreachable badge, staging until Save (one request with the name, applied to the fake, none before), Save enabled by a staged change alone, Undo, the leaving note and its singular and its absence at 0, Cancel discarding what was staged, a refusal under the picker keeping the dialog open, an archived workspace linked, the picker's From your pull requests (no linked, picked or Unreachable Repository; the lock), local filtering ignoring case and by a pasted URL, picking (the field cleared), Enter picking the first row, the typed row only for an unlisted name, GitHub showing it (staged under GitHub's name, private kept) or not ("GitHub can't see …" under the field, the list closed, cleared by typing), signed out (no typed row, "Sign in to GitHub to find more repositories."), and New workspace linking what was picked on create; the picker's Suggested section first, ignoring dismissals, its rows left out of From your pull requests, filtered as typed, picked by click or Enter; its All your repositories after the other sections (none listed above, linked or Unreachable; the lock), filtered as typed, picked by click or Enter, no typed row for a name it lists, a refresh asked each time it opens, the rows loaded so far with "Loading your repositories… N of about M" under them (and with no count before page 1, and still in view under rows that scroll), read again on `changed github_repositories`, "Couldn't load your repositories." with Retry (GitHub's failure or the daemon unreadable) keeping the other sections and typed names, Retry loading again, "Sign in to GitHub…" in its place signed out (PR status or the list's `signed_out`), and only the rows in view drawn for 1,100; the loading line's count and rounding; the sidebar not reading again for a `github_repositories` event; the Suggestions strip on a Workspace's Pull requests (one row alone, several stacked in one strip under the header and over the table, none on the Pull requests view, an archived Workspace or for what it links by now), Link at once by GitHub's id with "Linked owner/name to ", the row gone and the group shown once read, its Undo unlinking without dismissing and a failure toasted with the row kept, Not now taking the row away for that Workspace only and kept across a restart in the GUI state file, the strip under Link repository on a Workspace with no Repositories, and an unlink from the group menu or Edit workspace's Save recording a dismissal (a failed one none); the GUI state's dismissed pairs, written by id; the GUI state forgetting a Workspace's entries (collapsed groups, last side, dismissals) when the Delete workspace dialog deletes it (none on a failed delete) and on the sidebar's next read that no longer lists it (deleted elsewhere, or before the GUI started; archived ones kept), never before the first read succeeds or on a failed read, and the file written back without them; the picker's offer read from a snapshot (linked ones, Unreachable included; Suggestions but what the Workspace links by now; your PRs' reachable Repositories; open PRs counted as the sidebar does; signed out only while the token is logged out); the archived screen with no switch; a pane notifying while its workspace shows its Pull requests; New workspace's Name field and optional picker; New agent's Folder select (where a new pane starts first, the other panes' folders, then `~`, each once) and a new pane starting in `~` in a workspace with none; the Delete workspace dialog's lines (its Repositories unlinked, its running panes stopped, each left out at 0); the archive toast; the top bar's name, centred, before its side switch; a Pane alert's body, " · ", and the pane header's parts; PR alerts over the fake notifier: each trigger, only PRs you authored (one you review, are assigned, or both, never alerts), one alert per PR replaced on a new change, a click landing on the row with its group opened, a Finished row shown with Show finished left off, scrolled to and highlighted until the highlight fades, "N PRs changed" opening the view, an alert withdrawn once the view shows, and the mute rule with every linking Workspace muted, one unmuted, only Archived muted ones, and none); the PR alert mute rule and the GitHub remote parser (https, ssh and scp-like URLs, for Suggestions) in `agentdeck-core`; the daemon's git config reader for Suggestions (each remote's first URL by name, sections and keys ignoring case, the old dotted header, comments and quotes, `upstream` on GitHub over `origin`, no other remote; a folder deep in a repo, a worktree's `.git` file and `commondir`, a relative `gitdir`, none outside a repo) and which events make Suggestions due | | integration | `agentdeckd/tests/integration` | temp `$XDG_*` dirs, a real daemon on a random port, a real client; PTYs run `sh`, which moves a pane with `cd` (read through `/proc`) or `printf`s an OSC 7, so a pane's current folder, its `changed` and its restore folder are tested without a shell that reports one; GitHub is httpmock (`AGENTDECK_GITHUB_API`, `AGENTDECK_GITHUB_REST_API` and `AGENTDECK_GITHUB_OAUTH`: GraphQL with `closePullRequest`, REST's `GET /repos/{owner}/{repo}` for Repository lookups, Links and Suggestions, `GET /repositories/{id}` for Repositories read by id and `GET /user/repos` for the GitHub repository list, and the device flow's code and token endpoints); Suggestions run Panes (`sh`, `sleep`) in temp git repos with `upstream`, `origin` and other remotes: upstream on GitHub over origin, origin when upstream is elsewhere, other remotes ignored, none outside a repo, one per name, a Pane that `cd`s in, an exited Pane at its last folder, a name GitHub can't see never suggested, a renamed one under GitHub's name, each name asked about once per run across reads and Workspaces, signed out only kept Repositories, one other Workspaces link still suggested, one the Workspace links left out, an archived Workspace none, `404 not_found`, and `changed suggestions` when a Pane opens in or moves into a repo, a Link takes one away and a deleted Pane takes one away; the client's `repositories::suggestions` against the same daemon, none from an older one; the GitHub repository list (REST `GET /user/repos` on httpmock, pages with a `Link` header): not loaded until a refresh asks, every page in GitHub's order once loaded, one page with no `Link` header, page 1 served while the rest load (`total` estimated from the last page link), the last page read first so `total` is exact early, a `github_repositories` event as the load begins, as each page arrives and as it ends, the list kept across reads with no new request, a refresh quietly showing the list before until the new one has loaded, a refresh while a load runs left alone, a 5xx tried three times then `failed` and loaded on a retry, a 403 rate limit and a 429 failing at once, a later page failing the whole load, a 401 `failed` ("GitHub rejected the token"), a failed quiet refresh keeping the list with its `error`, `signed_out` with no token and no GitHub call, a changed token loading the new sign-in's list, and `search/repositories` never called; the client's `repositories::github_list` and `refresh_github_list` against the same daemon (loaded, signed out, the daemon's `unauthorized`); `gh` is a stub script on `PATH`, and so are `claude` and `codex`, which read input as their TUIs do, and exit on a submitted `/exit` so a shell pane's hosted agent can leave (raw, bracketed paste on, a read that is a lone `\r` submits, any other read is a paste); the keyring is an in-memory fake store (`AGENTDECK_KEYRING=memory`; without it the harness's daemon has no session bus, so no keyring). The `agentdeck_client` helpers the GUI's real API calls (`panes`, `settings`, `prs`, `repositories`, `workspaces`) are tested here through the real client (`*_client`), each new operation of the GUI's fake API with a test of the same call in the same PR, so the fake can't drift from the daemon; `prs::list` also lists none from a daemon older than `GET /v1/prs`, and lists Finished PRs, marked; `repositories::list` lists each Repository with the Workspaces linking it, Archived ones included, and none from a daemon older than `GET /v1/repositories`; `repositories::resolve` answers the Repository GitHub shows for a typed URL and fails with the daemon's "GitHub can't see …"; `repositories::link` links by GitHub's id and links again, signed out, once an unlink deleted the Repository, and `repositories::unlink` keeps one another Workspace links and fails with the daemon's `not_found` for one the Workspace doesn't link; `workspaces::create` makes a Workspace linking what was picked, or nothing, and `workspaces::update` renames, links and unlinks together, or changes nothing, failing with the daemon's words. The Workspace routes' Links are tested here too: create linking a Repository agentdeck keeps (no GitHub call) and one GitHub resolves, nothing made when GitHub can't see one; update renaming, linking and unlinking in one request (an unreferenced Repository gone), nothing changed when a link fails or the name is blank, `invalid_links`, unlinking one it doesn't link changing nothing, an archived Workspace linked, and `changed` for each Repository then the workspace. The link route's link by GitHub's `id` is tested here too: a Repository an unlink deleted stored again from the body signed out (no GitHub, where a link by name is `not_signed_in`), the Repository kept with that id linked under its name now, `changed` for the Repository then the workspace, and `404 not_found` storing nothing for a Workspace that doesn't exist. PR sync's PRs of each kind are tested here too: the ones you authored, those where your review is requested and those assigned to you, and one that is yours several ways at once, each with why it is yours in `GET /v1/prs`, in a full sync (the list and the two open searches) and an incremental one (a search for each), the age cutoff leaving out old ones of each kind in both. Its Finished PRs too: Finished on merge, on close (from GitHub and from agentdeck), past the cutoff and once no longer yours (your review submitted, seen by the incremental sync's fetch by number; you unassigned, seen by a full sync's), an authored PR whose review request goes staying unfinished, no longer Finished once GitHub shows a PR open and yours again, deleted with their unreferenced Repositories after the window (`AGENTDECK_PR_FINISHED_SECS=0`), and Unreachable PRs kept with no window. PRs are kept by Repository and number: a renamed Repository's PR and one of another Repository that took the old name are two PRs. Repositories read by id are tested here too: a linked Repository with no PR renamed (its Link kept), lost (Unreachable, its Link kept, a `changed repository`) and regained (the mark cleared), none read while GitHub shows a PR of it, a PR's Repository GitHub doesn't show marked Unreachable with the PR, and a PR merged after its Repository's rename, the old name since taken by another Repository with a PR of the same number, fetched under the new name and Finished, not Unreachable. Workspaces without folders are tested here too: creating one makes nothing on disk and its JSON has no folder, an older client's `dir` and `force` are ignored, the dirty report route is gone (dropshot's own 404), deleting one unlinks its Repositories (a Repository nothing else names goes) and stops its panes but leaves every folder on disk (its panes' folders and an old scratch folder), the first pane of a workspace with none opens in `~` through `panes::new_shell_tab`, and `0002` drops the folder columns from a database at `0001`, keeping each Workspace and its Links. The fresh start is tested here too: a fresh data dir gets the migrations' schema (no `tasks`, `comments` or `instructions`; `pull_requests` keyed by `(repository_id, number)` with nothing unique on a name), a current database survives a restart, and a database with a `tasks` table, its last writes still in its WAL, is moved aside with its WAL and SHM files (the moved one still reads), logged, never over an earlier one, with scratch folders left alone, and the daemon starts empty | | integration | `mod integration_tests` in `agentdeckd/src` | a crate-private part over a real dependency, which `tests/integration` can't reach since the daemon is a binary: a `Pane` over a real PTY running `sh` reads as exited only once its exit is recorded. The integration nextest profile runs these modules; the unit one skips them | | integration | `agentdeckd/tests/integration` (keyring) | the keyring store against a real Secret Service: `gnome-keyring-daemon`, unlocked, on a private `dbus-daemon` session bus the test starts, as `agentdeck-notify`'s test does, which CI installs with `script/install-linux-deps.sh`. It saves, finds, replaces and deletes the token and client ID entries, and finds none with no Secret Service. It is the fake store's contract test: the same cases run against the fake, and a fake lands with a test of the real call in the same PR |