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.
Boxes: pick a repository or a checkout, and start from a local project
Adib Hannac2a15d97871b
diff --git a/AGENTS.md b/AGENTS.mdindex 2673972..96f6019 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -106,7 +106,7 @@ The CLI equivalents are `muxin session ls|start|read|question|answer|send|do|attA box is one task handed to an agent CLI: a fresh checkout of a repo on a new branch, in a Docker container of its own on one of the user's machines, with the agent running in it with its permission prompts off (the container is its sandbox). Ids look like `box-7k2m9q`.-- `box_create(repo, prompt, agent?, machine_id?)` makes one and starts its agent on the task (default agent `claude`; default machine: the online one with Docker and the most free memory). The first box on a machine builds Muxin's image there, a few minutes. It runs the repo's `.agents/setup` first. The agent can push its branch and open pull requests with the user's GitHub login. Only when the user asked.+- `box_create(repo, prompt, agent?, machine_id?)` makes one and starts its agent on the task. `repo` can also be a checkout's folder on `machine_id` (from `local_checkouts`): the box starts from it with its uncommitted changes, and pushes where it does (default agent `claude`; default machine: the online one with Docker and the most free memory). The first box on a machine builds Muxin's image there, a few minutes. It runs the repo's `.agents/setup` first. The agent can push its branch and open pull requests with the user's GitHub login. Only when the user asked.- `box_list` shows them: `state` (`running`, `starting`, `paused`), `busy`, `attention` (waiting for an answer), `session_id` while it runs, its `task`, and `git` (what it changed, its pull request).- `box_send(box_id, text)` asks its agent more. A paused box starts again and its agent continues the conversation with `text` as the next message; no `text` just starts it. `session_read` and `session_question` work on its `session_id`.- A box pauses by itself after 15 minutes without output from its agent or a shell in it (an open terminal doesn't keep it going), or when its agent quits; `box_pause` pauses it now. Its files and the conversation stay; processes it started (dev servers) end.diff --git a/README.md b/README.mdindex 376fd3d..a3a3000 100644--- a/README.md+++ b/README.md@@ -408,7 +408,8 @@ Build the agent for every platform with `scripts/build-agents.sh` (needs `cargo-Hand a task to an agent and let it work on it by itself, on your own hardware. A box is one task: a fresh checkout of a repository on a new branch, in a Docker container of its own on one of your machines, with an agent CLI working in it.-- **Start one.** **Boxes › New box**: the repository, the task, the agent (Claude Code, Codex, Amp, OpenCode, Gemini CLI or Pi) and where it runs (the online machine with Docker and the most free memory, or one you pick). Muxin clones the repository, runs its `.agents/setup` if it has one, and starts the agent on the task. The first box on a machine builds Muxin's image there (Debian, Node.js, git, the GitHub CLI and the agent CLIs), which takes a few minutes; later boxes start in seconds.+- **Start one.** **Boxes › New box**: the repository, the task, the agent (Claude Code, Codex, Amp, OpenCode, Gemini CLI or Pi) and where it runs (the online machine with Docker and the most free memory, or one you pick). Type to search your GitHub repositories and the checkouts on your machines.+- **A local project.** Pick a checkout on one of your machines (or type its folder): the box goes on that machine and starts from it as it is now, its uncommitted changes and new files included, on a branch of its own. It pushes where the checkout does (an ssh remote goes over https in the box), and the checkout stays as it was; it's the box's `checkout` remote, to fetch its branch from. Muxin clones the repository, runs its `.agents/setup` if it has one, and starts the agent on the task. The first box on a machine builds Muxin's image there (Debian, Node.js, git, the GitHub CLI and the agent CLIs), which takes a few minutes; later boxes start in seconds.- **On its own.** The container is the agent's sandbox, so it runs with its permission prompts off (`--dangerously-skip-permissions` and the like). It works as you, with your GitHub login, so it can push its branch and open a pull request. It sees its own checkout and home and the machine's agent folders (below), not the machine's other files, and Docker isn't shared with it. Its network isn't closed off.- **Pauses by itself.** When its agent has printed nothing for 15 minutes (an open terminal nobody types in doesn't keep it going), or has quit, Muxin's agent on the machine stops the container. That works whether or not the app is open. Its files, branch and conversation stay. Ask it something more (or **Resume**) and it starts again: the agent continues its last conversation, after the repository's `.agents/resume` if it has one. Dev servers and shells it ran don't survive a pause.- **Watch it.** **Open** shows its agent's terminal, like any session. ⌘D (or the split buttons) opens a shell in the box beside it: same container, checkout and tools, so you can run the tests or another agent CLI there. Typing in it counts as using the box, and pausing the box ends it. The Boxes page shows each box working, waiting for you, idle or paused, with its branch, what it changed and its pull request with checks.@@ -419,6 +420,7 @@ Hand a task to an agent and let it work on it by itself, on your own hardware. A```shmuxin box new acme/api "Add rate limit headers to every response, with tests, and open a pull request"muxin box new acme/api "Fix the flaky webhook test" --agent codex --on beelink+muxin box new ~/code/app "Finish this refactor" --on beelink # a checkout there, with its uncommitted workmuxin box ls # every box: working, waiting, idle or paused, and its gitmuxin box send box-7k2m9q "Also update the API docs" # starts it again if it's pausedmuxin box attach box-7k2m9q # its agent, in this terminaldiff --git a/src/fleet/boxes/mod.rs b/src/fleet/boxes/mod.rsindex 1b3685e..cf0c8f1 100644--- a/src/fleet/boxes/mod.rs+++ b/src/fleet/boxes/mod.rs@@ -133,6 +133,9 @@ pub struct BoxInfo {pub session_id: Option<String>,/// What it was first asked.pub task: String,+ /// The checkout on its machine it was made from (a local project), if it was.+ #[serde(skip_serializing_if = "Option::is_none")]+ pub checkout: Option<String>,/// The checkout on the machine.pub path: String,pub idle_minutes: u32,@@ -170,6 +173,7 @@ pub(crate) fn parse(machine_id: &str, reply: &Value) -> Vec<BoxInfo> {agent,state: b["state"].as_str().unwrap_or("paused").to_string(),task: str_of("task"),+ checkout: b["checkout"].as_str().filter(|c| !c.is_empty()).map(str::to_string),path: str_of("path"),idle_minutes: b["idle_minutes"].as_u64().map(|m| m as u32).unwrap_or(IDLE_MINUTES),created_at: ts(&b["created"]),@@ -209,6 +213,11 @@ struct Plan {name: String,agent: String,repo: Repo,+ /// `repo` is a checkout on the box's machine (a local project): cloned+ /// from there, with its uncommitted changes.+ local: bool,+ /// The GitHub repository it pushes to ("owner/name"): `repo`'s, or the checkout's origin's.+ github: Option<String>,git_ref: String,branch: String,task: String,@@ -253,7 +262,16 @@ impl Engine {};let branch = req.branch.map(|b| b.trim().to_string()).filter(|b| !b.is_empty()).unwrap_or_else(|| format!("box/{}", short_slug(&name)));workspaces::validate_git_ref(&branch)?;+ // A folder on a machine: a checkout there (a local project), so the box goes there too.+ let local = repo.url.starts_with('/') || repo.url.starts_with("~/");+ if local && req.machine.as_deref().is_none_or(|m| m.trim().is_empty()) {+ return Err(format!("Say which machine {} is on.", repo.shown));+ }let spec = self.box_machine(req.machine.as_deref())?;+ let github = match local {+ true => self.checkouts_of(&spec.id).into_iter().find(|c| workspaces::same_folder(&c.path, &repo.url)).and_then(|c| c.repo),+ false => repo.on_github.then(|| workspaces::github_full_name(&repo)).flatten(),+ };let taken: Vec<String> = self.boxes().into_iter().map(|b| b.id).collect();let id = loop {let id = format!("box-{}", workspaces::random_id(6));@@ -261,7 +279,7 @@ impl Engine {break id;}};- let plan = Plan { id: id.clone(), name, agent, repo, git_ref, branch, task, cpus: req.cpus, memory_gb: req.memory_gb, idle_minutes: req.idle_minutes.unwrap_or(IDLE_MINUTES) };+ let plan = Plan { id: id.clone(), name, agent, repo, local, github, git_ref, branch, task, cpus: req.cpus, memory_gb: req.memory_gb, idle_minutes: req.idle_minutes.unwrap_or(IDLE_MINUTES) };let op = self.begin_op("box", format!("Make box {} on {}", plan.name, spec.name), Some(spec.id.clone()), None);let me = self.clone();self.runtime().spawn(async move {@@ -313,28 +331,40 @@ impl Engine {// GitHub: the token clones a private repo and lets the agent push and// open pull requests; commits are the user's, with their noreply address.let settings = self.settings().github;- let token = match plan.repo.on_github {- true => self.github().git_credentials(&settings).await.filter(|(host, _)| *host == plan.repo.host).map(|(_, t)| t),- false => None,+ // A checkout Muxin hasn't looked at yet: where it pushes, asked of it.+ let github = match (&plan.github, plan.local) {+ (None, true) => checkout_github(spec, &plan.repo.url, &workspaces::github_web_host(&settings.api_url)).await,+ (g, _) => g.clone(),+ };+ // The GitHub host it pushes to: its URL's, or (a checkout) GitHub's when its origin is there.+ let gh_host = match (plan.repo.on_github, &github) {+ (true, _) => Some(plan.repo.host.clone()),+ (false, Some(_)) => Some(workspaces::github_web_host(&settings.api_url)),+ (false, None) => None,+ };+ let token = match &gh_host {+ Some(h) => self.github().git_credentials(&settings).await.filter(|(host, _)| host == h).map(|(_, t)| t),+ None => None,};let identity = match self.github().viewer(&settings).await {Ok(v) => self.github().commit_identity(&settings, &v.login).await.ok(),Err(_) => None,};- if token.is_none() && plan.repo.on_github {+ if token.is_none() && gh_host.is_some() {self.op_log(op, "! No GitHub token: the agent can't push or open pull requests from the box");}+ let gh_host = gh_host.unwrap_or_default();let l = launch(&plan.agent).ok_or("That agent can't run in a box.")?;let mut env: Vec<(String, String)> = vec![("MUXIN_BOX".into(), plan.id.clone())];if let Some(t) = &token {env.push(("GH_TOKEN".into(), t.clone()));- if plan.repo.host != "github.com" {- env.push(("GH_HOST".into(), plan.repo.host.clone()));+ if gh_host != "github.com" {+ env.push(("GH_HOST".into(), gh_host.clone()));env.push(("GH_ENTERPRISE_TOKEN".into(), t.clone()));}}- let files = home_files(&l, &env, identity.as_ref(), token.as_ref().map(|_| plan.repo.host.as_str()));+ let files = home_files(&l, &env, identity.as_ref(), token.as_ref().map(|_| gh_host.as_str()));let encoded: Vec<String> = files.iter().map(|(path, mode, text)| format!("{path}\t{mode}\t{}", B64.encode(text))).collect();// Signed in as on the machine: its agent folders mounted (the box's// agent's made when missing, so a sign-in in the box stays), and a@@ -344,7 +374,8 @@ impl Engine {let copy: Vec<String> = vec![".claude.json".into()];let db_dirs: Vec<String> = DB_DIRS.iter().map(|d| d.to_string()).collect();let db_copy: Vec<String> = DB_COPY.iter().map(|d| d.to_string()).collect();- let header = token.as_ref().map(|t| format!("AUTHORIZATION: basic {}", B64.encode(format!("x-access-token:{t}")))).unwrap_or_default();+ // Only a clone from GitHub needs the token (a checkout is cloned from its folder).+ let header = token.as_ref().filter(|_| !plan.local).map(|t| format!("AUTHORIZATION: basic {}", B64.encode(format!("x-access-token:{t}")))).unwrap_or_default();let image = format!("muxen-box:{:08x}", fnv(DOCKERFILE.as_bytes()) as u32);let container = format!("muxen-{}", plan.id);let hostname = short_slug(&plan.name);@@ -360,6 +391,7 @@ impl Engine {("OR_IMAGE", Param::Str(&image)),("OR_DOCKERFILE", Param::Str(DOCKERFILE)),("OR_REPO", Param::Str(&plan.repo.url)),+ ("OR_LOCAL", Param::Bool(plan.local)),("OR_REPO_SHOWN", Param::Str(&plan.repo.shown)),("OR_REF", Param::Str(&plan.git_ref)),("OR_BRANCH", Param::Str(&plan.branch)),@@ -385,7 +417,8 @@ impl Engine {let record = json!({"id": plan.id,"name": plan.name,- "repo": plan.repo.shown,+ "repo": github.clone().unwrap_or_else(|| plan.repo.shown.clone()),+ "checkout": plan.local.then(|| plan.repo.shown.clone()),"branch": plan.branch,"agent": plan.agent,"task": plan.task,@@ -465,6 +498,27 @@ impl Engine {}}+/// The GitHub repository ("owner/name") a checkout on a machine pushes to: its origin's.+async fn checkout_github(spec: &MachineSpec, path: &str, gh_host: &str) -> Option<String> {+ let folder = match path.strip_prefix("~/") {+ Some(rest) => format!("\"$HOME\"/{}", sh_quote(rest)),+ None => sh_quote(path),+ };+ let url = remote::output(spec, Shell::Sh, format!("git -C {folder} remote get-url origin\n"), Duration::from_secs(30)).await.ok()?;+ github_name(url.trim(), gh_host)+}++/// "owner/name" of a git URL on the GitHub host: https, or ssh (git@host:owner/name).+fn github_name(url: &str, gh_host: &str) -> Option<String> {+ let ssh = [format!("git@{gh_host}:"), format!("ssh://git@{gh_host}/")];+ let https = match ssh.iter().find_map(|p| url.strip_prefix(p.as_str())) {+ Some(path) => format!("https://{gh_host}/{path}"),+ None => url.to_string(),+ };+ let repo = workspaces::normalize_repo(&https, gh_host).ok()?;+ repo.on_github.then(|| workspaces::github_full_name(&repo)).flatten()+}+/// The files of a box's home Muxin writes: path (under /home/box), mode and contents.fn home_files(l: &Launch, env: &[(String, String)], identity: Option<&(String, String)>, git_host: Option<&str>) -> Vec<(String, &'static str, String)> {let mut files: Vec<(String, &'static str, String)> = Vec::new();@@ -481,6 +535,8 @@ fn home_files(l: &Launch, env: &[(String, String)], identity: Option<&(String, Sif let Some(host) = git_host {files.push((".muxin/git-credential".into(), "755", GIT_CREDENTIAL.into()));gitconfig.push_str(&format!("[credential \"https://{host}\"]\n\thelper = /home/box/.muxin/git-credential\n"));+ // A box has no ssh keys: ssh remotes (a checkout's, say) go over https, with the token.+ gitconfig.push_str(&format!("[url \"https://{host}/\"]\n\tinsteadOf = git@{host}:\n\tinsteadOf = ssh://git@{host}/\n"));}gitconfig.push_str("[init]\n\tdefaultBranch = main\n[push]\n\tautoSetupRemote = true\n");files.push((".gitconfig".into(), "644", gitconfig));@@ -627,6 +683,15 @@ mod tests {}}+ #[test]+ fn a_checkouts_origin_names_its_github_repo() {+ assert_eq!(github_name("https://github.com/acme/api.git", "github.com").as_deref(), Some("acme/api"));+ assert_eq!(github_name("[email protected]:acme/api.git", "github.com").as_deref(), Some("acme/api"));+ assert_eq!(github_name("ssh://[email protected]/acme/api", "github.com").as_deref(), Some("acme/api"));+ assert_eq!(github_name("[email protected]:acme/api.git", "github.com"), None);+ assert_eq!(github_name("/srv/git/api.git", "github.com"), None);+ }+#[test]fn sessions_belong_to_their_box() {let boxes = vec![BoxInfo { id: "box-ab12cd".into(), ..Default::default() }];diff --git a/src/fleet/boxes/scripts/create.sh b/src/fleet/boxes/scripts/create.shindex 008b896..3dac119 100644--- a/src/fleet/boxes/scripts/create.sh+++ b/src/fleet/boxes/scripts/create.sh@@ -2,9 +2,12 @@# time), a checkout of the repository, the agent's home and a container# running as this user, then the repository's .agents/setup in it.# Prepended: OR_ID OR_CONTAINER OR_HOSTNAME OR_IMAGE OR_DOCKERFILE OR_REPO-# OR_REPO_SHOWN OR_REF OR_BRANCH OR_AUTH OR_FILES OR_COPY OR_MOUNTS OR_ENSURE-# OR_DB_DIRS OR_DB_COPY OR_CPUS OR_MEM. OR_AUTH is an http.extraHeader value; it only ever lives in-# this process's environment. OR_FILES: one file of the agent's home per+# OR_LOCAL OR_REPO_SHOWN OR_REF OR_BRANCH OR_AUTH OR_FILES OR_COPY OR_MOUNTS+# OR_ENSURE OR_DB_DIRS OR_DB_COPY OR_CPUS OR_MEM. OR_AUTH is an+# http.extraHeader value; it only ever lives in this process's environment.+# OR_LOCAL: OR_REPO is a checkout here (a local project): it's cloned from+# that folder with its uncommitted changes (and new files that aren't+# ignored), and pushes where the checkout does. OR_FILES: one file of the agent's home per# line, "<path>\t<mode>\t<base64>". OR_COPY: files of this user's home copied# into the agent's when they're here. OR_MOUNTS: this user's agent folders# (~/.claude, ~/.codex, ...) mounted into the agent's home when they're here,@@ -47,6 +50,34 @@ export GIT_TERMINAL_PROMPT=0if [ -n "$OR_AUTH" ]; thenexport GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=http.extraHeader GIT_CONFIG_VALUE_0="$OR_AUTH"fi+if [ "$OR_LOCAL" = 1 ]; then+ src=$OR_REPO+ case "$src" in "~") src=$HOME ;; "~/"*) src="$HOME/${src#\~/}" ;; esac+ git -C "$src" rev-parse --is-inside-work-tree >/dev/null 2>&1 </dev/null || fail "$OR_REPO_SHOWN isn't a git checkout on $(hostname)."+ echo "▸ Copying the checkout $OR_REPO_SHOWN"+ git clone --quiet "$src" . </dev/null 2>&1 || { echo "error: git clone failed" >&2; exit 4; }+ if [ -n "$OR_REF" ]; then+ git -c advice.detachedHead=false checkout --quiet "$OR_REF" 2>&1 || fail "Couldn't check out $OR_REF."+ else+ # Where the checkout is now: its uncommitted changes, and its new files.+ git -C "$src" diff HEAD --binary > "$dir/.changes" 2>/dev/null </dev/null+ if [ -s "$dir/.changes" ]; then+ git apply --whitespace=nowarn "$dir/.changes" 2>&1 </dev/null || echo "! Some of its uncommitted changes didn't carry over"+ fi+ rm -f "$dir/.changes"+ (cd "$src" && git ls-files --others --exclude-standard -z </dev/null | tar cf - --null -T -) | tar xf - 2>/dev/null+ or_n=$(git status --porcelain 2>/dev/null </dev/null | wc -l | tr -d ' ')+ [ "${or_n:-0}" -gt 0 ] && echo "✓ Brought along its $or_n uncommitted files"+ fi+ # It pushes where the checkout does; the checkout itself stays a remote ("checkout").+ or_origin=$(git -C "$src" remote get-url origin 2>/dev/null </dev/null)+ if [ -n "$or_origin" ]; then+ git remote set-url origin "$or_origin"+ git remote add checkout "$src"+ else+ git remote rename origin checkout+ fi+elseecho "▸ Cloning $OR_REPO_SHOWN"case "$OR_REF" inpull/*/head)@@ -63,6 +94,7 @@ case "$OR_REF" ingit -c advice.detachedHead=false checkout --quiet "$OR_REF" 2>&1 || fail "Couldn't check out $OR_REF.";;esac+fiunset GIT_CONFIG_COUNT GIT_CONFIG_KEY_0 GIT_CONFIG_VALUE_0if [ -n "$OR_BRANCH" ]; thengit checkout --quiet -b "$OR_BRANCH" 2>&1 || fail "Couldn't make the branch $OR_BRANCH."diff --git a/src/main.rs b/src/main.rsindex 35a6933..31d1e41 100644--- a/src/main.rs+++ b/src/main.rs@@ -1042,7 +1042,7 @@ struct BoxLsArgs {struct BoxNewArgs {#[command(flatten)]agent: AgentArgs,- /// owner/name on GitHub, or a git URL+ /// owner/name on GitHub, a git URL, or a checkout's folder on the --on machine (with its uncommitted work)repo: String,/// What the agent is asked to do#[arg(num_args = 1..)]diff --git a/src/mcp.rs b/src/mcp.rsindex 463bcd5..a45efa7 100644--- a/src/mcp.rs+++ b/src/mcp.rs@@ -640,7 +640,7 @@ pub fn tools() -> Vec<Value> {"name": "box_create","description": "Hand a task to an agent in a new box: Muxin clones the repo onto a new branch in a container of its own on one of the user's machines (one with Docker; the first box there builds Muxin's image, a few minutes), runs the repo's .agents/setup, and starts the agent CLI there on the prompt with its permission prompts off (the container is its sandbox). It can push and open pull requests with the user's GitHub login. The box pauses by itself when its agent has been quiet for a while; box_send picks it up again. Waits until the agent has started (wait: false returns an operation_id to poll). Only when the user asked for it.","inputSchema": schema(json!({- "repo": { "type": "string", "description": "owner/name on GitHub, or a git URL." },+ "repo": { "type": "string", "description": "owner/name on GitHub, a git URL, or a checkout's folder on machine_id (see local_checkouts): the box starts from that checkout with its uncommitted changes." },"prompt": { "type": "string", "description": "The task: what the agent is asked to do (an issue's URL and text works well)." },"agent": { "type": "string", "enum": ["claude", "codex", "amp", "opencode", "gemini", "pi"], "description": "Which agent CLI. Default claude. It's signed in as it is on that machine (its ~/.claude, ~/.codex, ... are shared with the box); if it isn't signed in there, the user signs it in once from the box's terminal." },"machine_id": { "type": "string", "description": "Where it runs. Default: the online machine with Docker and the most free memory." },diff --git a/src/ui/box_dialog.rs b/src/ui/box_dialog.rsindex 2d8d39b..e1e8833 100644--- a/src/ui/box_dialog.rs+++ b/src/ui/box_dialog.rs@@ -1,5 +1,6 @@//! New box: a task for an agent that works on it by itself, in a container-//! of its own on one of your machines.+//! of its own on one of your machines, from one of your repositories or a+//! checkout on that machine (a local project).use std::sync::Arc;@@ -8,10 +9,15 @@ use gpui::{AnyElement, App, Context, Entity, EventEmitter, FocusHandle, Focusabluse super::dialogs::{DialogEvent, MODAL_CHROME, error_line, field, footer, frame};use super::input::{InputEvent, TextInput};use super::kit::{self, Button, ButtonStyle};-use super::theme::ActiveTheme;+use super::theme::{ActiveTheme, Theme, mono_font};use crate::fleet::Engine;use crate::fleet::boxes::{BOX_AGENTS, CreateBox};-use crate::fleet::model::Machine;+use crate::fleet::model::{Checkout, Machine};+use crate::github::hub;++/// How many of each the Repository field suggests.+const SHOW_CHECKOUTS: usize = 4;+const SHOW_REPOS: usize = 6;pub struct BoxDialog {engine: Arc<Engine>,@@ -20,6 +26,10 @@ pub struct BoxDialog {agent: String,/// None: the machine with Docker and the most free memory.machine: Option<String>,+ /// Your GitHub repositories (favorites first), once they're read.+ repos: Option<Vec<hub::Repo>>,+ /// A checkout picked from the list: the box goes on its machine, made from it.+ checkout: Option<Checkout>,error: Option<String>,_subscriptions: Vec<Subscription>,}@@ -34,7 +44,7 @@ fn can_run(m: &Machine) -> bool {impl BoxDialog {/// `repo` and `task`, when something opened it with them (an issue to fix).pub fn new(engine: Arc<Engine>, repo: Option<String>, task: Option<String>, window: &mut Window, cx: &mut Context<Self>) -> Self {- let repo = cx.new(|cx| TextInput::new(cx, "owner/name, or a git URL").mono().with_text(repo.unwrap_or_default()));+ let repo = cx.new(|cx| TextInput::new(cx, "Search your repositories and checkouts, or owner/name, a git URL, a folder").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()));let mut subs = Vec::new();for i in [&repo, &task] {@@ -43,22 +53,59 @@ impl BoxDialog {InputEvent::Cancel => cx.emit(DialogEvent::Dismissed),InputEvent::Changed => {this.error = None;+ // Typed over the checkout picked: it's what's typed now.+ let typed = this.repo.read(cx).text().trim().to_string();+ if this.checkout.as_ref().is_some_and(|c| c.path != typed) {+ this.checkout = None;+ }cx.notify()}}));}- BoxDialog { engine, repo, task, agent: "claude".into(), machine: None, error: None, _subscriptions: subs }+ // Your repositories, and the checkouts on the machines boxes can run on.+ let job = engine.runtime().spawn({+ let engine = engine.clone();+ async move {+ let s = engine.current();+ let unread: Vec<String> = s.machines.iter().filter(|m| can_run(m) && engine.checkouts_of(&m.id).is_empty()).map(|m| m.id.clone()).collect();+ futures::future::join_all(unread.iter().map(|id| engine.refresh_checkouts(id))).await;+ crate::api::github_repos(&engine).await.ok()+ }+ });+ cx.spawn(async move |this, cx| {+ let repos = job.await.ok().flatten();+ let _ = this.update(cx, |this, cx| {+ this.repos = Some(repos.unwrap_or_default());+ cx.notify()+ });+ })+ .detach();+ BoxDialog { engine, repo, task, agent: "claude".into(), machine: None, repos: None, checkout: None, error: None, _subscriptions: subs }}pub fn first_focus(&self, cx: &App) -> FocusHandle {if self.repo.read(cx).text().trim().is_empty() { self.repo.focus_handle(cx) } else { self.task.focus_handle(cx) }}+ fn pick_repo(&mut self, name: String, cx: &mut Context<Self>) {+ self.checkout = None;+ self.repo.update(cx, |i, cx| i.set_text(name, cx));+ cx.notify();+ }++ fn pick_checkout(&mut self, c: Checkout, cx: &mut Context<Self>) {+ self.machine = Some(c.machine_id.clone());+ let path = c.path.clone();+ self.checkout = Some(c);+ self.repo.update(cx, |i, cx| i.set_text(path, cx));+ cx.notify();+ }+fn submit(&mut self, cx: &mut Context<Self>) {let repo = self.repo.read(cx).text().trim().to_string();let task = self.task.read(cx).text().trim().to_string();if repo.is_empty() {- self.error = Some("Which repository? owner/name for GitHub, or a git URL.".into());+ self.error = Some("Which repository? Pick one, or type owner/name, a git URL or a folder.".into());cx.notify();return;}@@ -67,7 +114,8 @@ impl BoxDialog {cx.notify();return;}- let req = CreateBox { repo, prompt: task, agent: self.agent.clone(), machine: self.machine.clone(), ..Default::default() };+ let machine = self.checkout.as_ref().map(|c| c.machine_id.clone()).or_else(|| self.machine.clone());+ let req = CreateBox { repo, prompt: task, agent: self.agent.clone(), machine, ..Default::default() };match self.engine.box_create(req) {Ok((op, _)) => cx.emit(DialogEvent::BoxStarted(op)),Err(e) => {@@ -76,6 +124,92 @@ impl BoxDialog {}}}++ /// The Repository field's suggestions: checkouts on the machines boxes+ /// can run on, then your GitHub repositories, matching what's typed.+ fn suggestions(&self, theme: &Theme, typed: &str, cx: &mut Context<Self>) -> Option<AnyElement> {+ let q = typed.to_lowercase();+ // Picked (or typed exactly): nothing more to suggest.+ if self.checkout.as_ref().is_some_and(|c| c.path == typed) || self.repos.iter().flatten().any(|r| r.full_name.eq_ignore_ascii_case(typed)) {+ return None;+ }+ let s = self.engine.current();+ let machine_name = |id: &str| s.machines.iter().find(|m| m.id == id).map(|m| m.name.clone()).unwrap_or_else(|| id.to_string());+ let runs = |id: &str| s.machines.iter().any(|m| m.id == id && can_run(m));+ let checkouts: Vec<Checkout> = s+ .checkouts+ .iter()+ .filter(|c| runs(&c.machine_id))+ .filter(|c| q.is_empty() || c.path.to_lowercase().contains(&q) || c.repo.as_deref().is_some_and(|r| r.to_lowercase().contains(&q)) || machine_name(&c.machine_id).to_lowercase().contains(&q))+ .take(SHOW_CHECKOUTS)+ .cloned()+ .collect();+ let repos: Vec<hub::Repo> = self.repos.iter().flatten().filter(|r| !r.archived && (q.is_empty() || r.full_name.to_lowercase().contains(&q))).take(SHOW_REPOS).cloned().collect();+ let row = |id: SharedString, icon: &'static str, title: String, detail: String| {+ div()+ .id(id)+ .flex()+ .items_center()+ .gap(px(8.))+ .px(px(8.))+ .py(px(5.))+ .rounded(px(6.))+ .cursor_pointer()+ .hover(|st| st.bg(theme.ghost_hover))+ .child(kit::icon(icon, 13., theme.text_placeholder))+ .child(div().flex_none().max_w(px(260.)).truncate().font_family(mono_font()).text_size(px(12.)).text_color(theme.text).child(title))+ .child(div().flex_1().min_w(px(0.)).truncate().text_size(px(11.5)).text_color(theme.text_placeholder).child(detail))+ };+ let heading = |text: &'static str| div().px(px(8.)).pt(px(4.)).text_size(px(11.)).text_color(theme.text_placeholder).child(text);+ let mut list: Vec<AnyElement> = Vec::new();+ if !checkouts.is_empty() {+ list.push(heading("On your machines").into_any_element());+ for (i, c) in checkouts.into_iter().enumerate() {+ let mut detail = vec![machine_name(&c.machine_id)];+ if !c.branch.is_empty() {+ detail.push(c.branch.clone());+ }+ if c.dirty > 0 {+ detail.push(format!("{} uncommitted", c.dirty));+ }+ if let Some(r) = &c.repo {+ detail.push(r.clone());+ }+ let pick = c.clone();+ list.push(+ row(SharedString::from(format!("bx-co-{i}")), "folder", c.path.clone(), detail.join(" · "))+ .on_click(cx.listener(move |this, _, _, cx| this.pick_checkout(pick.clone(), cx)))+ .into_any_element(),+ );+ }+ }+ match &self.repos {+ None => list.push(div().px(px(8.)).py(px(4.)).text_size(px(11.5)).text_color(theme.text_placeholder).child("Reading your repositories…").into_any_element()),+ Some(_) if repos.is_empty() => {}+ Some(_) => {+ list.push(heading("On GitHub").into_any_element());+ for r in repos {+ let mut detail = Vec::new();+ if r.favorite {+ detail.push("favorite".to_string());+ }+ if r.private {+ detail.push("private".into());+ }+ if let Some(d) = r.description.clone().filter(|d| !d.is_empty()) {+ detail.push(d);+ }+ let name = r.full_name.clone();+ list.push(+ row(SharedString::from(format!("bx-gh-{}", r.full_name)), "agent-github", r.full_name.clone(), detail.join(" · "))+ .on_click(cx.listener(move |this, _, _, cx| this.pick_repo(name.clone(), cx)))+ .into_any_element(),+ );+ }+ }+ }+ (!list.is_empty()).then(|| div().flex().flex_col().gap(px(1.)).p(px(4.)).rounded(px(8.)).border_1().border_color(theme.border_variant).bg(theme.surface).children(list).into_any_element())+ }}impl Focusable for BoxDialog {@@ -105,26 +239,24 @@ impl Render for BoxDialog {};let s = self.engine.current();- // Your favorite repositories, one click away.let typed = self.repo.read(cx).text().trim().to_string();- let favorites: Vec<AnyElement> = self- .engine- .settings()- .favorite_repos- .into_iter()- .take(8)- .map(|name| {- let pick = name.clone();- base(SharedString::from(format!("bx-r-{name}")), typed.eq_ignore_ascii_case(&name), true)- .child(name)- .on_click(cx.listener(move |this, _, _, cx| {- this.repo.update(cx, |i, cx| i.set_text(pick.clone(), cx));- cx.notify()- }))- .into_any_element()- })- .collect();- let repo = div().flex().flex_col().gap(px(8.)).child(self.repo.clone()).when(!favorites.is_empty(), |d| d.child(div().flex().flex_wrap().gap(px(6.)).children(favorites)));+ let picked = self.checkout.clone().filter(|c| c.path == typed);+ let note = match &picked {+ Some(c) => Some(format!(+ "A checkout on {}: the box starts from it{}, on a branch of its own. Your checkout isn't touched.",+ s.machines.iter().find(|m| m.id == c.machine_id).map(|m| m.name.clone()).unwrap_or_else(|| c.machine_id.clone()),+ if c.dirty > 0 { format!(", with its {} uncommitted files", c.dirty) } else { String::new() }+ )),+ None if typed.starts_with('/') || typed.starts_with("~/") => Some("A folder: a git checkout on the machine picked below, which the box starts from (with its uncommitted changes).".to_string()),+ None => None,+ };+ let repo = div()+ .flex()+ .flex_col()+ .gap(px(8.))+ .child(self.repo.clone())+ .children(self.suggestions(&theme, &typed, cx))+ .children(note.map(|n| div().text_size(px(11.5)).text_color(theme.text_placeholder).child(n)));let agents: Vec<AnyElement> = BOX_AGENTS.iter()@@ -153,19 +285,25 @@ impl Render for BoxDialog {"{name} is signed in as it is on that machine. If it isn't signed in there, sign it in once from the box's terminal.")));- // Where: the best machine, or one picked.- let mut machines: Vec<AnyElement> = vec![base("bx-m-auto".into(), self.machine.is_none(), true)- .child("Best one")- .on_click(cx.listener(|this, _, _, cx| {- this.machine = None;- cx.notify()- }))- .into_any_element()];- machines.extend(s.machines.iter().filter(|m| m.status == "online" && !m.platform.starts_with("windows")).map(|m| {+ // Where: the best machine, or one picked (a checkout's own, when one is).+ let fixed = picked.as_ref().map(|c| c.machine_id.clone());+ let mut machines: Vec<AnyElement> = Vec::new();+ if fixed.is_none() {+ machines.push(+ base("bx-m-auto".into(), self.machine.is_none(), true)+ .child("Best one")+ .on_click(cx.listener(|this, _, _, cx| {+ this.machine = None;+ cx.notify()+ }))+ .into_any_element(),+ );+ }+ machines.extend(s.machines.iter().filter(|m| m.status == "online" && !m.platform.starts_with("windows")).filter(|m| fixed.as_ref().is_none_or(|f| *f == m.id)).map(|m| {let id = m.id.clone();let ok = can_run(m);let (from, to) = super::format::machine_tile(m);- base(SharedString::from(format!("bx-m-{id}")), self.machine.as_deref() == Some(id.as_str()), ok)+ base(SharedString::from(format!("bx-m-{id}")), self.machine.as_deref() == Some(id.as_str()) || fixed.as_deref() == Some(id.as_str()), ok).pl(px(4.)).child(kit::tile(super::format::machine_icon(m), from, to, 18.)).child(m.name.clone())@@ -184,10 +322,10 @@ impl Render for BoxDialog {.flex_col().gap(px(8.)).child(div().flex().flex_wrap().gap(px(6.)).children(machines))- .child(div().text_size(px(11.5)).text_color(if any { theme.text_placeholder } else { theme.warning }).child(if any {- "In a Docker container there, on a new branch of a fresh checkout. The first box on a machine builds Muxin's image (a few minutes)."- } else {- "Boxes run in Docker: install it on a Linux machine or a Mac (Docker Desktop, OrbStack or Colima)."+ .child(div().text_size(px(11.5)).text_color(if any { theme.text_placeholder } else { theme.warning }).child(match (any, fixed.is_some()) {+ (false, _) => "Boxes run in Docker: install it on a Linux machine or a Mac (Docker Desktop, OrbStack or Colima).",+ (true, true) => "On the checkout's machine, in a Docker container there. The first box on a machine builds Muxin's image (a few minutes).",+ (true, false) => "In a Docker container there, on a new branch of a fresh checkout. The first box on a machine builds Muxin's image (a few minutes).",}));let body_max = (f32::from(window.viewport_size().height) - MODAL_CHROME).max(220.);