All your machines, one app. For you and your AI agents: agent sessions, desktops, files, logs and GitHub across your Macs, Linux and Windows machines, with an MCP server.
Ask a machine for its GitHub CLI state again until it is signed in (#25)
nobody-ops8b3fa7091259
diff --git a/src/api.rs b/src/api.rsindex f9fc30a..b5d3136 100644--- a/src/api.rs+++ b/src/api.rs@@ -15,7 +15,7 @@ use chrono::{DateTime, Utc};use serde::{Deserialize, Serialize};use crate::fleet::Engine;-use crate::fleet::model::{Job, Machine, Operation, Runner, Snapshot, WorkspaceCommand, WorkspaceInfo};+use crate::fleet::model::{GhCli, Job, Machine, Operation, Runner, Snapshot, WorkspaceCommand, WorkspaceInfo};use crate::fleet::workspaces::{CreateWorkspace, ExecOptions, SyncDirection};use crate::ops::{InstallMode, InstallRequest, NewMachine, RunnerAction};use crate::util;@@ -2529,6 +2529,17 @@ mod tests {workspace_destroy(&engine, WorkspaceDestroyRequest { workspace_id: id.clone(), keep_files: false }, Surface::Mcp).await.unwrap();assert_eq!(workspace_get(&engine, WorkspaceRequest { workspace_id: id }, Surface::Mcp).unwrap_err().code, "not_found");}++ #[test]+ fn a_machine_that_is_not_signed_in_to_the_github_cli_is_asked_again() {+ let cli = |logged_in| Some(GhCli { installed: true, logged_in, ..Default::default() });+ assert!(gh_answer_stands(&cli(true)));+ // Signed out, not installed, and never looked at are all asked again:+ // signing in on the machine is what changes the answer.+ assert!(!gh_answer_stands(&cli(false)));+ assert!(!gh_answer_stands(&Some(GhCli::default())));+ assert!(!gh_answer_stands(&None));+ }}// ---------------------------------------------------------------------------@@ -3168,15 +3179,25 @@ pub struct GitSetupRequest {}/// The machine, with its GitHub CLI state known (asked for when it isn't yet).+///+/// Only "signed in" is taken as known. A machine with no sessions isn't re-read+/// on the timer, so what it said before the user signed in on it is still there+/// when they come back: asking again is what sees the sign-in. Asked now, not+/// when the timer would look at its CLIs again (every 10 minutes).async fn machine_with_gh(engine: &Arc<Engine>, machine_id: &str) -> ApiResult<crate::fleet::model::Machine> {let m = find_machine(&engine.current(), machine_id)?.clone();- if m.gh.is_some() {+ if gh_answer_stands(&m.gh) {return Ok(m);}- let _ = engine.refresh_sessions(&m.id).await;+ let _ = engine.refresh_tools(&m.id).await;Ok(find_machine(&engine.current(), &m.id)?.clone())}+/// Whether a machine's GitHub CLI answer stands as it is (see `machine_with_gh`).+fn gh_answer_stands(gh: &Option<GhCli>) -> bool {+ gh.as_ref().is_some_and(|g| g.logged_in)+}+async fn git_out(engine: &Arc<Engine>, m: &crate::fleet::model::Machine, setup: crate::fleet::code::GitSetup) -> GitSetupOut {let gh_account = m.gh.as_ref().filter(|g| g.logged_in).and_then(|g| g.account.clone());let settings = engine.settings().github;diff --git a/src/fleet/sessions/mod.rs b/src/fleet/sessions/mod.rsindex 29fba5a..9465a3f 100644--- a/src/fleet/sessions/mod.rs+++ b/src/fleet/sessions/mod.rs@@ -197,6 +197,16 @@ impl Engine {/// Sets up the machine's agent if needed, then re-reads its sessions (and,/// now and then, which agent CLIs are installed).pub async fn refresh_sessions(self: &Arc<Self>, machine_id: &str) -> Result<MachineSessions, String> {+ self.discover_sessions(machine_id, false).await+ }++ /// `refresh_sessions`, looking up the installed CLIs (and the GitHub CLI's+ /// login) now rather than when they're due: a sign-in there changes them.+ pub async fn refresh_tools(self: &Arc<Self>, machine_id: &str) -> Result<MachineSessions, String> {+ self.discover_sessions(machine_id, true).await+ }++ async fn discover_sessions(self: &Arc<Self>, machine_id: &str, tools: bool) -> Result<MachineSessions, String> {if let Some(world) = self.demo_world() {let found = self.sessions_of(machine_id).unwrap_or_else(|| world.sessions(machine_id));self.maybe_look_at_git(machine_id, Some(&found), &found);@@ -208,7 +218,7 @@ impl Engine {}spec.refuse_if_disconnected()?;let previous = self.sessions_of(&spec.id);- let detect = previous.as_ref().and_then(|p| p.agents_checked_at).is_none_or(|t| Utc::now() - t > AGENTS_EVERY);+ let detect = tools || previous.as_ref().and_then(|p| p.agents_checked_at).is_none_or(|t| Utc::now() - t > AGENTS_EVERY);let agents: Vec<&str> = if detect { AGENTS.iter().map(|a| a.command).filter(|c| !c.is_empty()).collect() } else { Vec::new() };let result = match agent::ensure(&spec, probe.as_ref()).await {Ok(()) => agent::ctl(&spec, &json!({ "op": "discover", "agents": agents })).await,diff --git a/src/ui/root.rs b/src/ui/root.rsindex 47eedfa..339894a 100644--- a/src/ui/root.rs+++ b/src/ui/root.rs@@ -602,6 +602,11 @@ impl Root {self.announce_notices(&snapshot);// Terminals of sessions that ended go away (one without the agent stops with its terminal).self.terminals.retain(|id, _| snapshot.sessions.iter().any(|s| &s.id == id));+ // A session that ended may have changed git or the GitHub CLI there (the+ // sign-in terminal does): the machine's Git card looks again when shown.+ for s in self.snapshot.sessions.iter().filter(|s| !snapshot.sessions.iter().any(|n| n.id == s.id)) {+ self.machine_git.remove(&s.machine_id);+ }// Looking at a session that just closed: back to its machine.if let Route::Session(id) = self.route.clone() {let gone = !snapshot.sessions.iter().any(|s| s.id == id) && self.snapshot.sessions.iter().any(|s| s.id == id);