Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

tui: simpler Machines & devices; search lists what shows the query first (#1487)

lingrd00fb4bf048d6
diff --git a/tui/Cargo.lock b/tui/Cargo.lock
index 0e98917b5..571fca4de 100644
--- a/tui/Cargo.lock
+++ b/tui/Cargo.lock
@@ -661,7 +661,7 @@ dependencies = [
[[package]]
name = "harness-tui"
-version = "0.1.38"
+version = "0.1.39"
dependencies = [
"alacritty_terminal",
"base64",
diff --git a/tui/Cargo.toml b/tui/Cargo.toml
index 4867efdbf..e18974ef4 100644
--- a/tui/Cargo.toml
+++ b/tui/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "harness-tui"
-version = "0.1.38"
+version = "0.1.39"
edition = "2024"
[dependencies]
diff --git a/tui/src/devices.rs b/tui/src/devices.rs
index e9d4cd409..5b9f5f93d 100644
--- a/tui/src/devices.rs
+++ b/tui/src/devices.rs
@@ -35,12 +35,6 @@ use crate::theme::{self, fg};
// ── what the app shows (desktop wording, kept word for word) ──────────────────
-/// Where Harness is downloaded (link_another_machine_dialog.dart).
-pub const DOWNLOAD_URL: &str = "https://www.autonomous.ai/harness";
-/// A server's three steps, run on THAT machine over SSH: copied, never run here.
-pub const INSTALL: &str = "curl -fsSL https://cdn.autonomous.ai/harness/cli/install.sh | bash";
-pub const LOGIN: &str = "harness login";
-pub const START: &str = "harness start && harness remote-password set";
/// What sharing this computer gives (machine_sharing_form.dart's intro).
/// What a guest gets (docs/plans/2026-10-19-guest-machine-sharing-plan.md): Guest is the only level.
const SHARE_ACCESS: &str = "People you invite get their own private space here and use your Claude and ChatGPT plans. They can't see your files or harnesses.";
@@ -82,7 +76,7 @@ impl View {
match self {
View::Connect => "Search machines not linked yet",
View::Phone => "Search paired devices",
- View::Machines => "Search machines, links and steps",
+ View::Machines => "Search machines",
}
}
}
@@ -93,6 +87,10 @@ impl View {
#[derive(Clone, Debug, PartialEq)]
pub struct Linked { pub machine: String, pub fingerprint: String, pub at: String }
+/// Where Esc goes back to: a view, the level it was at, and the row.
+#[derive(Clone, Debug, PartialEq)]
+pub struct Back { pub view: View, pub sub: Option<String>, pub row: Option<String> }
+
/// A `link connect` under way, or just over: the stage it last reported, and how it ended.
pub struct Linking { pub machine: String, pub name: String, pub stage: String, pub result: Option<Result<String, String>> }
@@ -192,6 +190,9 @@ pub struct Devices {
unfit: std::cell::Cell<bool>,
/// A level inside a view: a machine's actions (`m:<id>`).
pub sub: Option<String>,
+ /// The view another one was opened from in this panel (Add a machine → Connect a computer):
+ /// Esc goes back to it, its level and its row.
+ pub back: Option<Back>,
/// The footer's line: what happened, or (true) what went wrong — until the next thing does.
pub footer: Option<(String, bool, Instant)>,
pub loading: Vec<&'static str>,
@@ -202,7 +203,7 @@ pub struct Devices {
impl Default for Devices {
fn default() -> Devices {
Devices {
- password: None, sharing: None, links: None, account: HashMap::new(), link: None, phone: Phone::default(), ask: None, prompt_actions: Default::default(), back_at: Default::default(), prompt_row: Default::default(), prompt_focus: Default::default(), unfit: Default::default(), sub: None, footer: None, loading: Vec::new(), runner: default_runner(),
+ password: None, sharing: None, links: None, account: HashMap::new(), link: None, phone: Phone::default(), ask: None, prompt_actions: Default::default(), back_at: Default::default(), prompt_row: Default::default(), prompt_focus: Default::default(), unfit: Default::default(), sub: None, back: None, footer: None, loading: Vec::new(), runner: default_runner(),
}
}
}
@@ -490,6 +491,7 @@ fn enter(app: &mut App, view: View) {
let d = &mut app.devices;
d.ask = None;
d.sub = None;
+ d.back = None;
d.footer = None;
if view == View::Phone {
let generation = d.phone.generation + 1;
@@ -961,7 +963,7 @@ pub fn paste(app: &mut App, text: &str) -> bool {
pub fn mouse(app: &mut App, mouse: MouseEvent) -> bool {
let Some(view) = view_of(app) else { return false };
if app.devices.ask.is_none() {
- let back = app.devices.back_at.get().filter(|(size, _)| *size == app.size && app.devices.sub.is_some());
+ let back = app.devices.back_at.get().filter(|(size, _)| *size == app.size && (app.devices.sub.is_some() || app.devices.back.is_some()));
let click = mouse.kind == MouseEventKind::Down(MouseButton::Left) && mouse.modifiers.is_empty();
if !(click && back.is_some_and(|(_, r)| r.contains(Position::new(mouse.column, mouse.row)))) { return false }
step_back(app, view);
@@ -1140,6 +1142,7 @@ fn step_back(app: &mut App, view: View) {
if let Some(p) = picker_mut(app) { p.clear_query(); p.select(&sub) }
return;
}
+ if go_back(app) { return }
app.devices.phone.open = false;
let Some(Modal::Picker { mut picker, .. }) = app.modal.take() else { return };
if !picker.from_commands { return }
@@ -1190,18 +1193,14 @@ pub fn choose(app: &mut App, view: View, picker: Picker, enter: bool) {
(_, "pw") => match rest.as_str() {
"set" => entry(app, Entry::NewPassword, "New remote password", "", true),
"clear" => confirm(app, "Prevent new links using this password? Existing links and sessions stay connected.", Act::ClearPassword),
- _ => load_password(app),
- },
- (_, "ln") if rest.is_empty() => { note(app, "Loading linked machines…"); load_links(app) }
- (_, "ln") => { let name = name_of(app, &rest); confirm(app, format!("Remove this computer’s saved link to {name}? A new connection will need that machine’s password."), Act::Unlink { machine: rest, name }) }
- (_, "add") => match rest.as_str() {
- "download" => copy(app, DOWNLOAD_URL),
- "connect" => switch(app, View::Connect),
- "install" => copy(app, INSTALL),
- "login" => copy(app, LOGIN),
- "start" => copy(app, START),
- _ => copy(app, &format!("{INSTALL}\n{LOGIN}\n{START}")),
+ // The row itself: a first password at once; Change and Clear once there is one.
+ _ => match password_set(app) {
+ Some(true) => sub(app, "pw:".into()),
+ Some(false) => entry(app, Entry::NewPassword, "New remote password", "", true),
+ None => load_password(app),
+ },
},
+ (_, "add") => switch(app, View::Connect),
(_, "ph") => match rest.as_str() {
"arm" => run_act(app, Act::ArmPhone),
"new" => { app.devices.phone.code = new_code(); app.devices.phone.message = None; note(app, "A new code — the old one no longer pairs") }
@@ -1222,8 +1221,28 @@ fn sub(app: &mut App, level: String) {
if let Some(p) = picker_mut(app) { p.clear_query(); p.scroll = 0; p.vset(0, 1) }
}
-/// Over to another view in the same panel (Esc still goes back where the first one came from).
+/// Over to another view in the same panel: Esc comes back to this one, at the row it was on. Asked
+/// for the view it came from (Connect's Set up another computer, after Add a machine), it goes back
+/// there rather than opening a third.
fn switch(app: &mut App, view: View) {
+ if app.devices.back.as_ref().is_some_and(|b| b.view == view) { go_back(app); return }
+ let from = view_of(app).map(|v| Back { view: v, sub: app.devices.sub.clone(), row: picker_mut(app).and_then(|p| p.current_id()) });
+ show(app, view);
+ app.devices.back = from;
+}
+
+/// Back to the view this one was opened from, if it was: false when there is none.
+fn go_back(app: &mut App) -> bool {
+ let Some(back) = app.devices.back.take() else { return false };
+ show(app, back.view);
+ app.devices.sub = back.sub;
+ again(app);
+ if let (Some(p), Some(row)) = (picker_mut(app), back.row) { p.select(&row) }
+ true
+}
+
+/// [view] in this panel, from its first row.
+fn show(app: &mut App, view: View) {
enter(app, view);
if let Some(Modal::Picker { kind, picker }) = &mut app.modal {
*kind = PickerKind::Devices(view);
@@ -1236,10 +1255,6 @@ fn switch(app: &mut App, view: View) {
opened(app, view);
}
-fn copy(app: &mut App, text: &str) {
- let shown = text.lines().next().unwrap_or("").to_string();
- ask(app, Req::Copy(text.to_string()), None, move |app, _| note(app, format!("Copied: {shown}")));
-}
fn machine_action(app: &mut App, rest: &str) {
let Some((verb, machine)) = rest.split_once(':') else { return };
@@ -1247,6 +1262,7 @@ fn machine_action(app: &mut App, rest: &str) {
match verb {
"rename" => entry(app, Entry::Rename { machine, name: name.clone() }, "Machine name", &name, false),
"remove" => confirm(app, format!("Delete {name} from your account?"), Act::Remove { machine, name }),
+ "unlink" => confirm(app, format!("Remove this computer’s saved link to {name}? A new connection will need that machine’s password."), Act::Unlink { machine, name }),
"connect" => { switch(app, View::Connect); if let Some(p) = picker_mut(app) { p.select(&format!("m:{machine}")) } start_link(app, machine, name) }
"open" => {
app.devices.sub = None;
@@ -1380,6 +1396,7 @@ pub fn fill(app: &App, view: View, picker: &mut Picker) {
View::Connect => connect_rows(app),
View::Machines => match app.devices.sub.as_deref() {
Some("share:") => share_rows(app),
+ Some("pw:") => password_rows(app),
Some(sub) => match sub.strip_prefix("m:") { Some(id) => action_rows(app, id), None => machines_rows(app) },
None => machines_rows(app),
},
@@ -1402,16 +1419,19 @@ fn connect_rows(app: &App) -> Vec<Row> {
let linking = app.devices.link.as_ref().is_some_and(|l| l.machine == m.id && l.result.is_none());
// (One just linked stays in view, how it went beside it.)
if app.devices.link.as_ref().is_some_and(|l| l.machine == m.id && matches!(l.result, Some(Ok(_)))) {
- done.push(Row::new(format!("m:{}", m.id), m.name.clone()).group("Linked just now").extra(m.id.clone()).lead(dot("✓", theme::ONLINE)).detail(vec![span("linked", fg(theme::ONLINE))]).right("linked"));
+ done.push(Row::new(format!("m:{}", m.id), m.name.clone()).group("Linked just now").extra(m.id.clone()).lead(dot("✓", theme::ONLINE)).right("linked"));
} else if linking || (m.reach == Reach::NeedsLink && m.online()) {
- ready.push(Row::new(format!("m:{}", m.id), m.name.clone()).group("Not linked yet").extra(m.id.clone()).lead(dot(glyph, color)).detail(vec![span(word, fg(color))]).right("enter links it"));
+ // (Its group says what it is; the preview, what Enter does.)
+ ready.push(Row::new(format!("m:{}", m.id), m.name.clone()).group("Not linked yet").extra(format!("{} {word}", m.id)).lead(dot(glyph, color)).right(if linking { "connecting…" } else { "" }));
} else if !m.online() {
- let mut r = Row::new(format!("m:{}", m.id), m.name.clone()).group("Offline").extra(m.id.clone()).lead(dot(glyph, color)).detail(vec![span(format!("Open Harness on {} to bring it online.", m.name), fg(theme::MUTED))]).right("offline");
+ let mut r = Row::new(format!("m:{}", m.id), m.name.clone()).group("Offline").extra(m.id.clone()).lead(dot(glyph, color)).right("offline");
r.disabled = true;
away.push(r);
}
}
if ready.is_empty() { ready.push(info("none", if app.daemon_down { "Harness is not running on this computer" } else { "No computers ready to connect" }, "Not linked yet")) }
+ // (An offline row is never chosen, so it has no preview: the way to bring one back is said once, under them.)
+ if !away.is_empty() { away.push(info("offline-how", "Open Harness there to bring it online.", "Offline")) }
ready.extend(done);
ready.extend(away);
ready.push(setup());
@@ -1419,8 +1439,9 @@ fn connect_rows(app: &App) -> Vec<Row> {
}
fn account_row(app: &App) -> Row {
- let detail = if app.account.status == crate::account::Status::SignedOut { "Connect computers, sync your workspace and use your phone" } else { "Your Harness account and connected computers" };
- Row::new("account", crate::account::label(app)).group("Account").detail(vec![span(detail, fg(theme::MUTED))])
+ // Who is signed in, by name; what the account is for is in the preview.
+ let label = match account_email(app) { Some(e) if app.account.status != crate::account::Status::SignedOut => e, _ => crate::account::label(app).to_string() };
+ Row::new("account", label).group("Account").extra("account sign in")
}
fn machines_rows(app: &App) -> Vec<Row> {
@@ -1429,7 +1450,7 @@ fn machines_rows(app: &App) -> Vec<Row> {
let here = app.fleet.local_machine_name();
let here = here.as_str();
let password = app.devices.password.as_ref();
- let set = password.and_then(|p| p.as_ref().ok()).and_then(|v| v.get("hasPassword")).and_then(Value::as_bool);
+ let set = password_set(app);
let state = match password {
_ if is_loading(app, "password") && password.is_none() => "reading…".to_string(),
None => "…".into(),
@@ -1437,10 +1458,8 @@ fn machines_rows(app: &App) -> Vec<Row> {
Some(Ok(v)) => if set == Some(true) { v.get("setAt").and_then(Value::as_u64).map(|t| format!("set {}", crate::fleet::ago(t))).map(|s| if s == "set " { "set".into() } else { s }).unwrap_or_else(|| "set".into()) } else { "not set".into() },
};
let color = match set { Some(true) => theme::ONLINE, Some(false) => theme::MUTED, None => theme::WARN };
- rows.push(Row::new("pw:set", if set == Some(true) { "Change password…" } else { "Set password…" }).group(here).extra("remote password")
- .lead(dot(if set == Some(true) { "✓" } else { "·" }, color)).detail(vec![span("the remote password another machine links here with", fg(theme::MUTED))]).right(state));
- if set == Some(true) { rows.push(Row::new("pw:clear", "Clear password…").group(here).extra("remote password").lead(dot(" ", theme::MUTED)).detail(vec![span("no new links by password", fg(theme::MUTED))])) }
- if matches!(password, Some(Err(_))) { rows.push(Row::new("pw:status", "Retry").group(here).extra("password status").lead(dot("↻", theme::MUTED)).detail(vec![span("Password status is unavailable.", fg(theme::WARN))])) }
+ // One row: Enter sets a first password, opens Change and Clear once there is one, or reads it again.
+ rows.push(Row::new("pw:", "Remote password").group(here).extra("remote password set change clear").lead(dot(if set == Some(true) { "✓" } else { "·" }, color)).right(state));
// Sharing this computer with other accounts: off until its owner shares it.
if !app.devices.phone.signed_out && app.account.status != crate::account::Status::SignedOut {
let state = match (&app.devices.sharing, sharing_now(app)) {
@@ -1454,82 +1473,94 @@ fn machines_rows(app: &App) -> Vec<Row> {
_ if is_loading(app, "sharing") => "reading…".into(),
_ => "…".into(),
};
- rows.push(Row::new("share:", "Share this computer…").group(here).extra("share sharing people team domain").lead(dot("⇆", theme::TEAL))
- .detail(vec![span("with people you choose", fg(theme::MUTED))]).right(state));
+ rows.push(Row::new("share:", "Share this computer").group(here).extra("share sharing people team domain").lead(dot("⇆", theme::TEAL)).right(state));
}
+ // A row is its name and one word or count at the right; the rest is in the preview.
let yours = "Your machines";
for m in app.fleet.machines.iter().filter(|m| !m.shared && !app.fleet.shares.contains_key(&m.id)) {
if crate::local::is_local(&m.id) { continue }
- let (glyph, color, word) = reach(app, m);
- let rtt = app.rtt.get(&m.id).filter(|_| m.usable()).map(|d| format!("{}ms ", d.as_millis())).unwrap_or_default();
- rows.push(Row::new(format!("m:{}", m.id), m.name.clone()).group(yours).extra(format!("{} {word}", m.id)).lead(dot(glyph, color)).detail(vec![span(word, fg(color))]).right(format!("{rtt}{}", counts(app, &m.id))));
+ let (_, _, word) = reach(app, m);
+ rows.push(machine_row(app, m, yours).extra(format!("{} {word}", m.id)));
}
if app.fleet.machines.iter().all(|m| crate::local::is_local(&m.id)) { rows.push(info("m-none", if app.daemon_down { "Harness is not running on this computer" } else { "Loading machines…" }, yours)) }
+ // Another computer, last of yours: its steps are in the preview; Enter lists the ones ready to link.
+ rows.push(Row::new("add:", "Add a machine").group(yours).extra("connect link new computer password").lead(dot("+", theme::TEAL)));
+
// Other accounts' machines shared with this one: used as its own.
let with_you = "Shared with you";
for m in app.fleet.machines.iter() {
let Some(share) = app.fleet.shares.get(&m.id) else { continue };
- let (glyph, color, word) = reach(app, m);
- let rtt = app.rtt.get(&m.id).filter(|_| m.usable()).map(|d| format!("{}ms ", d.as_millis())).unwrap_or_default();
- rows.push(Row::new(format!("m:{}", m.id), m.name.clone()).group(with_you).extra(format!("{} {} {}", m.id, share.owner, share.email)).lead(dot(glyph, color))
- .detail(vec![span(format!("shared by {} · ", share.owner), fg(theme::MUTED)), span(word, fg(color))]).right(format!("{rtt}{}", counts(app, &m.id))));
+ let (_, _, word) = reach(app, m);
+ rows.push(machine_row(app, m, with_you).extra(format!("{} {} {} {word}", m.id, share.owner, share.email)));
}
// Shared with this account's domain: Enter adds one.
let team = "Shared with your team";
for (id, name, share) in &app.fleet.to_add {
- rows.push(Row::new(format!("addshared:{id}"), format!("Add {name}")).group(team).extra(format!("{id} {} {}", share.owner, share.email)).lead(dot("+", theme::TEAL))
- .detail(vec![span(format!("shared by {} with everyone at your company", share.owner), fg(theme::MUTED))]).right("add"));
- }
-
- let linked = "Linked from here";
- match &app.devices.links {
- None => rows.push(info("ln-loading", "Loading linked machines…", linked)),
- Some(Err(e)) => rows.push(info("ln-error", e.clone(), linked)),
- Some(Ok(list)) if list.is_empty() => rows.push(info("ln-none", "No machines linked yet.", linked)),
- Some(Ok(list)) => for l in list {
- let name = name_of(app, &l.machine);
- rows.push(Row::new(format!("ln:{}", l.machine), name).group(linked).extra(format!("{} {}", l.machine, l.fingerprint)).lead(dot("⇄", theme::TEAL)).detail(vec![span(l.fingerprint.clone(), fg(theme::MUTED))]).right(format!("linked {}", l.at)));
- },
+ rows.push(Row::new(format!("addshared:{id}"), format!("Add {name}")).group(team).extra(format!("{id} {} {}", share.owner, share.email)).lead(dot("+", theme::TEAL)));
}
- rows.push(Row::new("ln:", "Refresh links").group(linked).lead(dot("↻", theme::MUTED)).detail(vec![span("Machines this computer can connect to.", fg(theme::MUTED))]));
-
- // The app's two steps, then a server's three — each Enter copies what it names.
- let add = "Add a machine";
- let email = app.devices.phone.email.clone();
- let sign = email.as_ref().map(|e| format!("Sign in as {e}.")).unwrap_or_else(|| "Sign in with the same account.".into());
- rows.push(Row::new("add:download", "1. Open Harness on your other computer.").group(add).extra("download").lead(dot("⧉", theme::TEAL)).detail(vec![span(sign, fg(theme::MUTED))]).right("copy"));
- rows.push(Row::new("add:connect", "2. Open Machines and choose Set password.").group(add).extra("password connect").lead(dot("→", theme::TEAL)).detail(vec![span("Back here, click Connect and enter that password.", fg(theme::MUTED))]));
- let server = "Set up a server";
- rows.push(Row::new("add:install", "1. Install the CLI (skip if installed)").group(server).extra(INSTALL).lead(dot("⧉", theme::TEAL)).detail(vec![span(INSTALL, fg(theme::MUTED))]).right("copy"));
- rows.push(Row::new("add:login", format!("2. Sign in as {}", email.as_deref().unwrap_or("your account"))).group(server).extra(LOGIN).lead(dot("⧉", theme::TEAL)).detail(vec![span(LOGIN, fg(theme::MUTED))]).right("copy"));
- rows.push(Row::new("add:start", "3. Start Harness and set a remote password").group(server).extra(START).lead(dot("⧉", theme::TEAL)).detail(vec![span(START, fg(theme::MUTED))]).right("copy"));
- rows.push(Row::new("add:all", "Copy commands").group(server).extra("all three").lead(dot("⧉", theme::TEAL)).detail(vec![span("Run these on your server over SSH:", fg(theme::MUTED))]).right("copy all"));
rows
}
+/// A machine's row: its mark and name, and at the right its state — in a narrow list only why it
+/// can't be used (its ✓ says the rest; its harnesses are in the preview).
+fn machine_row(app: &App, m: &crate::fleet::Machine, group: &str) -> Row {
+ let (glyph, color, _) = reach(app, m);
+ let state = machine_state(app, m);
+ let narrow = if m.usable() { String::new() } else { state.clone() };
+ Row::new(format!("m:{}", m.id), m.name.clone()).group(group).lead(dot(glyph, color)).right(state).right_narrow(narrow)
+}
+
+/// A machine's right column: how many harnesses it has, or why it can't be used.
+fn machine_state(app: &App, m: &crate::fleet::Machine) -> String {
+ if !m.usable() {
+ let (_, _, word) = reach(app, m);
+ return match word.as_str() { "online · not linked" => "not linked".into(), w @ ("offline" | "online" | "connecting…") => w.into(), _ => "error".into() };
+ }
+ let n = app.fleet.agents.values().filter(|a| a.machine_id == m.id && a.engine != "terminal").count();
+ match n { 0 => "no harnesses".into(), 1 => "1 harness".into(), n => format!("{n} harnesses") }
+}
+
fn action_rows(app: &App, id: &str) -> Vec<Row> {
let Some(m) = app.fleet.machine(id) else { return vec![info("gone", "That machine is gone", "")] };
let group = m.name.clone();
let mut rows = Vec::new();
- let act = |verb: &str, label: &str, hint: &str, glyph: &str| Row::new(format!("act:{verb}:{id}"), label).group(group.clone()).lead(dot(glyph, theme::TEAL)).detail(vec![span(hint.to_string(), fg(theme::MUTED))]);
- if m.usable() { rows.push(act("open", "Open its harnesses", "the harnesses list, on this machine", "→")) }
+ let act = |verb: &str, label: &str, glyph: &str| Row::new(format!("act:{verb}:{id}"), label).group(group.clone()).lead(dot(glyph, theme::TEAL));
+ if m.usable() { rows.push(act("open", "Open its harnesses", "→")) }
// (A machine shared with this account links by its key once both daemons read the sharing: no password.)
- if m.reach == Reach::NeedsLink && m.online() && !app.fleet.shares.contains_key(id) { rows.push(act("connect", "Connect…", "its remote password, then link", "⇄")) }
+ if m.reach == Reach::NeedsLink && m.online() && !app.fleet.shares.contains_key(id) { rows.push(act("connect", "Connect…", "⇄")) }
+ if link_of(app, id).is_some() { rows.push(act("unlink", "Unlink…", "⇄")) }
match app.fleet.shares.get(id) {
// Another account's: its owner renames, removes and shares it.
Some(share) => {
rows.push(info("shared-by", format!("Shared with you by {}", owner_of(share)), &group));
}
None => {
- rows.push(act("rename", "Rename…", "the name every device on the account shows", "✎"));
- if !m.local { rows.push(act("remove", "Remove from account…", "delete it from your account", "✗")) }
+ rows.push(act("rename", "Rename…", "✎"));
+ if !m.local { rows.push(act("remove", "Remove from account…", "✗")) }
}
}
rows
}
+/// This computer's saved link to [machine], if it has one.
+fn link_of<'a>(app: &'a App, machine: &str) -> Option<&'a Linked> {
+ app.devices.links.as_ref()?.as_ref().ok()?.iter().find(|l| l.machine == machine)
+}
+
+/// Whether this computer has a remote password, once that is known.
+fn password_set(app: &App) -> Option<bool> {
+ app.devices.password.as_ref()?.as_ref().ok()?.get("hasPassword").and_then(Value::as_bool)
+}
+
+/// The remote password's level: change or clear the one there is, or set a first one.
+fn password_rows(app: &App) -> Vec<Row> {
+ let group = "Remote password";
+ if password_set(app) != Some(true) { return vec![Row::new("pw:set", "Set password…").group(group).lead(dot("✎", theme::TEAL))] }
+ vec![Row::new("pw:set", "Change password…").group(group).lead(dot("✎", theme::TEAL)), Row::new("pw:clear", "Clear password…").group(group).lead(dot("✗", theme::TEAL))]
+}
+
/// This computer's sharing: everyone at its domain, the addresses, and who uses it now.
fn share_rows(app: &App) -> Vec<Row> {
let here = format!("Share {}", app.fleet.local_machine_name());
@@ -1547,16 +1578,17 @@ fn share_rows(app: &App) -> Vec<Row> {
// Shared already, but guests start nothing until guest access is on (again, after an update).
let access = guest_access(app);
if (!emails.is_empty() || same_domain) && access.as_deref().is_some_and(|a| a != "ready") {
- rows.push(Row::new("shr:guests-on", "Turn on sharing…").group(here.clone()).extra("sharing guest access admin").lead(dot("!", theme::WARN))
- .detail(vec![span(if access.as_deref() == Some("outdated") { "people you added can't use it since the update" } else { "people you added can't use it yet" }, fg(theme::MUTED))]));
+ rows.push(Row::new("shr:guests-on", "Turn on sharing…").group(here.clone()).extra("sharing guest access admin").lead(dot("!", theme::WARN)).right("off"));
}
if let Some(domain) = &domain {
rows.push(Row::new("shr:domain", format!("Everyone at @{domain}")).group(here.clone()).extra("domain team company").lead(dot(if same_domain { "✓" } else { "·" }, if same_domain { theme::ONLINE } else { theme::MUTED }))
- .detail(vec![span("no invite needed", fg(theme::MUTED))]).right(if same_domain { "on" } else { "off" }));
+ .right(if same_domain { "on" } else { "off" }));
}
- rows.push(Row::new("shr:add", "Add an email…").group(here.clone()).extra("add email person").lead(dot("+", theme::TEAL)).detail(vec![span("they see it in their Machines", fg(theme::MUTED))]));
+ rows.push(Row::new("shr:add", "Add an email…").group(here.clone()).extra("add email person").lead(dot("+", theme::TEAL)));
+ let members = sharing_members(app);
for email in &emails {
- rows.push(Row::new(format!("shr:rm:{email}"), email.clone()).group(here.clone()).extra("remove").lead(dot("·", theme::MUTED)).right("remove"));
+ let joined = members.iter().any(|(e, _)| e == email);
+ rows.push(Row::new(format!("shr:rm:{email}"), email.clone()).group(here.clone()).extra("remove").lead(dot("·", theme::MUTED)).right(if joined { "joined" } else { "invited" }));
}
let using = using_by_email(app);
if !using.is_empty() { rows.push(info("share-using", format!("Using it now: {}", using.join(", ")), &here)) }
@@ -1618,7 +1650,12 @@ fn phone_rows(app: &App) -> Vec<Row> {
fn dim(text: impl Into<String>) -> Span<'static> { Span::styled(text.into(), Style::default().add_modifier(Modifier::DIM)) }
fn bold(text: impl Into<String>) -> Span<'static> { Span::styled(text.into(), Style::default().add_modifier(Modifier::BOLD)) }
-fn kv(k: &str, v: impl Into<String>) -> Line<'static> { Line::from(vec![dim(format!("{k:<10}")), Span::raw(v.into())]) }
+/// How another computer uses this one's remote password, in the rows' own names.
+const LINK_HERE: &str = "On the other computer: Add a machine → choose this computer → enter this password.";
+
+/// A preview's label column: wide enough for its longest label (`fingerprint`) and a space.
+const KEY_W: usize = 12;
+fn kv(k: &str, v: impl Into<String>) -> Line<'static> { Line::from(vec![dim(format!("{k:<KEY_W$}")), Span::raw(v.into())]) }
fn enter_does(text: impl Into<String>) -> Vec<Line<'static>> { vec![Line::raw(""), Line::from(vec![Span::styled("enter ", fg(theme::accent())), dim(text)])] }
/// The right side for the row under the cursor: what it is, and what Enter does.
@@ -1626,17 +1663,21 @@ pub fn preview(app: &App, view: View, id: &str) -> Vec<Line<'static>> {
let (what, rest) = id.split_once(':').unwrap_or((id, ""));
match what {
_ if app.daemon_down && matches!(id, "none" | "m-none") => vec![Line::raw("Harness is not running on this computer."), Line::raw(""), dim("Start it with `harness start`, then come back.").into()],
- "none" => vec![Line::raw("No computers are ready to connect."), Line::raw(""), dim("Open Harness on the other computer and sign in to the same account.").into()],
+ "none" => { let mut out = vec![Line::raw("No computers are ready to connect."), Line::raw("")]; out.extend(add_steps(app)); out }
"here" if rest == "login" => vec![Line::raw("Sign in to see your other computers."), Line::raw(""),
dim("Use the same Harness account on both. Your local agents work without signing in.").into(),
Line::raw(""), dim("After signing in, open Connect a computer again.").into(),
Line::raw(""), dim("Enter opens the normal Harness sign-in flow in a local terminal.").into()],
- "here" => vec![Line::raw("Set up Harness on your other computer."), Line::raw(""),
- dim("The setup guide covers sign-in, the remote password and servers.").into(),
- Line::raw(""), dim("Enter opens Machines & devices.").into()],
- "account" => match &app.account.status {
- crate::account::Status::SignedIn { email, .. } => {
- let mut out = vec![Line::raw(email.as_ref().map_or("Signed in.".into(), |e| format!("Signed in as {e}."))), Line::raw(""),
+ "here" => {
+ let mut out = vec![bold("Set up another computer").into(), Line::raw("")];
+ out.extend(add_steps(app));
+ out.extend(enter_does("opens Machines & devices"));
+ out
+ }
+ // (Signed in as the row says: by the account's status, or by the daemon's email while that loads.)
+ "account" => match (&app.account.status, account_email(app)) {
+ (crate::account::Status::SignedIn { .. }, email) | (crate::account::Status::Unknown, email @ Some(_)) => {
+ let mut out = vec![Line::raw(email.map_or("Signed in.".into(), |e| format!("Signed in as {e}."))), Line::raw(""),
dim("Your computers, workspace and phone use this account.").into()];
out.extend(enter_does("opens Account"));
out
@@ -1646,15 +1687,10 @@ pub fn preview(app: &App, view: View, id: &str) -> Vec<Line<'static>> {
"m" => {
let mut out = machine_lines(app, rest);
if view == View::Connect {
- out.push(Line::raw(""));
- out.push(dim("Enter the remote password set on this machine.").into());
out.extend(stage_lines(app, rest));
if app.devices.link.as_ref().is_none_or(|l| l.machine != rest) { out.extend(enter_does("type its remote password, then link")) }
} else {
- out.extend(enter_does(match app.fleet.shares.get(rest) {
- Some(_) => "its actions — open",
- None => "its actions — open, connect, rename, remove from account",
- }));
+ out.extend(enter_does("opens its actions"));
}
out
}
@@ -1666,6 +1702,7 @@ pub fn preview(app: &App, view: View, id: &str) -> Vec<Line<'static>> {
"connect" => "asks for its remote password, then links it",
"rename" => "asks for its new name, then y/n",
"remove" => "asks y/n, then deletes it from your account",
+ "unlink" => "asks y/n, then removes this computer's saved link — a new connection will need its password",
_ => "",
}));
out
@@ -1692,35 +1729,24 @@ pub fn preview(app: &App, view: View, id: &str) -> Vec<Line<'static>> {
if let Some(f) = v.get("fingerprint").and_then(Value::as_str) { out.push(kv("fingerprint", f)) }
if let Some(t) = v.get("setAt").and_then(Value::as_u64) { out.push(kv("set", format!("{} ago", crate::fleet::ago(t)))) }
out.push(Line::raw(""));
- out.push(dim("On the other machine: Link machine → select this computer → enter its password.").into());
+ out.push(dim(LINK_HERE).into());
}
- Some(Ok(_)) => { out.push(bold("No remote password set.").into()); out.push(Line::raw("")); out.push(dim("Use this password on the other machine to link to this computer.").into()) }
+ Some(Ok(_)) => { out.push(bold("No remote password set.").into()); out.push(Line::raw("")); out.push(dim("Set one so another computer can link to this one.").into()); out.push(dim(LINK_HERE).into()) }
Some(Err(e)) => { out.push(Line::from(vec![Span::styled("Password status is unavailable.", fg(theme::WARN))])); if e != "Password status is unavailable." { out.push(dim(e.clone()).into()) } }
None => out.push(dim("Reading password status…").into()),
}
- out.extend(enter_does(match rest { "set" => "asks for the new password twice, then y/n", "clear" => "asks y/n, then clears it — existing links stay", _ => "reads its status again" }));
- out
- }
- "ln" if rest.is_empty() => { let mut out = vec![Line::from(dim("Machines this computer can connect to."))]; out.extend(enter_does("reads `harness link list` again")); out }
- "ln" => {
- let Some(Ok(list)) = &app.devices.links else { return vec![] };
- let Some(l) = list.iter().find(|l| l.machine == rest) else { return vec![] };
- let mut out = vec![bold(name_of(app, rest)).into(), Line::raw(""), kv("machine", l.machine.clone()), kv("fingerprint", l.fingerprint.clone()), kv("linked", l.at.clone())];
- out.extend(enter_does("asks y/n, then unlinks it — a new connection will need its password"));
+ out.extend(enter_does(match (rest, password_set(app)) {
+ ("set", _) | ("", Some(false)) => "asks for the new password twice, then y/n",
+ ("clear", _) => "asks y/n, then clears it — existing links stay",
+ ("", Some(true)) => "change or clear it",
+ _ => "reads its status again",
+ }));
out
}
"add" => {
- let (text, copies): (&str, String) = match rest {
- "download" => ("Download Harness on your other computer and sign in with the same account.", DOWNLOAD_URL.into()),
- "connect" => ("On the other computer: Machines → Set password. Back here, Connect a computer and enter that password.", String::new()),
- "install" => ("Run these on your server over SSH:", INSTALL.into()),
- "login" => ("Open the printed sign-in link in a browser on any device.", LOGIN.into()),
- "start" => ("Start Harness and set a remote password.", START.into()),
- _ => ("Run these on your server over SSH:", format!("{INSTALL}\n{LOGIN}\n{START}")),
- };
- let mut out = vec![Line::raw(text.to_string()), Line::raw("")];
- for l in copies.lines() { out.push(Line::from(vec![Span::styled(l.to_string(), fg(theme::TEAL))])) }
- out.extend(enter_does(if copies.is_empty() { "opens Connect a computer".to_string() } else { "copies it — to the clipboard of the computer you sit at".to_string() }));
+ let mut out = vec![bold("Add a machine").into(), Line::raw("")];
+ out.extend(add_steps(app));
+ out.extend(enter_does("lists the computers ready to link"));
out
}
"ph" => {
@@ -1736,6 +1762,21 @@ pub fn preview(app: &App, view: View, id: &str) -> Vec<Line<'static>> {
}
}
+/// The signed-in account's email: as the account read it, else as the daemon last said (`/api/auth/me`).
+fn account_email(app: &App) -> Option<String> {
+ match &app.account.status { crate::account::Status::SignedIn { email: Some(e), .. } => Some(e.clone()), _ => app.devices.phone.email.clone() }
+}
+
+/// How another computer joins: the same account, a remote password there, that password here.
+fn add_steps(app: &App) -> Vec<Line<'static>> {
+ let account = account_email(app).unwrap_or_else(|| "the same account".into());
+ vec![
+ Line::raw(format!("1. On the other computer, open Harness and sign in as {account}.")),
+ Line::raw("2. There, set a remote password in Machines & devices."),
+ Line::raw("3. Back here, choose that computer and enter the password."),
+ ]
+}
+
/// Who this computer is shared with now, under its Share row.
fn sharing_lines(app: &App) -> Vec<Line<'static>> {
let Some((emails, same_domain, domain)) = sharing_now(app) else {
@@ -1781,7 +1822,8 @@ fn share_preview(app: &App, rest: &str) -> Vec<Line<'static>> {
out
}
("guests-on", _) => {
- let mut out = vec![bold("Turn on sharing").into(), Line::raw(""),
+ let why = if guest_access(app).as_deref() == Some("outdated") { "People you added can't use it since the update." } else { "People you added can't use it yet." };
+ let mut out = vec![bold("Turn on sharing").into(), Line::raw(""), Line::styled(why, fg(theme::WARN)), Line::raw(""),
Line::raw("Each person you share with gets their own account on this computer, so they can't see your files. You enter your password once to set this up.")];
out.extend(enter_does("shows this computer's admin prompt"));
out
@@ -1808,9 +1850,11 @@ fn machine_lines(app: &App, id: &str) -> Vec<Line<'static>> {
let Some(m) = app.fleet.machine(id) else { return vec![dim("(gone)").into()] };
let (glyph, color, word) = reach(app, m);
let mut out = vec![Line::from(vec![bold(m.name.clone()), dim(if m.local { " this computer" } else { "" })]), Line::raw("")];
- out.push(Line::from(vec![dim(format!("{:<10}", "status")), Span::styled(format!("{glyph} {word}"), fg(color))]));
+ out.push(Line::from(vec![dim(format!("{:<KEY_W$}", "status")), Span::styled(format!("{glyph} {word}"), fg(color))]));
if let Some(share) = app.fleet.shares.get(id) { out.push(kv("shared by", owner_of(share))) }
if let Some(rtt) = app.rtt.get(id).filter(|_| m.usable()) { out.push(kv("rtt", format!("{}ms", rtt.as_millis()))) }
+ // (Saved, not live: a machine can still need linking again after it.)
+ if let Some(l) = link_of(app, id) { out.push(kv("saved link", l.at.clone())) }
let row = app.devices.account.get(id);
let seen = row.and_then(|r| ["lastSeenAt", "lastSeen", "lastActiveAt", "updatedAt"].iter().find_map(|k| r.get(*k)));
match seen {
@@ -1856,15 +1900,23 @@ fn stage_lines(app: &App, machine: &str) -> Vec<Line<'static>> {
/// A title, where you are inside it, and the way out.
fn head(buf: &mut Buffer, app: &App, title: &str, x: u16, y: u16, right: u16, c: &Chrome) {
- let mut at = x + settings::put(buf, x, y, right.saturating_sub(x), title, c.base.add_modifier(Modifier::BOLD));
let level = match app.devices.sub.as_deref() {
Some("share:") => Some(format!("Share {}", app.fleet.local_machine_name())),
+ Some("pw:") => Some("Remote password".to_string()),
sub => sub.and_then(|s| s.strip_prefix("m:")).map(|id| name_of(app, id)),
};
- app.devices.back_at.set(level.as_ref().map(|_| (app.size, Rect::new(x, y, at - x, 1))));
- if let Some(level) = level {
- at += settings::put(buf, at, y, right.saturating_sub(at), " › ", c.muted);
- settings::put(buf, at, y, right.saturating_sub(at), &level, c.accent);
+ // The way here, the view it came from first: `Machines & devices › Connect a computer`.
+ let path: Vec<String> = app.devices.back.as_ref().map(|b| b.view.title().to_string()).into_iter().chain(std::iter::once(title.to_string())).chain(level).collect();
+ // (It stops a column short of `esc`, however long.)
+ let end = right.saturating_sub(4);
+ let mut at = x;
+ for (i, part) in path.iter().enumerate() {
+ if i > 0 { at += settings::put(buf, at, y, end.saturating_sub(at), " › ", c.muted) }
+ let style = if i == 0 { c.base.add_modifier(Modifier::BOLD) } else if i + 1 == path.len() { c.accent } else { c.base };
+ let w = settings::put(buf, at, y, end.saturating_sub(at), part, style);
+ // The first part is the way back, as Esc is.
+ if i == 0 { app.devices.back_at.set((path.len() > 1).then(|| (app.size, Rect::new(x, y, w, 1)))) }
+ at += w;
}
settings::put(buf, right.saturating_sub(3), y, 3, "esc", c.muted);
}
@@ -1995,7 +2047,7 @@ fn footer(buf: &mut Buffer, app: &App, picker: &Picker, x: u16, y: u16, w: u16,
if app.devices.ask.is_some() { return }
let (line, style) = match app.devices.footer.as_ref().filter(|(_, err, at)| *err || at.elapsed() < Duration::from_secs(6)) {
Some((t, err, _)) => (t.clone(), if *err { c.danger } else { c.accent }),
- None => (format!("↑↓ move enter choose type to search esc {}", if app.devices.sub.is_some() || picker.from_commands { "back" } else { "close" }), c.muted),
+ None => (format!("↑↓ move enter choose type to search esc {}", if app.devices.sub.is_some() || app.devices.back.is_some() || picker.from_commands { "back" } else { "close" }), c.muted),
};
// (Too long for one line — a question beside the QR code — it takes the line above too.)
if line.width() as u16 <= w || y == 0 { settings::put(buf, x, y, w, &line, style); return }
@@ -2164,6 +2216,15 @@ mod tests {
p.select(id);
assert_eq!(p.current_id().as_deref(), Some(id), "no row {id}");
}
+ /// Onto a row of the remote password's level, in through its one row when not there already
+ /// (`pw:set` with no password yet is that row itself: Enter on it asks for one).
+ fn to_password(app: &mut App, id: &str) {
+ if ids(app).iter().any(|r| r == id) { return go_to(app, id) }
+ go_to(app, "pw:");
+ if id == "pw:set" && password_set(app) != Some(true) { return }
+ press(app, KeyCode::Enter);
+ go_to(app, id);
+ }
fn ids(app: &App) -> Vec<String> { match &app.modal { Some(Modal::Picker { picker, .. }) => picker.rows.iter().map(|r| r.id.clone()).collect(), _ => vec![] } }
fn clis(log: &Arc<Mutex<Vec<Req>>>, first: &str) -> Vec<Req> { log.lock().unwrap().iter().filter(|r| matches!(r, Req::Cli { args, .. } if args.first().map(String::as_str) == Some(first))).cloned().collect() }
fn has(log: &Arc<Mutex<Vec<Req>>>, want: &Req) -> bool { log.lock().unwrap().contains(want) }
@@ -2245,7 +2306,9 @@ mod tests {
app.rtt.insert(SHARED.into(), std::time::Duration::from_millis(42));
open(&mut app, View::Machines);
assert_eq!(row_of(&app, &format!("m:{SHARED}")).and_then(|r| r.group.as_deref()), Some("Shared with you"));
- assert!(row_of(&app, &format!("m:{SHARED}")).is_some_and(|r| r.right.starts_with("42ms")), "its round trip, as your own machines show");
+ assert_eq!(row_of(&app, &format!("m:{SHARED}")).map(|r| r.right.as_str()), Some("no harnesses"), "one value at the right, as your own machines show");
+ let said = preview(&app, View::Machines, &format!("m:{SHARED}")).iter().map(|l| l.to_string()).collect::<Vec<_>>().join("\n");
+ assert!(said.contains("42ms") && said.contains("Dee"), "its round trip and owner are in the preview: {said}");
assert_eq!(row_of(&app, &format!("addshared:{TEAM}")).map(|r| (r.label.as_str(), r.group.as_deref())), Some(("Add gpu-box-2", Some("Shared with your team"))));
assert_eq!(row_of(&app, &format!("m:{REMOTE}")).and_then(|r| r.group.as_deref()), Some("Your machines"));
@@ -2366,7 +2429,8 @@ mod tests {
open(&mut app, View::Machines);
go_to(&mut app, "share:");
press(&mut app, KeyCode::Enter);
- assert!(row_of(&app, "shr:guests-on").is_some_and(|r| r.detail.iter().any(|s| s.content.contains("since the update"))));
+ assert!(row_of(&app, "shr:guests-on").is_some_and(|r| r.detail.is_empty() && r.right == "off"));
+ assert!(preview(&app, View::Machines, "shr:guests-on").iter().any(|l| l.to_string().contains("since the update")), "why is in the preview");
go_to(&mut app, "shr:guests-on");
press(&mut app, KeyCode::Enter);
assert!(has(&log, &rpc("enable_guests", json!({}))));
@@ -2445,7 +2509,7 @@ mod tests {
assert!(text("account").starts_with("Signed in as [email protected]."), "{}", text("account"));
let share = text("share:");
- for said in ["People you invite get their own private space", "everyone at @acme.io · on", "[email protected]", "[email protected]", "using it [email protected]"] { assert!(share.contains(said), "{said}: {share}") }
+ for said in ["People you invite get their own private space", "everyone at @acme.io · on", "[email protected]", "[email protected]", "using it [email protected]"] { assert!(share.contains(said), "{said}: {share}") }
// Everyone at the domain may use it, and is the domain row: nobody at it is named one by one.
assert!(!share.contains("[email protected]"), "{share}");
let domain = text("shr:domain");
@@ -2463,7 +2527,9 @@ mod tests {
go_to(&mut app, "share:");
press(&mut app, KeyCode::Enter);
assert!(row_of(&app, "share-what").is_some_and(|r| r.label.chars().count() <= 44));
- assert!(row_of(&app, "shr:domain").is_some_and(|r| r.detail.iter().any(|s| s.content == "no invite needed")));
+ assert!(row_of(&app, "shr:domain").is_some_and(|r| r.detail.is_empty()));
+ assert!(preview(&app, View::Machines, "shr:domain").iter().any(|l| l.to_string().contains("no invite needed")), "what it means is in the preview");
+ assert_eq!(row_of(&app, "shr:rm:[email protected]").map(|r| r.right.as_str()), Some("joined"), "the right column is its state, not a verb");
assert_eq!(row_of(&app, "share-using").map(|r| r.label.as_str()), Some("Using it now: [email protected]"));
}
@@ -2529,22 +2595,33 @@ mod tests {
let _log = fake(&mut app);
crate::input::run(&mut app, "devices");
let rows = ids(&app);
- for id in ["pw:set", "pw:clear", &format!("m:{LOCAL}"), &format!("m:{REMOTE}"), &format!("m:{OFF}"), &format!("ln:{REMOTE}"), "ln:", "add:download", "add:connect", "add:install", "add:login", "add:start", "add:all"] {
- assert!(rows.iter().any(|r| r == id), "{id} missing from {rows:?}");
- }
+ assert_eq!(rows, vec!["account".to_string(), "pw:".into(), "share:".into(), format!("m:{LOCAL}"), format!("m:{REMOTE}"), format!("m:{OFF}"), "add:".into()]);
let Some(Modal::Picker { picker, .. }) = &app.modal else { panic!() };
let groups: Vec<&str> = picker.rows.iter().filter_map(|r| r.group.as_deref()).collect::<Vec<_>>();
let mut seen: Vec<&str> = Vec::new();
for g in groups { if seen.last() != Some(&g) { seen.push(g) } }
// This computer's section is under its name once it has one ("studio" here), not "This computer".
- assert_eq!(seen, vec!["Account", app.fleet.local_machine_name().as_str(), "Your machines", "Linked from here", "Add a machine", "Set up a server"], "each group once, in order");
- assert!(!seen.contains(&"This computer"));
- assert!(picker.rows.iter().any(|r| r.id == "add:login" && r.label == "2. Sign in as [email protected]"), "the server steps name the account");
- // A machine opens its actions: no Remove for this computer, Connect for one not linked.
+ assert_eq!(seen, vec!["Account", app.fleet.local_machine_name().as_str(), "Your machines"], "each group once, in order; Add a machine is the last of yours");
+ let account = preview(&app, View::Machines, "account").iter().map(|l| l.to_string()).collect::<Vec<_>>().join("\n");
+ assert!(account.contains("Signed in as [email protected]"), "the preview says what the row does: {account}");
+ // A row is its name and one value at the right: what it means is in the preview.
+ for r in &picker.rows {
+ assert!(r.detail.is_empty(), "{} has text after its name", r.id);
+ assert!(!r.right.contains(" ") && !r.right.contains('·'), "{} has two values at the right: {:?}", r.id, r.right);
+ }
+ assert_eq!(row_of(&app, "account").map(|r| r.label.clone()), Some("[email protected]".into()), "the account row names who is signed in");
+ assert_eq!(row_of(&app, &format!("m:{OFF}")).map(|r| r.right.clone()), Some("offline".into()));
+ // Narrow, only why one can't be used: a connected one's ✓ says the rest.
+ let narrow = |id: &str| row_of(&app, id).map(|r| r.right_at(30).to_string());
+ assert_eq!((narrow(&format!("m:{LOCAL}")), narrow(&format!("m:{OFF}"))), (Some(String::new()), Some("offline".into())));
+ let add = preview(&app, View::Machines, "add:").iter().map(|l| l.to_string()).collect::<Vec<_>>().join("\n");
+ assert!(add.contains("sign in as [email protected]") && !add.contains("curl") && !add.contains("http"), "the steps, no download or install: {add}");
+ // A machine opens its actions: no Remove for this computer, Connect for one not linked, Unlink for one linked.
go_to(&mut app, &format!("m:{REMOTE}"));
press(&mut app, KeyCode::Enter);
let acts = ids(&app);
assert!(acts.contains(&format!("act:connect:{REMOTE}")) && acts.contains(&format!("act:remove:{REMOTE}")) && acts.contains(&format!("act:rename:{REMOTE}")), "{acts:?}");
+ assert!(acts.contains(&format!("act:unlink:{REMOTE}")), "its saved link is removed from its actions: {acts:?}");
press(&mut app, KeyCode::Esc);
assert_eq!(picker_mut(&mut app).and_then(|p| p.current_id()), Some(format!("m:{REMOTE}")), "back on the machine");
go_to(&mut app, &format!("m:{LOCAL}"));
@@ -2561,6 +2638,8 @@ mod tests {
let usable: Vec<&str> = picker.rows.iter().filter(|r| !r.disabled).map(|r| r.id.as_str()).collect();
assert_eq!(usable, vec![format!("m:{REMOTE}").as_str(), "here:setup"]);
assert!(picker.rows.iter().any(|r| r.id == format!("m:{OFF}") && r.disabled), "an offline one is shown, not chosen");
+ assert!(picker.rows.iter().all(|r| r.detail.is_empty()), "a row is its name and state, as in Machines & devices");
+ assert!(picker.rows.iter().any(|r| r.id == "offline-how"), "how to bring one back is said once, under them");
}
#[test]
@@ -2700,7 +2779,7 @@ mod tests {
// (27 wide at the least: `[ Cancel ] [ Yes ]` is 19 columns and the panel is 4 narrower
// than the screen, with 2 columns of inset each side; the old buttons fit in 24.)
for (w, h) in [(150, 42), (80, 24), (40, 12), (27, 10)] {
- go_to(&mut app, "pw:clear");
+ to_password(&mut app, "pw:clear");
press(&mut app, KeyCode::Enter);
crate::input::handle(&mut app, crossterm::event::Event::Resize(w, h));
let (visible, _) = screen(&mut app, w, h);
@@ -2709,7 +2788,7 @@ mod tests {
assert!(app.devices.ask.is_none());
assert!(!has(&log, &clear));
}
- go_to(&mut app, "pw:clear"); press(&mut app, KeyCode::Enter);
+ to_password(&mut app, "pw:clear"); press(&mut app, KeyCode::Enter);
crate::input::handle(&mut app, crossterm::event::Event::Resize(80, 24));
screen(&mut app, 80, 24);
// Too small to draw: the question is cancelled, never kept invisible to answer keys.
@@ -2746,7 +2825,7 @@ mod tests {
assert_eq!(title(&mut app), "Connect · gpu-box");
press(&mut app, KeyCode::Esc);
crate::input::run(&mut app, "devices");
- go_to(&mut app, "pw:set");
+ to_password(&mut app, "pw:set");
press(&mut app, KeyCode::Enter);
assert_eq!(title(&mut app), "Set Remote Password");
typed(&mut app, "a"); press(&mut app, KeyCode::Enter);
@@ -2754,10 +2833,12 @@ mod tests {
typed(&mut app, "a"); press(&mut app, KeyCode::Enter);
assert_eq!(title(&mut app), "Set Remote Password", "and its question");
press(&mut app, KeyCode::Esc);
- go_to(&mut app, "pw:clear");
+ to_password(&mut app, "pw:clear");
press(&mut app, KeyCode::Enter);
assert_eq!(title(&mut app), "Clear Remote Password");
press(&mut app, KeyCode::Esc);
+ press(&mut app, KeyCode::Esc);
+ assert_eq!(picker_mut(&mut app).and_then(|p| p.current_id()).as_deref(), Some("pw:"), "out of its level, back on its row");
go_to(&mut app, &format!("m:{REMOTE}"));
press(&mut app, KeyCode::Enter);
go_to(&mut app, &format!("act:rename:{REMOTE}"));
@@ -2801,7 +2882,7 @@ mod tests {
buf[(x, y as u16)].bg
};
let selected = settings::chrome().selected.bg;
- go_to(&mut app, "pw:clear");
+ to_password(&mut app, "pw:clear");
press(&mut app, KeyCode::Enter);
let (s, buf) = screen(&mut app, 150, 42);
assert!(s.contains("[ Cancel ] [ Yes ]") && s.contains(buttons::KEYS), "the one keys hint every question shows: {s}");
@@ -2812,7 +2893,7 @@ mod tests {
press(&mut app, KeyCode::Enter);
assert!(app.devices.ask.is_none(), "Enter on Cancel closes");
assert!(!has(&log, &clear));
- go_to(&mut app, "pw:clear");
+ to_password(&mut app, "pw:clear");
press(&mut app, KeyCode::Enter);
press(&mut app, KeyCode::Right);
assert!(matches!(app.devices.ask, Some(Ask::Confirm { .. })), "an arrow keeps the prompt");
@@ -2975,7 +3056,7 @@ mod tests {
crate::input::run(&mut app, "devices");
for (w, h, label) in [(28, 12, "[ Next ]"), (31, 12, "[ Next ]"), (32, 12, "[ Continue ]"), (80, 24, "[ Continue ]")] {
crate::input::handle(&mut app, crossterm::event::Event::Resize(150, 42));
- go_to(&mut app, "pw:set");
+ to_password(&mut app, "pw:set");
press(&mut app, KeyCode::Enter);
typed(&mut app, "pw");
crate::input::handle(&mut app, crossterm::event::Event::Resize(w, h));
@@ -3032,18 +3113,21 @@ mod tests {
let log = fake(&mut app);
crate::input::run(&mut app, "devices");
// Unlink: y/n first; n changes nothing, y runs it.
- go_to(&mut app, &format!("ln:{REMOTE}"));
+ go_to(&mut app, &format!("m:{REMOTE}"));
+ press(&mut app, KeyCode::Enter);
+ go_to(&mut app, &format!("act:unlink:{REMOTE}"));
press(&mut app, KeyCode::Enter);
assert!(matches!(&app.devices.ask, Some(Ask::Confirm { question, .. }) if question.contains("gpu-box")));
press(&mut app, KeyCode::Char('n'));
let unlink = cli(&["link", "unlink", REMOTE], None);
assert!(!has(&log, &unlink), "n: nothing ran");
- go_to(&mut app, &format!("ln:{REMOTE}"));
+ go_to(&mut app, &format!("act:unlink:{REMOTE}"));
press(&mut app, KeyCode::Enter);
press(&mut app, KeyCode::Char('y'));
assert!(has(&log, &unlink), "y: unlinked");
+ press(&mut app, KeyCode::Esc);
// Set password: twice, a mismatch caught, then y/n.
- go_to(&mut app, "pw:set");
+ to_password(&mut app, "pw:set");
press(&mut app, KeyCode::Enter);
typed(&mut app, "abc");
press(&mut app, KeyCode::Enter);
@@ -3059,10 +3143,11 @@ mod tests {
press(&mut app, KeyCode::Char('y'));
assert!(has(&log, &set), "the password went on stdin");
// Clear.
- go_to(&mut app, "pw:clear");
+ to_password(&mut app, "pw:clear");
press(&mut app, KeyCode::Enter);
press(&mut app, KeyCode::Esc);
assert!(!has(&log, &cli(&["remote-password", "clear", "--json"], None)));
+ press(&mut app, KeyCode::Esc);
// Rename, then remove from the account.
go_to(&mut app, &format!("m:{REMOTE}"));
press(&mut app, KeyCode::Enter);
@@ -3191,10 +3276,60 @@ mod tests {
assert_eq!(picker.current_id().as_deref(), Some("cmd:devices"));
}
+ // Seen 2026-10-21: Add a machine opened Connect a computer, and Esc there closed the whole panel;
+ // its Set up another computer opened Machines again on top.
+ #[test]
+ fn add_a_machine_opens_connect_and_esc_comes_back_to_it() {
+ let mut app = app((150, 42));
+ app.mouse = true;
+ let _log = fake(&mut app);
+ let view = |app: &App| match &app.modal { Some(Modal::Picker { kind: PickerKind::Devices(v), picker }) => Some((*v, picker.current_id())), _ => None };
+ crate::input::run(&mut app, "devices");
+ go_to(&mut app, "add:");
+ press(&mut app, KeyCode::Enter);
+ assert_eq!(view(&app).map(|v| v.0), Some(View::Connect));
+ let (s, _) = screen(&mut app, 150, 42);
+ assert!(s.contains("Machines & devices › Connect a computer") && s.contains("esc back"), "the way here, and back:\n{s}");
+ // Esc: back on Add a machine, not closed.
+ press(&mut app, KeyCode::Esc);
+ assert_eq!(view(&app), Some((View::Machines, Some("add:".into()))));
+ assert!(app.devices.back.is_none());
+ // Set up another computer goes back too, rather than a third view on top.
+ go_to(&mut app, "add:");
+ press(&mut app, KeyCode::Enter);
+ go_to(&mut app, "here:setup");
+ press(&mut app, KeyCode::Enter);
+ assert_eq!(view(&app), Some((View::Machines, Some("add:".into()))));
+ // And a click on where it came from, as Esc.
+ go_to(&mut app, "add:");
+ press(&mut app, KeyCode::Enter);
+ let (s, _) = screen(&mut app, 150, 42);
+ let (y, line) = s.lines().enumerate().find(|(_, l)| l.contains("Machines & devices ›")).unwrap();
+ let x = line[..line.find("Machines & devices").unwrap()].chars().count() as u16;
+ assert!(mouse(&mut app, MouseEvent { kind: MouseEventKind::Down(MouseButton::Left), column: x + 2, row: y as u16, modifiers: KeyModifiers::NONE }));
+ assert_eq!(view(&app), Some((View::Machines, Some("add:".into()))));
+ // Esc again closes it, as it did.
+ press(&mut app, KeyCode::Esc);
+ assert!(view(&app).is_none());
+ }
+
#[test]
fn nothing_real_runs_under_test() {
let mut app = app((150, 42));
crate::input::run(&mut app, "devices");
assert!(matches!(app.devices.password, Some(Err(_))), "the CLI is not there in tests");
}
+
+ // Seen 2026-10-21: `mach` in Commands listed Open harness and New pane above the machine ones.
+ #[test]
+ fn searching_commands_for_machines_lists_the_machine_ones_first() {
+ let app = app((150, 42));
+ let mut c = crate::picker::Picker::new("Commands", "");
+ (c.live, c.search_extra) = (true, true); // as the panel opens it
+ c.set_rows(crate::modal::command_rows_for(&app, true, false));
+ c.set_query("mach");
+ let labels: Vec<String> = c.visible.iter().map(|(i, _)| c.rows[*i].label.to_lowercase()).collect();
+ let named = labels.iter().take_while(|l| l.contains("mach")).count();
+ assert!(named >= 2 && labels[named..].iter().all(|l| !l.contains("mach")), "{labels:?}");
+ }
}
diff --git a/tui/src/modal.rs b/tui/src/modal.rs
index 85d9c9a5d..7220c3a1a 100644
--- a/tui/src/modal.rs
+++ b/tui/src/modal.rs
@@ -1033,14 +1033,18 @@ mod theme_row_tests {
// Never twice: copy-mode, new-window, clone-harness are hn's own already.
for name in ["copy-mode", "new-window", "clone-harness", "kill-pane"] { assert!(!tmux.iter().any(|r| r.label == name), "{name} twice") }
assert!(tmux.iter().any(|r| r.label == "select-layout"));
- // Searched: hn's matches before tmux's, whatever they score.
+ // Searched: rows whose name shows what you typed first, hn's before tmux's whatever they
+ // score; then the rows only their hidden words name.
let mut p = crate::picker::Picker::new("Commands", "");
p.search_extra = true; // as the panel opens it: a row's hint is searched, not shown
p.set_rows(command_rows_for(&app, true, false));
p.set_query("lay");
- let shown: Vec<&str> = p.visible.iter().map(|(i, _)| p.rows[*i].id.as_str()).collect();
- let first_tmux = shown.iter().position(|id| id.starts_with("tmux:")).unwrap();
- assert!(shown[..first_tmux].contains(&"cmd:layout") && shown[first_tmux..].iter().all(|id| id.starts_with("tmux:")), "{shown:?}");
+ let shown: Vec<(&str, bool)> = p.visible.iter().map(|(i, _)| (p.rows[*i].id.as_str(), p.rows[*i].label.to_lowercase().contains("lay"))).collect();
+ let named = shown.iter().take_while(|(_, says)| *says).count();
+ assert!(named > 1 && shown[named..].iter().all(|(_, says)| !says), "every row named `lay…` comes first: {shown:?}");
+ let first_tmux = shown[..named].iter().position(|(id, _)| id.starts_with("tmux:")).unwrap_or(named);
+ assert!(shown[first_tmux..named].iter().all(|(id, _)| id.starts_with("tmux:")), "hn's before tmux's: {shown:?}");
+ assert_eq!(shown.first().map(|(id, _)| *id), Some("cmd:layout"), "{shown:?}");
}
/// The list is names and keys: no description beside a row. Account is one row (Sign out is in
diff --git a/tui/src/picker.rs b/tui/src/picker.rs
index 6ac7e9840..36f3d10b1 100644
--- a/tui/src/picker.rs
+++ b/tui/src/picker.rs
@@ -37,7 +37,8 @@ pub struct Row {
/// Its line comes before its right column wherever both don't fit (a question, a failure).
pub line_first: bool,
/// A search lists a lower tier's matches first, however well a higher one's match (the command
- /// list: hn's own, then tmux's).
+ /// list: hn's own, then tmux's) — among the rows that show what was typed, then again among
+ /// the rows only their searched keywords name.
pub tier: u8,
}
@@ -433,6 +434,9 @@ impl Picker {
}
sorted = !self.keep_order && q.sortable() && (o.no_sort == self.sort_flipped);
if sorted { scored.sort_by(|a, b| a.0.cmp(&b.0)) }
+ // Rows lit only in their searched keywords (a command's group) come after every row
+ // that shows what you typed, however well they scored: `mach` lists the machine ones first.
+ let (scored, behind): (Vec<_>, Vec<_>) = if self.search_extra { scored.into_iter().partition(|(_, _, hits)| !hits.is_empty()) } else { (scored, Vec::new()) };
// Rows its keywords name (`codex`: the Codex harnesses) come before rows the query
// found only as letters scattered through the line (c…o…d…e…x in `gpu-box`).
let plain: Vec<String> = q.positive_terms().into_iter().filter(|w| w.chars().count() >= 3).map(|w| w.to_lowercase()).collect();
@@ -448,12 +452,12 @@ impl Picker {
} else { Vec::new() };
// Rows its keywords name, or where what was said found it, before rows the query found
// only as letters scattered through the line.
- let (weak, strong): (Vec<_>, Vec<_>) = if hidden.is_empty() && said_all.is_empty() { (Vec::new(), scored) } else { scored.into_iter().partition(|(_, i, _)| scattered(*i) && !said_all.contains(i)) };
- let taken: std::collections::HashSet<usize> = strong.iter().map(|(_, i, _)| *i).chain(hidden.iter().copied()).chain(weak.iter().map(|(_, i, _)| *i)).collect();
+ let (weak, strong): (Vec<_>, Vec<_>) = if hidden.is_empty() && behind.is_empty() && said_all.is_empty() { (Vec::new(), scored) } else { scored.into_iter().partition(|(_, i, _)| scattered(*i) && !said_all.contains(i)) };
+ let taken: std::collections::HashSet<usize> = strong.iter().chain(&behind).map(|(_, i, _)| *i).chain(hidden.iter().copied()).chain(weak.iter().map(|(_, i, _)| *i)).collect();
let said: Vec<usize> = said_all.into_iter().filter(|i| !taken.contains(i)).collect();
let mut seen = std::collections::HashSet::new();
let said: Vec<usize> = said.into_iter().filter(|i| seen.insert(*i)).collect();
- self.visible = strong.into_iter().map(|(_, i, hits)| (i, hits)).chain(hidden.into_iter().map(|i| (i, Vec::new()))).chain(said.into_iter().map(|i| (i, Vec::new()))).chain(weak.into_iter().map(|(_, i, hits)| (i, hits))).collect();
+ self.visible = strong.into_iter().chain(behind).map(|(_, i, hits)| (i, hits)).chain(hidden.into_iter().map(|i| (i, Vec::new()))).chain(said.into_iter().map(|i| (i, Vec::new()))).chain(weak.into_iter().map(|(_, i, hits)| (i, hits))).collect();
}
// --tac: the input order reversed (wherever the order is the input's).
if crate::theme::fzf_opts().tac && !sorted { self.visible.reverse() }
@@ -970,6 +974,25 @@ mod tests {
assert_eq!(ids(&p), ["b"]);
}
+ // Seen 2026-10-21 in Commands: `mach` listed Open harness and New pane (their group, Machines,
+ // is in their keywords) above List machines and Connect machines.
+ #[test]
+ fn rows_that_show_the_query_come_before_rows_only_their_keywords_name() {
+ let mut p = Picker::new("t", "");
+ p.live = true;
+ p.search_extra = true;
+ p.set_rows(vec![
+ Row::new("open", "Open harness").extra("open harnesses machine").right("D-b s"),
+ Row::new("pane", "New pane").extra("new-pane Machines").right("D-b T"),
+ Row::new("list", "List machines").extra("machines Machines").right("D-b @"),
+ Row::new("connect", "Connect machines").extra("devices Machines"),
+ Row::new("menu", "machine-menu").extra("machine-menu").tier(1),
+ ]);
+ let ids = |p: &Picker| p.visible.iter().map(|(i, _)| p.rows[*i].id.clone()).collect::<Vec<_>>();
+ p.set_query("mach");
+ assert_eq!(ids(&p), ["list", "connect", "menu", "open", "pane"], "what you see named first, a lower tier among them; the keywords' finds after");
+ }
+
/// A live list (C-b s) finds what its rows show but what changes as you look: the question,
/// the error, the finished turn, the pull request, lit where they are; keywords by OR groups;
/// state words whole; `#4807` a pull request's number.
diff --git a/tui/tests/workspace-controls.py b/tui/tests/workspace-controls.py
index 2697dcea3..7c7430b56 100644
--- a/tui/tests/workspace-controls.py
+++ b/tui/tests/workspace-controls.py
@@ -276,17 +276,21 @@ def machine_prompt_journey():
# The question is asked in its own box; the panel's search line stays the search.
shown('┌─' + title)
shown('[ Cancel ] [ ' + action + ' ]')
- assert 'Search machines, links and steps' in screen()
+ assert 'Search machines' in screen()
+ # The list's own column: the preview beside it may name the row too.
+ list_x = 40
hn('devices')
- shown('Set password…')
- click_text('Set password…')
+ shown('Remote password')
+ shown('not set')
+ # With no password yet, its one row asks for one at once.
+ click_text('Remote password', before=list_x)
shown('New remote password')
dialog('Set Remote Password', 'Continue')
paste_password()
assert '│' + '•' * len('fixture pasted password') in screen(), 'the password is typed into the dialog input'
# A list click used to become Enter and accept the unfinished password.
- click_text('Refresh links')
+ click_text('Add a machine', before=list_x)
shown('New remote password')
assert 'Repeat password' not in screen()
click_text('Continue')
@@ -301,13 +305,17 @@ def machine_prompt_journey():
shown('Nothing changed')
assert not actions() and 'fixture pasted password' not in screen()
- click_text('Set password…')
+ click_text('Remote password', before=list_x)
paste_password()
click_text('Continue')
paste_password()
click_text('Continue')
click_text('[ Yes ]')
wait(lambda: actions() == ['set'], 'one explicitly confirmed password write')
+ # Once there is one, its row opens Change and Clear.
+ shown('✓ Remote password')
+ click_text('Remote password', before=list_x)
+ shown('Change password…')
shown('Clear password…')
click_text('Clear password…')
shown('Prevent new links')
@@ -321,8 +329,12 @@ def machine_prompt_journey():
snapshot(f'machine-confirmation-{cols}x{rows}')
click_text('Cancel')
assert actions() == ['set']
- keys('Escape')
tmux('resize-window', '-t', 'test', '-x', '170', '-y', '44')
+ # Esc leaves the password's level first, then closes the panel.
+ keys('Escape')
+ shown('Your machines')
+ keys('Escape')
+ wait(lambda: 'Machines & devices' not in screen(), 'the panel closes')
shown('Alpha task terminal')
print('PASS workspace: machine prompts accept mouse confirmation, protect pasted passwords, cancel and resize', flush=True)