Skip to content

armgit / muxin

Public Imported from GitHub
0

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.

New box from an issue opens at its task's start; the demo hands off

Adib Hannaafba405b90e6
diff --git a/src/fleet/sessions/handoff.rs b/src/fleet/sessions/handoff.rs
index 6d36634..c032bd1 100644
--- a/src/fleet/sessions/handoff.rs
+++ b/src/fleet/sessions/handoff.rs
@@ -58,13 +58,13 @@ impl Engine {
/// session unless `keep`. A box's agent changes in the box. With
/// `machine` (another one), the work moves there first.
pub async fn handoff_session(self: &Arc<Self>, id: &str, to: &str, keep: bool, machine: Option<&str>) -> Result<HandedOff, String> {
- if self.demo_world().is_some() {
- return Err("The demo's sessions are only for show.".into());
- }
let kind = super::agent(to).filter(|k| !k.command.is_empty()).ok_or_else(|| {
let ids: Vec<&str> = super::AGENTS.iter().filter(|a| !a.command.is_empty()).map(|a| a.id).collect();
format!("Hand off to which agent? Use one of: {}.", ids.join(", "))
})?;
+ if self.demo_world().is_some() {
+ return self.demo_handoff(id, kind, keep, machine).await;
+ }
let snap = self.current();
let s = snap.sessions.iter().find(|s| s.id == id).cloned();
let here = self.find_box(id).map(|b| b.machine_id).ok().or_else(|| s.as_ref().map(|s| s.machine_id.clone()));
@@ -143,6 +143,33 @@ impl Engine {
Ok(HandedOff { session, note: note_path(&note), source: source(&note), kept: keep.then(|| s.id.clone()), box_id: None, workspace: None, warnings: Vec::new() })
}
+ /// The demo's handoff: the new agent's session starts (in a workspace on
+ /// the other machine for a move) and the old one ends, with no note to write.
+ async fn demo_handoff(self: &Arc<Self>, id: &str, kind: &'static AgentKind, keep: bool, machine: Option<&str>) -> Result<HandedOff, String> {
+ let snap = self.current();
+ let s = snap.sessions.iter().find(|s| s.id == id).cloned().ok_or_else(|| format!("No session called {id}."))?;
+ if s.box_id.is_some() {
+ return Err("The demo's boxes are only for show.".into());
+ }
+ let from = super::agent(&s.agent).filter(|k| !k.command.is_empty()).ok_or_else(|| format!("{} is a shell: only an agent's work can be handed off.", s.title))?;
+ let target = match machine.map(str::trim).filter(|m| !m.is_empty()) {
+ Some(m) => snap.machines.iter().find(|x| x.id == m || x.name.eq_ignore_ascii_case(m)).map(|x| x.id.clone()).ok_or_else(|| format!("No machine called {m}."))?,
+ None => s.machine_id.clone(),
+ };
+ let moved = target != s.machine_id;
+ let workspace = moved.then(|| format!("ws-{}", super::super::workspaces::random_id(6)));
+ let cwd = match &workspace {
+ Some(ws) => format!("~/muxen/workspaces/{ws}"),
+ None => s.cwd.clone(),
+ };
+ let title = if s.title == default_title(from, &s.cwd) { default_title(kind, &s.cwd) } else { s.title.clone() };
+ let session = self.start_session(StartSession { machine_id: target, agent: kind.id.into(), cwd: cwd.clone(), title: Some(title), ..Default::default() }).await?;
+ if !keep {
+ self.control_session(&s.id, Control::Stop).await?;
+ }
+ Ok(HandedOff { session, note: format!("{cwd}/{NOTE}"), source: "transcript".into(), kept: keep.then(|| s.id.clone()), box_id: None, workspace, warnings: Vec::new() })
+ }
+
/// Moves session `s`'s work to machine `target` and hands it to `kind`
/// there, as an operation (its steps show in Activity).
async fn move_session(self: &Arc<Self>, s: &SessionInfo, from: &'static AgentKind, kind: &'static AgentKind, target: &str, keep: bool) -> Result<HandedOff, String> {
diff --git a/src/ui/box_dialog.rs b/src/ui/box_dialog.rs
index 62b47ac..2bb3ccc 100644
--- a/src/ui/box_dialog.rs
+++ b/src/ui/box_dialog.rs
@@ -142,7 +142,8 @@ impl BoxDialog {
pub fn new(engine: Arc<Engine>, prefill: BoxPrefill, window: &mut Window, cx: &mut Context<Self>) -> Self {
let BoxPrefill { repo, task, details, name, branch } = prefill;
let repo = cx.new(|cx| TextInput::new(cx, GITHUB_HINT).mono().with_text(repo.unwrap_or_default()));
- let task = cx.new(|cx| TextInput::new(cx, "Fix the login redirect loop, add a test, and open a pull request").with_text(task.unwrap_or_default()));
+ // A task filled in (an issue's) shows from its start.
+ let task = cx.new(|cx| TextInput::new(cx, "Fix the login redirect loop, add a test, and open a pull request").with_text(task.unwrap_or_default()).at_start());
let subs = vec![
cx.subscribe_in(&repo, window, |this: &mut Self, _, e: &InputEvent, _, cx| match e {
// Enter on a result picks it; on what's picked, starts the box.
@@ -403,10 +404,7 @@ impl BoxDialog {
cx.notify();
return;
}
- let prompt = match &self.details {
- Some(d) => format!("{task}\n\n{d}"),
- None => task,
- };
+ let prompt = prompt_for(task, self.details.as_deref());
let req = CreateBox { repo, prompt, agent: self.agent.clone(), machine, name: self.name.clone(), branch: self.branch.clone(), ..Default::default() };
match self.engine.box_create(req) {
Ok((op, _)) => cx.emit(DialogEvent::BoxStarted(op)),
@@ -686,6 +684,14 @@ impl Render for BoxDialog {
}
}
+/// What the box's agent is asked: the task, then what a prefill sends along (an issue).
+pub(super) fn prompt_for(task: String, details: Option<&str>) -> String {
+ match details {
+ Some(d) => format!("{task}\n\n{d}"),
+ None => task,
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/src/ui/github.rs b/src/ui/github.rs
index 5d5d143..8414a28 100644
--- a/src/ui/github.rs
+++ b/src/ui/github.rs
@@ -329,21 +329,7 @@ impl Root {
/// New box, filled in for an issue: its repository, a task that says to fix
/// it (the issue's description goes along), and a branch named for it.
fn gh_to_box(&mut self, d: &Detail, window: &mut Window, cx: &mut Context<Self>) {
- let it = &d.item;
- let body: String = d.body.trim().chars().take(3000).collect();
- let mut details = format!("#{} {}", it.number, it.title);
- if !body.is_empty() {
- details.push_str(&format!("\n\n{body}"));
- }
- let short_repo = it.repo.rsplit('/').next().unwrap_or(&it.repo);
- let prefill = BoxPrefill {
- repo: Some(it.repo.clone()),
- task: Some(format!("Fix this GitHub issue and open a pull request that closes it: {}", it.html_url)),
- details: Some(details),
- name: Some(format!("{short_repo} #{}", it.number)),
- branch: Some(issue_branch(it.number, &it.title)),
- };
- self.show_box_dialog(prefill, window, cx);
+ self.show_box_dialog(box_prefill(d), window, cx);
}
/// `gh_to_agent` for an issue or pull request in a list: loads it first if needed.
@@ -1431,10 +1417,59 @@ fn inline(text: &str) -> String {
out
}
+/// New box for an issue: its repository, a task to fix it and open a pull
+/// request that closes it (its title and description go along to the agent,
+/// unseen), a branch named for it, and a name like "api #12".
+pub(super) fn box_prefill(d: &Detail) -> BoxPrefill {
+ let it = &d.item;
+ let body: String = d.body.trim().chars().take(3000).collect();
+ let mut details = format!("#{} {}", it.number, it.title);
+ if !body.is_empty() {
+ details.push_str(&format!("\n\n{body}"));
+ }
+ let short_repo = it.repo.rsplit('/').next().unwrap_or(&it.repo);
+ BoxPrefill {
+ repo: Some(it.repo.clone()),
+ task: Some(format!("Fix this GitHub issue and open a pull request that closes it: {}", it.html_url)),
+ details: Some(details),
+ name: Some(format!("{short_repo} #{}", it.number)),
+ branch: Some(issue_branch(it.number, &it.title)),
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
+ #[test]
+ fn an_issue_fills_in_new_box() {
+ let item = Item {
+ repo: "adibhanna/muxin-handoff-test".into(),
+ number: 1,
+ title: "average() is off by one".into(),
+ pull_request: false,
+ draft: false,
+ state: "open".into(),
+ author: "adibhanna".into(),
+ assignees: Vec::new(),
+ labels: Vec::new(),
+ comments: 0,
+ created_at: chrono::Utc::now(),
+ updated_at: chrono::Utc::now(),
+ html_url: "https://github.com/adibhanna/muxin-handoff-test/issues/1".into(),
+ };
+ let d = Detail { item, body: "average([2, 4]) returns 4 instead of 3.\n".into(), comments: Vec::new(), pull: None };
+ let p = box_prefill(&d);
+ assert_eq!(p.repo.as_deref(), Some("adibhanna/muxin-handoff-test"));
+ assert_eq!(p.task.as_deref(), Some("Fix this GitHub issue and open a pull request that closes it: https://github.com/adibhanna/muxin-handoff-test/issues/1"));
+ assert_eq!(p.details.as_deref(), Some("#1 average() is off by one\n\naverage([2, 4]) returns 4 instead of 3."));
+ assert_eq!(p.name.as_deref(), Some("muxin-handoff-test #1"));
+ assert_eq!(p.branch.as_deref(), Some("issue-1-average-off-by-one"));
+ // What the box's agent is asked: the task, then the issue.
+ let prompt = super::super::box_dialog::prompt_for(p.task.clone().unwrap(), p.details.as_deref());
+ assert_eq!(prompt, format!("{}\n\n{}", p.task.unwrap(), p.details.unwrap()));
+ }
+
#[test]
fn shortens_titles_at_words() {
assert_eq!(short_title("[Feature] The content in excalidraw cannot be searched globally.", 48), "[Feature] The content in excalidraw cannot be…");
diff --git a/src/ui/input.rs b/src/ui/input.rs
index bf09e4e..6da565d 100644
--- a/src/ui/input.rs
+++ b/src/ui/input.rs
@@ -204,6 +204,12 @@ impl TextInput {
self
}
+ /// Starts with the cursor at the start: a long text filled in shows its beginning.
+ pub fn at_start(mut self) -> Self {
+ self.selected_range = 0..0;
+ self
+ }
+
/// Starts with all of its text selected, so typing replaces it.
pub fn selected(mut self) -> Self {
self.selected_range = 0..self.content.len();
diff --git a/src/ui/move_dialog.rs b/src/ui/move_dialog.rs
index 2796328..5ec78aa 100644
--- a/src/ui/move_dialog.rs
+++ b/src/ui/move_dialog.rs
@@ -99,8 +99,9 @@ impl Render for MoveDialog {
.child(div().flex().flex_wrap().gap(px(6.)).children(agents))
.when(none, |d| d.child(quiet(format!("Muxin hasn't found an agent CLI on {there} yet: install one there (Claude Code, Codex, …).")))) ;
- // What goes along, and where it lands.
- let git = self.session.git.as_ref();
+ // What goes along, and where it lands: the session as it is now (its git may come in after the dialog opens).
+ let current = s.sessions.iter().find(|x| x.id == self.session.id);
+ let git = current.and_then(|x| x.git.as_ref()).or(self.session.git.as_ref());
let what = match git {
Some(g) => {
let mut parts = vec![if g.branch.is_empty() { "its commits".to_string() } else { format!("branch {}", g.branch) }];
diff --git a/src/ui/root.rs b/src/ui/root.rs
index 3e16009..e6d63b5 100644
--- a/src/ui/root.rs
+++ b/src/ui/root.rs
@@ -419,6 +419,8 @@ pub struct Root {
pub(super) box_ui: super::boxes::BoxUi,
/// Sessions being handed to another agent.
pub(super) handing_off: std::collections::HashSet<String>,
+ /// The demo's badge by the name (`badge:off` hides it, for screenshots).
+ demo_badge: bool,
/// This computer's clipboard as last seen (see watch_clipboard).
clipboard_seen: ClipboardSeen,
/// Sessions this app shares, and the guests already announced.
@@ -600,6 +602,7 @@ impl Root {
ws_ui: WorkspaceUi::default(),
box_ui: super::boxes::BoxUi::default(),
handing_off: Default::default(),
+ demo_badge: true,
clipboard_seen: ClipboardSeen { count: super::pasteboard_state().map(|s| s.0).unwrap_or(0), ..Default::default() },
shares: Vec::new(),
knocks_seen: HashSet::new(),
@@ -1007,6 +1010,15 @@ impl Root {
"menu" => self.open_menu(super::menu::MenuTarget::Machine(arg.into()), gpui::point(px(260.), px(160.)), cx),
// A session's Actions menu, under its header's button (for screenshots).
"session-actions" => self.open_menu(super::menu::MenuTarget::SessionActions(arg.into()), gpui::point(px(1080.), px(120.)), cx),
+ // Without the demo's badge (for screenshots).
+ "badge" if arg == "off" => self.demo_badge = false,
+ // A session's Hand off menu, under its button; "move:<session>@<machine>" the Move dialog (for screenshots).
+ "handoff" => self.open_menu(super::menu::MenuTarget::Handoff(arg.into()), gpui::point(px(1190.), px(120.)), cx),
+ "move" => {
+ if let Some((session, machine)) = arg.split_once('@') {
+ self.show_move_dialog(session, machine.to_string(), window, cx);
+ }
+ }
"runner-menu" => self.open_menu(super::menu::MenuTarget::Runner(arg.into()), gpui::point(px(200.), px(560.)), cx),
"favorite" => self.set_favorite_machine(arg, true, cx),
// The palette with this text typed: "palette:" (places), "palette:>set" (commands).
@@ -2295,7 +2307,7 @@ impl Root {
fn brand(&self, theme: &Theme, s: &Snapshot, cx: &mut Context<Self>) -> impl IntoElement {
// GPUI 0.2 only ellipsizes text whose width is known before layout.
- let text_w = self.sidebar_width - 74. - if s.demo { 48. } else { 0. };
+ let text_w = self.sidebar_width - 74. - if s.demo && self.demo_badge { 48. } else { 0. };
div()
.id("brand")
.flex()
@@ -2314,7 +2326,7 @@ impl Root {
.min_w(px(0.))
.child(div().w(px(text_w)).truncate().text_size(px(14.)).font_weight(FontWeight::SEMIBOLD).text_color(theme.text).child("Muxin")),
)
- .when(s.demo, |d| d.child(div().flex_1()).child(kit::pill("demo", theme.warning)))
+ .when(s.demo && self.demo_badge, |d| d.child(div().flex_1()).child(kit::pill("demo", theme.warning)))
}
#[allow(clippy::too_many_arguments)]
diff --git a/src/ui/sessions.rs b/src/ui/sessions.rs
index 7c53181..b8dabff 100644
--- a/src/ui/sessions.rs
+++ b/src/ui/sessions.rs
@@ -602,7 +602,7 @@ impl Root {
)
})
// Another agent takes over (an exited one's work too: it may have run out of usage).
- .when(info.agent != "shell" && !info.agent.is_empty() && info.persistent && offline.is_none() && (!in_box || box_agent) && !self.engine.is_demo(), |d| {
+ .when(info.agent != "shell" && !info.agent.is_empty() && info.persistent && offline.is_none() && (!in_box || box_agent), |d| {
let sid = info.id.clone();
let handing = self.handing_off.contains(&info.id);
d.child(