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
87 changes: 87 additions & 0 deletions crates/agentdeck-client/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4404,6 +4404,23 @@ impl Client {
pub fn link_delete(&self) -> builder::LinkDelete<'_> {
builder::LinkDelete::new(self)
}
///Workspace `id`'s Suggestions (spec §3): the Repositories its Panes work in that it doesn't
///
///link, each as GitHub showed it when this run first asked about its name, by name ignoring case. A Pane counts at its current folder, an exited one at its last known folder; its git repo's `upstream` remote counts when it is on GitHub, else its `origin`. A Repository other Workspaces link is still suggested; one GitHub can't see never is; signed out, only one agentdeck keeps is. An archived Workspace has none. Not filtered by what the GUI was told Not now. A Workspace that doesn't exist is 404 `not_found`.
///
///Sends a `GET` request to `/v1/workspaces/{id}/suggestions`
///
///Arguments:
///- `id`: The entity's id.
///```ignore
///let response = client.suggestion_list()
/// .id(id)
/// .send()
/// .await;
///```
pub fn suggestion_list(&self) -> builder::SuggestionList<'_> {
builder::SuggestionList::new(self)
}
///A workspace's tabs, in position order
///
///Sends a `GET` request to `/v1/workspaces/{id}/tabs`
Expand Down Expand Up @@ -6758,6 +6775,76 @@ pub mod builder {
}
}
}
///Builder for [`Client::suggestion_list`]
///
///[`Client::suggestion_list`]: super::Client::suggestion_list
#[derive(Debug, Clone)]
pub struct SuggestionList<'a> {
client: &'a super::Client,
id: Result<agentdeck_core::WorkspaceId, String>,
}
impl<'a> SuggestionList<'a> {
pub fn new(client: &'a super::Client) -> Self {
Self {
client: client,
id: Err("id was not initialized".to_string()),
}
}
pub fn id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<agentdeck_core::WorkspaceId>,
{
self.id = value.try_into().map_err(|_| {
"conversion to `agentdeck_core :: WorkspaceId` for id failed".to_string()
});
self
}
///Sends a `GET` request to `/v1/workspaces/{id}/suggestions`
pub async fn send(
self,
) -> Result<ResponseValue<::std::vec::Vec<types::Repository>>, Error<types::Error>>
{
let Self { client, id } = self;
let id = id.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/v1/workspaces/{}/suggestions",
client.baseurl,
encode_path(&id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(super::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.get(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "suggestion_list",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
400u16..=499u16 => Err(Error::ErrorResponse(
ResponseValue::from_response(response).await?,
)),
500u16..=599u16 => Err(Error::ErrorResponse(
ResponseValue::from_response(response).await?,
)),
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
///Builder for [`Client::tab_list`]
///
///[`Client::tab_list`]: super::Client::tab_list
Expand Down
23 changes: 22 additions & 1 deletion crates/agentdeck-client/src/repositories.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Repositories as the GUI reads them (spec §4 `GET /v1/repositories`, §11 Notifications),
//! and the Links a Repository group's `…` menu makes and takes away (spec §4
//! `/v1/workspaces/{id}/links`, §11 Pull requests view).
//! `/v1/workspaces/{id}/links`, §11 Pull requests view), and each Workspace's Suggestions
//! (`/v1/workspaces/{id}/suggestions`).

use agentdeck_core::{RepositoryId, RepositoryName, WorkspaceId};

Expand All @@ -24,6 +25,26 @@ pub async fn list(client: &Client) -> Result<Vec<RepositoryLinks>, ApiError> {
}
}

/// Workspace `workspace`'s Suggestions (spec §3): the Repositories its Panes work in that it
/// doesn't link, by name, each as GitHub showed it, so the GUI links one by its id. Not
/// filtered by what the GUI was told Not now. A daemon older than the route has none to give,
/// and lists none rather than failing.
pub async fn suggestions(
client: &Client,
workspace: WorkspaceId,
) -> Result<Vec<Repository>, ApiError> {
match client.suggestion_list().id(workspace).send().await {
Ok(suggestions) => Ok(suggestions.into_inner()),
Err(err) => match ApiError::from(err) {
ApiError {
message,
code: None,
} if message == OLDER_DAEMON => Ok(Vec::new()),
err => Err(err),
},
}
}

/// The Repository GitHub shows by `name` now (`owner/name` or its URL), as the picker's typed
/// row looks one up. One GitHub can't see is the daemon's `unknown_repository`, whose message
/// is what the GUI shows: "GitHub can't see owner/name. Check the name or your token's
Expand Down
2 changes: 1 addition & 1 deletion crates/agentdeck-core/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
/// fails when `openapi.json` changes without a bump.
///
/// `0` is every daemon from before it existed, whose `daemon.json` has no `api_version`.
pub const API_VERSION: u32 = 25;
pub const API_VERSION: u32 = 26;

/// What `$XDG_RUNTIME_DIR/agentdeck/daemon.json` holds. The daemon writes it once it serves;
/// the GUI and the CLI read it to reach the daemon.
Expand Down
14 changes: 14 additions & 0 deletions crates/agentdeck-core/src/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ pub enum Entity {
/// its number, `1296269#7`, so a rename keeps it. It came with `API_VERSION` 22, when the
/// `task` it replaces went; an older client skips the message.
PullRequest,
/// `/v1/workspaces/{id}/suggestions`: a Workspace's Suggestions differ from the last ones
/// the daemon worked out for it, after a Pane of it opened, exited, moved or was deleted,
/// a Link of it changed, it was archived or brought back, or the GitHub sign-in changed.
/// Its id is the Workspace's. It came with `API_VERSION` 26; an older client skips the
/// message.
Suggestions,
}

#[cfg(test)]
Expand Down Expand Up @@ -386,6 +392,14 @@ mod tests {
},
json!({"t": "changed", "entity": "repository", "id": "1296269"}),
),
(
ServerMessage::Changed {
entity: Entity::Suggestions,
id: "019a0000-0000-7000-8000-000000000001".into(),
},
json!({"t": "changed", "entity": "suggestions",
"id": "019a0000-0000-7000-8000-000000000001"}),
),
(
ServerMessage::Lagged { channel: 3 },
json!({"t": "lagged", "channel": 3}),
Expand Down
20 changes: 17 additions & 3 deletions crates/agentdeck-gui/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,15 +456,20 @@ async fn panes(client: Client, workspace: WorkspaceId) -> anyhow::Result<Workspa
Ok(WorkspacePanes { tabs, panes })
}

/// Reads a [`Snapshot`]: the workspaces, then each live one's tabs and the panes in their
/// layouts, then PR sync status, the pull requests and the Repositories with the Workspaces
/// linking each.
/// Reads a [`Snapshot`]: the workspaces, then each live one's Suggestions, tabs and the panes
/// in their layouts, then PR sync status, the pull requests and the Repositories with the
/// Workspaces linking each.
async fn snapshot(client: Client) -> anyhow::Result<Snapshot> {
let workspaces = (client.workspace_list().send().await)
.map_err(ApiError::from)?
.into_inner();
let mut panes = Vec::new();
let mut suggestions = std::collections::HashMap::new();
for workspace in workspaces.iter().filter(|w| w.archived_at.is_none()) {
suggestions.insert(
workspace.id,
agentdeck_client::repositories::suggestions(&client, workspace.id).await?,
);
let tabs = client
.tab_list()
.id(workspace.id)
Expand Down Expand Up @@ -498,6 +503,7 @@ async fn snapshot(client: Client) -> anyhow::Result<Snapshot> {
),
prs: agentdeck_client::prs::list(&client).await?,
repositories: agentdeck_client::repositories::list(&client).await?,
suggestions,
})
}

Expand Down Expand Up @@ -823,6 +829,11 @@ pub(crate) mod fake {
repository.workspaces.retain(|w| *w != workspace);
}
}
if let Some(suggested) = snapshot.suggestions.get_mut(&workspace) {
suggested.retain(|r| {
!(link.iter()).any(|n| n.to_string().eq_ignore_ascii_case(&r.name.to_string()))
});
}
let prs = snapshot.prs.clone();
snapshot.repositories.retain(|repository| {
!repository.workspaces.is_empty()
Expand Down Expand Up @@ -1178,6 +1189,9 @@ pub(crate) mod fake {
if let Some(held) = held.filter(|r| !r.workspaces.contains(&workspace)) {
held.workspaces.push(workspace);
}
if let Some(suggested) = snapshot.suggestions.get_mut(&workspace) {
suggested.retain(|r| r.id != repository.id);
}
Task::ready(Ok(()))
}

Expand Down
56 changes: 54 additions & 2 deletions crates/agentdeck-gui/src/edit_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
//! one request; Cancel discards them, and nothing asks to confirm. Save, and Enter in the name,
//! go ahead once the name isn't blank and something changed. A blank name, or the daemon's
//! `invalid_name`, shows under the name; a Repository the daemon can't link shows under the
//! picker, and any other failure toasts. Once saved it closes and emits [`Saved`]. The slug
//! stays as it is. An archived workspace can be edited too.
//! picker, and any other failure toasts. Once saved it closes and emits [`Saved`]; each
//! Repository it unlinked counts as Not now for the workspace's Suggestions. The slug stays as
//! it is. An archived workspace can be edited too.

use std::sync::Arc;

Expand All @@ -26,6 +27,7 @@ use gpui::{
use gpui_base::input::InputEvent;

use crate::api::{Api, Change};
use crate::gui_state;
use crate::link_picker::{LinkPicker, Offer, Staging};
use crate::workspace::failed;

Expand Down Expand Up @@ -185,6 +187,7 @@ impl EditWorkspaceDialog {
};
let typed = self.name.read(cx).value();
let (link, unlink) = self.picker.read(cx).change();
let unlinked = unlink.clone();
let change = Change {
name: new_name(&typed, &target.name).map(str::to_owned),
link,
Expand All @@ -199,6 +202,12 @@ impl EditWorkspaceDialog {
this.saving = false;
match saved {
Ok(()) => {
// An unlink in the GUI counts as Not now for the Workspace's Suggestions.
gui_state::update(cx, |state| {
for repository in unlinked {
state.dismiss(target.id, repository);
}
});
this.handle.close(window, cx);
cx.emit(Saved(target.id));
}
Expand Down Expand Up @@ -713,6 +722,49 @@ mod tests {
assert_eq!(harness.rows(cx), [(WIDGETS.to_owned(), Staged::Unlinking)]);
}

#[gpui::test]
fn should_count_a_saved_unlink_as_not_now(cx: &mut TestAppContext) {
let (harness, cx) = Harness::open(cx);
harness.click("unlink acme/widgets", cx);

harness.save(cx);

let dismissed = cx.update(|_, cx| {
gui_state::read(cx, |s| s.is_dismissed(id(1), repository_id(WIDGETS)))
});
assert!(dismissed);
}

#[gpui::test]
fn should_not_count_an_unlink_cancelled_or_refused(cx: &mut TestAppContext) {
let (harness, cx) = Harness::open(cx);
harness.click("unlink acme/widgets", cx);
harness.api.fail_next("the daemon went away");

harness.save(cx);

let dismissed = cx.update(|_, cx| {
gui_state::read(cx, |s| s.is_dismissed(id(1), repository_id(WIDGETS)))
});
assert!(!dismissed);
}

#[gpui::test]
fn should_suggest_in_the_picker_what_was_told_not_now(cx: &mut TestAppContext) {
let mut snapshot = snapshot();
snapshot.suggestions.insert(
id(1),
vec![crate::overview::fixtures::suggestion("acme/infra")],
);
cx.update(|cx| {
gui_state::update(cx, |s| s.dismiss(id(1), repository_id("acme/infra")))
});

let (_harness, cx) = Harness::open_on(snapshot, true, cx);

assert!(cx.debug_bounds("suggested acme/infra").is_some());
}

#[gpui::test]
fn should_link_on_an_archived_workspace(cx: &mut TestAppContext) {
let mut snapshot = snapshot();
Expand Down
13 changes: 11 additions & 2 deletions crates/agentdeck-gui/src/group_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use gpui::{
};

use crate::api::Api;
use crate::gui_state;
use crate::notice::{Notice, NoticeAction};
use crate::overview::Snapshot;
use crate::pr_table::Linker;
Expand Down Expand Up @@ -184,6 +185,7 @@ pub fn menu(
api.clone(),
workspace.clone(),
repository.clone(),
|_, _| {},
window,
cx,
);
Expand Down Expand Up @@ -230,11 +232,14 @@ pub fn menu(
.into_any_element()
}

/// Links `workspace` to `repository` at once and toasts it, with an Undo that unlinks it.
/// Links `workspace` to `repository` at once and toasts it, with an Undo that unlinks it;
/// `linked` runs once it is linked. Undo doesn't dismiss a Suggestion: it puts things back as
/// they were.
pub fn link(
api: Arc<dyn Api>,
workspace: Linker,
repository: Repository,
linked: impl FnOnce(&mut Window, &mut App) + 'static,
window: &mut Window,
cx: &mut App,
) {
Expand All @@ -243,6 +248,7 @@ pub fn link(
let name = repository.name.to_string();
match done {
Ok(()) => {
linked(window, cx);
let undo = NoticeAction::new("Undo", {
let (workspace, id) = (workspace.clone(), repository.id);
move |window, cx| {
Expand All @@ -266,7 +272,8 @@ pub fn link(
}

/// Unlinks the Workspace whose Pull requests `target` is on from its Repository at once, and
/// toasts it with an Undo that links it again by GitHub's id.
/// toasts it with an Undo that links it again by GitHub's id. The unlink counts as Not now:
/// the Workspace's Suggestions leave the Repository out from then on.
pub fn unlink(api: Arc<dyn Api>, target: Target, window: &mut Window, cx: &mut App) {
let Some(workspace) = target.workspace.clone() else {
return;
Expand All @@ -276,6 +283,8 @@ pub fn unlink(api: Arc<dyn Api>, target: Target, window: &mut Window, cx: &mut A
let name = target.repository.name.to_string();
match done {
Ok(()) => {
let (id, repository) = (workspace.id, target.repository.id);
gui_state::update(cx, |state| state.dismiss(id, repository));
let undo = NoticeAction::new("Undo", {
let (workspace, repository) = (workspace.clone(), target.repository.clone());
move |window, cx| {
Expand Down
Loading