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.

Demo mode's GitHub is simulated; a view that opens a port

Adib Hannaeccd8771737f
diff --git a/src/api.rs b/src/api.rs
index 84d771a..7f615dc 100644
--- a/src/api.rs
+++ b/src/api.rs
@@ -2708,6 +2708,9 @@ pub struct GitOut {
}
pub async fn github_inbox(engine: &Arc<Engine>) -> ApiResult<hub::Inbox> {
+ if engine.is_demo() {
+ return Ok(crate::demo::github::inbox());
+ }
let settings = engine.settings().github;
engine.github().inbox(&settings).await.map_err(github_error)
}
@@ -2715,7 +2718,7 @@ pub async fn github_inbox(engine: &Arc<Engine>) -> ApiResult<hub::Inbox> {
/// Your repositories, favorites first, then most recently pushed.
pub async fn github_repos(engine: &Arc<Engine>) -> ApiResult<Vec<hub::Repo>> {
let settings = engine.settings();
- let mut repos = engine.github().my_repos(&settings.github).await.map_err(github_error)?;
+ let mut repos = if engine.is_demo() { crate::demo::github::repos() } else { engine.github().my_repos(&settings.github).await.map_err(github_error)? };
for r in &mut repos {
r.favorite = settings.favorite_repos.iter().any(|f| f.eq_ignore_ascii_case(&r.full_name));
}
@@ -2726,6 +2729,19 @@ pub async fn github_repos(engine: &Arc<Engine>) -> ApiResult<Vec<hub::Repo>> {
/// The GitHub CLI's accounts, and which one Muxen uses (read fresh, so a
/// permission granted a moment ago shows).
pub async fn github_accounts(engine: &Arc<Engine>) -> ApiResult<AccountsOut> {
+ if engine.is_demo() {
+ let login = crate::demo::github::LOGIN.to_string();
+ return Ok(AccountsOut {
+ using: Some(login.clone()),
+ token_source: "gh".into(),
+ machine_id: None,
+ accounts: vec![crate::github::Account { login, gh_active: true, ok: true, scopes: "repo, read:org, admin:org".into() }],
+ machines: Vec::new(),
+ scopes: Some(vec!["repo".into(), "read:org".into(), "admin:org".into()]),
+ orgs: vec!["acme".into()],
+ grant_command: None,
+ });
+ }
let settings = engine.settings().github;
let gh = engine.github();
gh.reload_login();
@@ -2841,6 +2857,11 @@ pub fn github_favorite(engine: &Arc<Engine>, req: FavoriteRequest) -> ApiResult<
pub async fn github_repo(engine: &Arc<Engine>, req: RepoRequest) -> ApiResult<RepoOut> {
let name = hub::repo_name(&req.repo).ok_or_else(|| ApiError::invalid(format!("\"{}\" isn't a GitHub repository; use owner/name.", req.repo)))?;
+ if engine.is_demo() {
+ let repo = crate::demo::github::repo_named(&name).ok_or_else(|| ApiError::new("not_found", format!("No repository called {name} in the demo.")))?;
+ let items = crate::demo::github::repo_items(&name);
+ return Ok(RepoOut { repo, issues: items.issues, pulls: items.pulls, runs: crate::demo::github::runs(&name), checkouts: Vec::new() });
+ }
let settings = engine.settings().github;
let gh = engine.github();
let (repo, items, runs) = futures::join!(gh.repo(&settings, &name), gh.repo_items(&settings, &name), gh.repo_runs(&settings, &name));
@@ -2854,6 +2875,9 @@ pub async fn github_repo(engine: &Arc<Engine>, req: RepoRequest) -> ApiResult<Re
pub async fn github_item(engine: &Arc<Engine>, req: ItemRequest) -> ApiResult<hub::Detail> {
let (repo, number) = hub::issue_ref(&req.reference)
.ok_or_else(|| ApiError::invalid(format!("\"{}\" isn't an issue or pull request; use its URL or owner/name#123.", req.reference)))?;
+ if engine.is_demo() {
+ return crate::demo::github::detail(&repo, number).ok_or_else(|| ApiError::new("not_found", format!("No {repo}#{number} in the demo.")));
+ }
let settings = engine.settings().github;
engine.github().detail(&settings, &repo, number).await.map_err(github_error)
}
diff --git a/src/demo.rs b/src/demo.rs
index 8e16379..77e21e6 100644
--- a/src/demo.rs
+++ b/src/demo.rs
@@ -778,3 +778,145 @@ pub fn demo_screen_text(name: &str) -> String {
_ => "$ ".into(),
}
}
+
+// ---------------------------------------------------------------------------
+// GitHub, simulated: the demo never reads the user's real account.
+
+pub mod github {
+ use chrono::{Duration as Ago, Utc};
+
+ use crate::github::hub::{Checks, Comment, Detail, Inbox, Item, Label, PullInfo, Repo, RepoItems, Review, Run, Viewer};
+
+ pub const LOGIN: &str = "jordan";
+
+ fn label(name: &str, color: &str) -> Label {
+ Label { name: name.into(), color: color.into() }
+ }
+
+ #[allow(clippy::too_many_arguments)]
+ fn item(repo: &str, number: u64, title: &str, pull: bool, author: &str, labels: Vec<Label>, comments: u32, minutes_ago: i64) -> Item {
+ let updated = Utc::now() - Ago::minutes(minutes_ago);
+ Item {
+ repo: repo.into(),
+ number,
+ title: title.into(),
+ pull_request: pull,
+ draft: false,
+ state: "open".into(),
+ author: author.into(),
+ assignees: if pull { Vec::new() } else { vec![LOGIN.into()] },
+ labels,
+ comments,
+ created_at: updated - Ago::hours(30),
+ updated_at: updated,
+ html_url: format!("https://github.com/{repo}/{}/{number}", if pull { "pull" } else { "issues" }),
+ }
+ }
+
+ fn repo(full_name: &str, description: &str, private: bool, language: &str, stars: u32, open_issues: u32, hours_ago: i64) -> Repo {
+ Repo {
+ full_name: full_name.into(),
+ description: Some(description.into()),
+ private,
+ fork: false,
+ archived: false,
+ default_branch: "main".into(),
+ language: Some(language.into()),
+ stars,
+ open_issues,
+ pushed_at: Some(Utc::now() - Ago::hours(hours_ago)),
+ html_url: format!("https://github.com/{full_name}"),
+ owner_is_org: full_name.starts_with("acme/"),
+ favorite: false,
+ }
+ }
+
+ pub fn viewer() -> Viewer {
+ Viewer { login: LOGIN.into(), name: Some("Jordan Lee".into()), html_url: format!("https://github.com/{LOGIN}") }
+ }
+
+ pub fn repos() -> Vec<Repo> {
+ vec![
+ repo("acme/api", "Billing, accounts and the public API", true, "Go", 48, 12, 1),
+ repo("acme/web", "The customer dashboard", true, "TypeScript", 23, 8, 2),
+ repo("acme/desktop", "The desktop app for macOS, Windows and Linux", false, "Rust", 1310, 41, 5),
+ repo("acme/ios", "The iPhone and iPad app", true, "Swift", 12, 6, 20),
+ repo("acme/infra", "Terraform and deploy scripts", true, "HCL", 4, 2, 48),
+ repo("jordan/dotfiles", "My shell, editor and terminal setup", false, "Shell", 31, 0, 96),
+ repo("jordan/blog", "jordanlee.dev", false, "TypeScript", 6, 1, 200),
+ ]
+ }
+
+ pub fn inbox() -> Inbox {
+ Inbox {
+ viewer: viewer(),
+ review_requests: vec![
+ item("acme/web", 91, "Checkout: show tax before the total", true, "mira", vec![label("frontend", "1d76db")], 3, 40),
+ item("acme/api", 418, "Retry failed webhooks with backoff", true, "devon", vec![label("backend", "5319e7")], 1, 130),
+ item("acme/desktop", 1302, "Remember each window's size per display", true, "lena", vec![label("enhancement", "a2eeef")], 6, 1500),
+ ],
+ assigned: vec![
+ item("acme/api", 412, "Coupon total is wrong after tax", false, "sam", vec![label("bug", "d73a4a"), label("billing", "fbca04")], 5, 190),
+ item("acme/web", 87, "Empty state for the orders page", false, "mira", vec![label("design", "c5def5")], 2, 1300),
+ item("acme/desktop", 1290, "Crash when a monitor is unplugged", false, "kai", vec![label("bug", "d73a4a"), label("crash", "b60205")], 9, 2900),
+ ],
+ authored: vec![item("acme/api", 415, "Cache the plan lookup per request", true, LOGIN, vec![label("performance", "0e8a16")], 0, 300)],
+ }
+ }
+
+ /// Everything in the inbox and a few more, by repository.
+ fn all() -> Vec<Item> {
+ let i = inbox();
+ let mut out: Vec<Item> = i.review_requests.into_iter().chain(i.assigned).chain(i.authored).collect();
+ out.push(item("acme/api", 409, "Rate limits per API key", false, "devon", vec![label("enhancement", "a2eeef")], 4, 4000));
+ out.push(item("acme/desktop", 1287, "Tray icon is blurry on Linux", false, "noor", vec![label("bug", "d73a4a"), label("linux", "fef2c0")], 2, 5000));
+ out
+ }
+
+ pub fn repo_items(full_name: &str) -> RepoItems {
+ let (pulls, issues) = all().into_iter().filter(|i| i.repo.eq_ignore_ascii_case(full_name)).partition(|i| i.pull_request);
+ RepoItems { issues, pulls }
+ }
+
+ pub fn repo_named(full_name: &str) -> Option<Repo> {
+ repos().into_iter().find(|r| r.full_name.eq_ignore_ascii_case(full_name))
+ }
+
+ pub fn runs(full_name: &str) -> Vec<Run> {
+ let run = |name: &str, conclusion: Option<&str>, title: &str, minutes: i64| Run {
+ name: name.into(),
+ status: if conclusion.is_some() { "completed".into() } else { "in_progress".into() },
+ conclusion: conclusion.map(str::to_string),
+ branch: "main".into(),
+ event: "push".into(),
+ title: title.into(),
+ created_at: Utc::now() - Ago::minutes(minutes),
+ html_url: format!("https://github.com/{full_name}/actions"),
+ };
+ vec![run("CI", None, "Cache the plan lookup per request", 4), run("CI", Some("success"), "Retry failed webhooks with backoff", 95), run("Deploy", Some("success"), "Release 2.14", 600)]
+ }
+
+ pub fn detail(full_name: &str, number: u64) -> Option<Detail> {
+ let item = all().into_iter().find(|i| i.repo.eq_ignore_ascii_case(full_name) && i.number == number)?;
+ let body = if item.pull_request {
+ format!("{}.\n\nTested on staging; screenshots below.", item.title)
+ } else {
+ "Steps:\n1. Add a 10% coupon to an order over $100\n2. Check out with tax on\n\nThe coupon comes off after tax instead of before, so the total is a few cents off.".to_string()
+ };
+ // As many comments as the list says it has.
+ let said = [("sam", "Seen on three orders today."), ("devon", "The discount runs after tax in pricing.go."), ("mira", "Same thing on the web checkout."), ("kai", "Support has two tickets about it."), ("sam", "Can we get this into Friday's release?")];
+ let comments = said.iter().cycle().take(item.comments as usize).enumerate().map(|(k, (author, body))| Comment { author: author.to_string(), body: body.to_string(), created_at: Utc::now() - Ago::hours(20 - 3 * k as i64) }).collect();
+ let pull = item.pull_request.then(|| PullInfo {
+ head: "feature".into(),
+ head_repo: Some(item.repo.clone()),
+ base: "main".into(),
+ mergeable: Some(true),
+ additions: 84,
+ deletions: 17,
+ changed_files: 6,
+ checks: Checks { total: 4, passed: 4, ..Default::default() },
+ reviews: vec![Review { author: "devon".into(), state: "APPROVED".into() }],
+ });
+ Some(Detail { item, body, comments, pull })
+ }
+}
diff --git a/src/ui/root.rs b/src/ui/root.rs
index f2f6a01..a6e28ac 100644
--- a/src/ui/root.rs
+++ b/src/ui/root.rs
@@ -836,6 +836,14 @@ impl Root {
page.read(cx).scroll.scroll_to_bottom();
}
}
+ // "forward:<machine>:<port>": that port of the machine open here (no browser).
+ "forward" => {
+ if let Some((machine, port)) = arg.rsplit_once(':')
+ && let Ok(port) = port.parse::<u16>()
+ {
+ self.open_port(machine, port, None, false, cx);
+ }
+ }
"theme" => {
let id = arg.to_string();
if let Some(p) = super::themes::find(&id) {