Skip to content
Open
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
13 changes: 6 additions & 7 deletions desktop/ox-desk-core/src/store/palette_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,10 @@ impl Store {
pub fn palette_has_more(&self) -> bool {
!self.palette_search.pending && self.palette_search.cursor.is_some()
}
pub fn palette_has_more_for(&self, query: &str) -> bool {
!query.is_empty() && self.palette_query() == query && self.palette_has_more()
}
pub fn palette_search(&mut self, query: &str) -> io::Result<()> {
if self.remote().is_some() {
if self.palette_search.query == query {
return Ok(());
}
self.palette_search.query = query.into();
return self.forward(crate::actions::Action::PaletteSearch(query.into()));
}
if query == self.palette_search.query {
return Ok(());
}
Expand All @@ -62,6 +58,9 @@ impl Store {
query: query.into(),
..Default::default()
};
if self.remote().is_some() {
return self.forward(crate::actions::Action::PaletteSearch(query.into()));
}
if query.is_empty() || !matches!(self.state, Connection::Ready | Connection::SignInRequired)
{
return Ok(());
Expand Down
10 changes: 10 additions & 0 deletions desktop/ox-desk-core/src/store/replica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,16 @@ impl Store {
self.changed.mark(Changed::THREADS);
}
Change::Asks { asks } => {
// A request can move or clear without a session-row update.
// The sidebar caches its waiting rows and count by catalog revision.
if self
.asks
.iter()
.filter_map(|ask| ask.thread.as_ref())
.ne(asks.iter().filter_map(|ask| ask.thread.as_ref()))
{
self.catalog_revision += 1;
}
self.remote_mut().tokens.clear();
self.asks = asks
.into_iter()
Expand Down
112 changes: 108 additions & 4 deletions desktop/ox-desktop/src/app/fleet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ struct Project {
struct CatalogRow {
title: String,
native: Option<ThreadRow>,
/// The host reported an active turn (`SessionView::status == "running"`).
running: bool,
}
impl CatalogRow {
fn live(view: SessionView) -> (String, Self) {
let running = view.status == "running";
let native = replica::row(&view);
(
view.id,
Self {
title: view.title,
native,
running,
},
)
}
Expand Down Expand Up @@ -245,6 +249,7 @@ impl Inventory {
CatalogRow {
title: row.title().to_owned(),
native: Some(row),
running: false,
},
);
}
Expand Down Expand Up @@ -394,6 +399,29 @@ impl Inventory {
rows.sort_by(|a, b| (&a.0.project, &a.2, &a.1).cmp(&(&b.0.project, &b.2, &b.1)));
rows
}

/// Every non-archived session the host reports as running, for the palette's
/// `is:running` token.
pub fn running_rows(&self) -> Vec<(Scope, Option<String>, String)> {
let mut rows = Vec::new();
for (scope, project) in &self.projects {
for (id, row) in &project.titles {
if row.running && !project.archived.contains(id) {
rows.push((
scope.clone(),
Some(id.clone()),
if row.title.is_empty() {
id.clone()
} else {
row.title.clone()
},
));
}
}
}
rows.sort_by(|a, b| (&a.0.project, &a.2, &a.1).cmp(&(&b.0.project, &b.2, &b.1)));
rows
}
fn can_open(&self, scope: Option<&Scope>, thread: Option<&str>) -> bool {
if !self.online {
return false;
Expand Down Expand Up @@ -453,12 +481,16 @@ pub(crate) struct PaletteRow {
pub context: String,
pub target: Destination,
pub online: bool,
/// The row is waiting for an approval, so the palette files it under
/// NEEDS YOU even when a running token is also in the query.
pub needs_you: bool,
}
/// A slash command carries its own arguments, including worker and handoff destinations.
pub(crate) struct Query<'a> {
hosts: Vec<&'a str>,
labels: Vec<&'a str>,
waiting: bool,
pub waiting: bool,
pub running: bool,
pub text: String,
}
impl<'a> Query<'a> {
Expand All @@ -467,6 +499,7 @@ impl<'a> Query<'a> {
hosts: vec![],
labels: vec![],
waiting: false,
running: false,
text: String::new(),
};
let mut words = Vec::new();
Expand All @@ -477,6 +510,8 @@ impl<'a> Query<'a> {
query.labels.push(label);
} else if word == "is:waiting" {
query.waiting = true;
} else if word == "is:running" {
query.running = true;
} else {
words.push(word);
}
Expand All @@ -485,7 +520,7 @@ impl<'a> Query<'a> {
query
}
pub fn scoped(&self) -> bool {
self.waiting || !self.hosts.is_empty() || !self.labels.is_empty()
self.waiting || self.running || !self.hosts.is_empty() || !self.labels.is_empty()
}
fn accepts(&self, inventory: &Inventory, id: &Option<String>) -> bool {
let name = inventory.display_name().to_lowercase();
Expand Down Expand Up @@ -602,7 +637,7 @@ impl super::Workspace {
} else {
name.to_owned()
};
if !query.waiting {
if !query.waiting && !query.running {
rows.push(PaletteRow {
title: name.to_owned(),
context: format!("Host · {identity} · {}", catalog.status()),
Expand All @@ -613,6 +648,7 @@ impl super::Workspace {
thread: None,
},
online,
needs_you: false,
});
}
let view = match id {
Expand All @@ -626,7 +662,36 @@ impl super::Workspace {
} else {
view.map_or(&catalog.saved_sidebar, |v| v.read(cx).sidebar_state())
};
for (scope, thread, mut title) in catalog.rows(query.waiting) {
// Both tokens may be present: `is:waiting is:running` then lists
// every session that needs a response or is running a turn, with
// each row keeping its own section instead of all reading NEEDS YOU.
let mut listed: Vec<(Scope, Option<String>, String, bool)> = Vec::new();
let mut seen: HashSet<(Scope, Option<String>)> = HashSet::new();
let mut push = |row: (Scope, Option<String>, String), needs_you: bool| {
if seen.insert((row.0.clone(), row.1.clone())) {
listed.push((row.0, row.1, row.2, needs_you));
}
};
match (query.waiting, query.running) {
(false, false) => {
for row in catalog.rows(false) {
push(row, false);
}
}
(waiting, running) => {
if waiting {
for row in catalog.rows(true) {
push(row, true);
}
}
if running {
for row in catalog.running_rows() {
push(row, false);
}
}
}
}
for (scope, thread, mut title, needs_you) in listed {
if let Some(meta) = thread.as_ref().and_then(|sid| {
sidebar.thread(&crate::sidebar_state::ThreadMetaKey::new(
scope.project.clone(),
Expand Down Expand Up @@ -657,6 +722,7 @@ impl super::Workspace {
thread,
},
online,
needs_you,
});
}
}
Expand Down Expand Up @@ -1024,6 +1090,7 @@ mod tests {
CatalogRow {
title: title.into(),
native: None,
running: false,
},
)])
};
Expand Down Expand Up @@ -1095,4 +1162,41 @@ mod tests {
hosts[0].receive(CatalogEvent::DraftWaiting(scope, false));
assert!(hosts[0].rows(true).is_empty());
}

#[::core::prelude::v1::test]
fn running_rows_follow_the_hosts_signed_session_status() {
let scope = Scope {
project: "/work/ox".into(),
route: Route::CODEX_SUBSCRIPTION,
};
let view = |id: &str, title: &str, status: &str| SessionView {
id: id.into(),
title: title.into(),
status: status.into(),
parent: None,
updated_at: 0,
capabilities: vec![],
detail: Default::default(),
};
let mut host = Inventory::default();
host.receive(CatalogEvent::Replace(
scope.clone(),
vec![
view("running", "Running turn", "running"),
view("waiting", "Waiting turn", "needs_input"),
view("idle", "Idle turn", "idle"),
],
));
assert_eq!(
host.running_rows()
.into_iter()
.map(|(_, id, title)| (id, title))
.collect::<Vec<_>>(),
vec![(Some("running".into()), "Running turn".into())]
);
// The palette's `is:running` token is a scoped search of running rows.
let query = Query::parse("is:running");
assert!(query.running && query.scoped());
assert_eq!(query.text, "");
}
}
10 changes: 8 additions & 2 deletions desktop/ox-desktop/src/app/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,14 @@ impl Workspace {
.defined
.as_ref()
.and_then(|d| d.new_thread_route.as_ref());
match crate::defined::thread_route(default, offered, in_use.as_ref(), last.as_ref())
{
// The same standard route the sidebar and palette pick: a
// worker harness first, and an API-only host still starts.
match crate::defined::standard_thread_route(
default,
offered,
in_use.as_ref(),
last.as_ref(),
) {
crate::defined::ThreadRoute::Start(route) => route,
crate::defined::ThreadRoute::Ask { unavailable } => {
let name = self.host_name(&host, cx);
Expand Down
Loading
Loading