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.

hn 0.1.20: a phone's approval is the answer; a trimmer account panel (#1099)

lingrdb5b6fd4ef10c
diff --git a/tui/Cargo.lock b/tui/Cargo.lock
index 3b8ceb7cd..56c86c693 100644
--- a/tui/Cargo.lock
+++ b/tui/Cargo.lock
@@ -654,7 +654,7 @@ dependencies = [
[[package]]
name = "harness-tui"
-version = "0.1.19"
+version = "0.1.20"
dependencies = [
"alacritty_terminal",
"base64",
diff --git a/tui/Cargo.toml b/tui/Cargo.toml
index 0bf0c54f9..f9e65c8d1 100644
--- a/tui/Cargo.toml
+++ b/tui/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "harness-tui"
-version = "0.1.19"
+version = "0.1.20"
edition = "2024"
[dependencies]
diff --git a/tui/src/account.rs b/tui/src/account.rs
index 8226e5493..91aad1d62 100644
--- a/tui/src/account.rs
+++ b/tui/src/account.rs
@@ -28,7 +28,6 @@ enum Phase {
Starting,
Browser(String),
Phone { url: String, expires: Instant },
- Confirm(String),
Completing,
Committed,
SigningOut,
@@ -158,11 +157,6 @@ pub fn fill(app: &App, picker: &mut Picker) {
rows.push(Row::new("account:copy", "Copy phone sign-in link"));
rows.push(Row::new("account:cancel", "Cancel sign-in"));
}
- Phase::Confirm(email) => {
- // No account gets accepted merely because Enter was used on the preceding page.
- rows.push(Row::new("account:deny", "Cancel sign-in"));
- rows.push(Row::new("account:confirm", format!("Sign in as {email}")));
- }
Phase::Completing => rows.push(Row::new("account:wait", "Finishing sign-in…")),
Phase::Committed => {
rows.push(Row::new("account:wait", "Signed in · connecting this computer…"));
@@ -172,7 +166,6 @@ pub fn fill(app: &App, picker: &mut Picker) {
Status::SignedIn { .. } => {
rows.push(Row::new("account:machines", "Connect a machine"));
rows.push(Row::new("account:phone", "Add your phone"));
- rows.push(Row::new("account:models", "Models on your machines"));
rows.push(Row::new("account:signout", "Sign out"));
}
_ => {
@@ -182,7 +175,8 @@ pub fn fill(app: &App, picker: &mut Picker) {
}
},
}
- rows.push(Row::new("account:back", if matches!(app.account.status, Status::SignedIn { .. }) { "Back to workspace" } else { "Keep using locally" }));
+ // Signed in, Esc is the way back; signed out, "Keep using locally" says that sign-in is optional.
+ if !matches!(app.account.status, Status::SignedIn { .. }) { rows.push(Row::new("account:back", "Keep using locally")) }
// These are page actions, not a growing search result list. Keep Back last
// across sign-in phases; set_rows still preserves the selected action by ID.
picker.rows.clear();
@@ -220,10 +214,6 @@ pub fn preview(app: &App, _: &str) -> Vec<Line<'static>> {
lines.push(Line::raw(""));
lines.push(Line::raw(format!("Expires in {}s", expires.saturating_duration_since(Instant::now()).as_secs())));
}
- Phase::Confirm(email) => {
- lines.push(Line::raw(format!("Your phone approved {email}.")));
- lines.push(Line::raw("Choose that account here to finish."));
- }
Phase::Failed(message) => lines.push(Line::raw(message.clone())),
Phase::Starting => lines.push(Line::raw(app.account.waiting.clone().unwrap_or_else(|| "Opening sign-in…".into()))),
Phase::SigningOut => lines.push(Line::raw(SIGNING_OUT)),
@@ -270,12 +260,11 @@ pub fn draw(buf: &mut Buffer, app: &App, body: Rect, picker: &mut Picker) -> Opt
let mut lines = match &app.account.phase {
Phase::Ready => match &app.account.status {
Status::SignedIn { email, offline } => vec![Line::raw(email.clone().unwrap_or_else(|| "Signed in".into())),
- Line::raw(if *offline { "Account is offline. Local work is still available." } else { "Manage your connected computers, phone and models." })],
+ Line::raw(if *offline { "Account is offline. Local work is still available." } else { "Manage your connected computers and phone." })],
_ => vec![Line::raw("Connect computers and sync your workspace."), Line::raw("Use models on a linked machine. Follow work from your phone."),
Line::raw(""), Line::raw("Sign-in is optional. Keep working locally anytime.")],
},
Phase::Browser(_) => vec![Line::raw("Finish signing in in your browser."), Line::raw("Using SSH? Cancel and choose Sign in with your phone.")],
- Phase::Confirm(email) => vec![Line::raw(format!("Your phone approved {email}.")), Line::raw("Choose that account below to finish.")],
Phase::Failed(message) => vec![Line::raw(message.clone())],
Phase::Phone { .. } => preview(app, ""),
Phase::Starting => vec![Line::raw(app.account.waiting.clone().unwrap_or_else(|| "Opening sign-in…".into()))],
@@ -309,8 +298,8 @@ pub fn choose(app: &mut App, mut picker: Picker, id: &str) {
// Reattach before callbacks update the view; every completion checks its own attempt.
let action = id.strip_prefix("account:").unwrap_or("");
if action == "back" { cancel(app); return }
- if matches!(action, "machines" | "phone" | "models") {
- crate::input::run(app, match action { "machines" => "connect-machine", "phone" => "add-phone", _ => "models" });
+ if matches!(action, "machines" | "phone") {
+ crate::input::run(app, if action == "machines" { "connect-machine" } else { "add-phone" });
return;
}
picker.set_query("");
@@ -318,15 +307,7 @@ pub fn choose(app: &mut App, mut picker: Picker, id: &str) {
match action {
"google" | "apple" | "qr" => start(app, action),
"signout" => ask_sign_out(app, true),
- "cancel" | "deny" => { cancel(app); refill(app); }
- "confirm" => {
- if matches!(app.account.phase, Phase::Confirm(_)) {
- if let Some(tx) = &app.account.driver { let _ = tx.send(Driver::Answer(true)); }
- app.account.phase = Phase::Completing;
- app.account.waiting = Some("Finishing sign-in…".into());
- refill(app);
- }
- }
+ "cancel" => { cancel(app); refill(app); }
"browser" => { if let Phase::Browser(url) = &app.account.phase { open_browser(app, url.clone()); } }
"copy" => {
let url = match &app.account.phase { Phase::Browser(url) | Phase::Phone { url, .. } => Some(url.clone()), _ => None };
@@ -456,10 +437,16 @@ fn event(app: &mut App, generation: u64, value: Value) {
let seconds = value["expiresIn"].as_u64().unwrap_or(120).clamp(1, 600);
app.account.phase = Phase::Phone { url: url.into(), expires: Instant::now() + Duration::from_secs(seconds) };
},
+ // The phone that approved is signed in to the account, and its person scanned this code, so
+ // there is nothing left to ask here: the CLI is told yes and finishes the sign-in.
Some("confirm") => {
let email = clean("email");
if !email.contains('@') { cancel(app); app.account.phase = Phase::Failed("The phone returned no valid account. Try signing in again.".into()); }
- else { app.account.phase = Phase::Confirm(email); }
+ else {
+ if let Some(tx) = &app.account.driver { let _ = tx.send(Driver::Answer(true)); }
+ app.account.phase = Phase::Completing;
+ app.account.waiting = Some("Finishing sign-in…".into());
+ }
}
Some("waiting") => app.account.waiting = Some(clean("message")),
Some("result") if value["status"] == "success" => {
@@ -471,7 +458,6 @@ fn event(app: &mut App, generation: u64, value: Value) {
_ => {}
}
refill(app);
- if matches!(app.account.phase, Phase::Confirm(_)) { if let Some(Modal::Picker { picker, .. }) = &mut app.modal { picker.select("account:deny"); } }
}
fn finished(app: &mut App, generation: u64, committed: bool, error: Option<String>) {
@@ -626,13 +612,14 @@ mod tests {
app.account.status = if signed_in { Status::SignedIn { email:Some("[email protected]".into()), offline:false } } else { Status::SignedOut };
crate::input::picker(&mut app, PickerKind::Account, "Your Harness account", "");
let (text, _) = render(&mut app, 40, 12);
- for label in if signed_in { vec!["Connect a machine", "Add your phone", "Models on your machines", "Sign out", "Back to workspace"] }
+ for label in if signed_in { vec!["Connect a machine", "Add your phone", "Sign out"] }
else { vec!["Continue with Google", "Continue with Apple", "Sign in with your phone", "Keep using locally"] } {
assert!(text.contains(label), "{label}\n{text}");
}
+ if signed_in { for gone in ["Models on your machines", "Back to workspace"] { assert!(!text.contains(gone), "{gone} is not offered\n{text}") } }
assert!(text.contains("Esc back"));
let Some(Modal::Picker { picker, .. }) = &app.modal else { panic!() };
- assert!(picker.list_area.get().height >= 4);
+ assert!(picker.list_area.get().height >= if signed_in { 3 } else { 4 }, "every action stays visible");
}
}
@@ -737,23 +724,16 @@ mod tests {
}
#[test]
- fn phone_approval_requires_an_explicit_account_choice_and_is_not_repeated() {
+ fn phone_approval_signs_in_at_once_and_is_not_repeated() {
let mut app = app();
open(&mut app);
select(&mut app, "account:qr");
let generation = app.account.generation;
- event(&mut app, generation, json!({ "type": "confirm", "email": "[email protected]" }));
let (sender, mut receive) = mpsc::unbounded_channel();
app.account.driver = Some(sender);
- key(&mut app, KeyCode::Enter);
- assert_eq!(receive.try_recv().unwrap(), Driver::Cancel, "Enter must not accept an account just arriving from a phone");
- select(&mut app, "account:qr");
- let generation = app.account.generation;
event(&mut app, generation, json!({ "type": "confirm", "email": "[email protected]" }));
- let (sender, mut receive) = mpsc::unbounded_channel();
- app.account.driver = Some(sender);
- select(&mut app, "account:confirm");
- assert_eq!(receive.try_recv().unwrap(), Driver::Answer(true));
+ assert_eq!(receive.try_recv().unwrap(), Driver::Answer(true), "the phone's approval is the answer; nothing more is asked here");
+ assert_eq!(app.account.phase, Phase::Completing);
key(&mut app, KeyCode::Enter);
key(&mut app, KeyCode::Esc);
tick(&mut app);
@@ -802,7 +782,7 @@ mod tests {
}
#[tokio::test]
- async fn cli_driver_keeps_stdin_open_then_delivers_exact_phone_approval() {
+ async fn cli_driver_keeps_stdin_open_then_answers_the_phone_approval_itself() {
let mut app = app();
open(&mut app);
let (sink, mut events) = mpsc::unbounded_channel();
@@ -812,9 +792,7 @@ mod tests {
command.args(["-c", r#"printf '%s\n' '{"type":"confirm","email":"[email protected]"}'; IFS= read -r answer; [ "$answer" = yes ] || exit 1; printf '%s\n' '{"type":"result","status":"success","email":"[email protected]"}'"#]);
let task = tokio::spawn(drive(command, app.account.generation, sink, receive));
apply_next(&mut app, &mut events).await;
- assert!(matches!(app.account.phase, Phase::Confirm(_)));
- assert!(!task.is_finished(), "CLI must still be waiting for the user");
- sender.send(Driver::Answer(true)).unwrap();
+ assert_eq!(app.account.phase, Phase::Completing, "no step is shown for an account the phone already approved");
apply_next(&mut app, &mut events).await;
assert_eq!(app.account.phase, Phase::Committed);
apply_next(&mut app, &mut events).await;
diff --git a/tui/src/devices.rs b/tui/src/devices.rs
index 477b006b3..150a058c0 100644
--- a/tui/src/devices.rs
+++ b/tui/src/devices.rs
@@ -479,9 +479,9 @@ fn opened(app: &mut App, view: View) {
let generation = app.devices.phone.generation;
sign_in(app, generation);
load_pairs(app);
- // (The QR shows at once; handing the daemon its code is a write, so it waits for a yes —
- // asked at once, unless there is no Harness here to hand it to.)
- if !app.daemon_down { confirm(app, format!("Let the phone that scans this code pair with this {}?", this_computer()), Act::ArmPhone) }
+ // Opening Add your phone is the ask: the code is handed to the daemon at once, as long as
+ // the QR is on screen, unless there is no Harness here to hand it to.
+ if !app.daemon_down { run_act(app, Act::ArmPhone) }
}
}
}
@@ -1046,7 +1046,7 @@ pub fn choose(app: &mut App, view: View, picker: Picker, enter: bool) {
_ => copy(app, &format!("{INSTALL}\n{LOGIN}\n{START}")),
},
(_, "ph") => match rest.as_str() {
- "arm" => confirm(app, format!("Let the phone that scans this code pair with this {}?", this_computer()), Act::ArmPhone),
+ "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") }
fp => {
let name = app.devices.phone.paired.iter().find(|p| p.get("fingerprint").and_then(Value::as_str) == Some(fp)).map(device_name).unwrap_or_else(|| "this device".into());
@@ -2368,12 +2368,13 @@ mod tests {
}
#[test]
- fn add_phone_shows_the_qr_for_the_link_and_arms_only_after_a_yes() {
+ fn add_phone_shows_the_qr_for_the_link_and_arms_without_asking() {
let mut app = app((150, 42));
let log = fake(&mut app);
crate::input::run(&mut app, "add-phone");
let pair = |log: &Arc<Mutex<Vec<Req>>>| log.lock().unwrap().iter().filter(|r| matches!(r, Req::Http { path, .. } if path == "/api/pair")).count();
- assert_eq!(pair(&log), 0, "not armed before the yes");
+ assert!(app.devices.ask.is_none(), "no dialog: opening Add your phone is the ask");
+ assert_eq!(pair(&log), 1, "armed at once: the code handed over");
let link = phone_link(&app).expect("a link");
assert!(link.starts_with("https://harness.autonomous.ai/pair#e=dev%2Bhn%40example.com&m=") && link.contains("&h=hs_"), "{link}");
let (s, buf) = screen(&mut app, 150, 42);
@@ -2382,8 +2383,6 @@ mod tests {
let grouped: Vec<String> = app.devices.phone.code.as_bytes().chunks(4).map(|g| String::from_utf8_lossy(g).to_string()).collect();
assert!(s.contains(&grouped.join(" ")), "the code in text:\n{s}");
assert!(s.contains("Dee's iPhone") && !s.contains("Cabled gadget"), "the phones and computers paired, nothing else:\n{s}");
- press(&mut app, KeyCode::Char('y'));
- assert_eq!(pair(&log), 1, "armed: the code handed over");
assert!(has(&log, &http("POST", "/api/pair", Some(json!({ "code": app.devices.phone.code })))));
assert!(app.devices.phone.message.is_none(), "no phone yet is not an error");
}
@@ -2403,7 +2402,7 @@ mod tests {
View::Phone if w == 80 => assert!(s.contains("to show the QR code") && app.devices.phone.drawn.get().is_none(), "too small says so:\n{s}"),
View::Phone => assert!(app.devices.phone.drawn.get().is_some(), "{s}"),
}
- if view == View::Phone { assert!(s.contains("[ Cancel ] [ Yes ]"), "asks before handing over the code:\n{s}") }
+ if view == View::Phone { assert!(!s.contains("[ Yes ]"), "no dialog before handing over the code:\n{s}") }
}
}
}
diff --git a/tui/tests/workspace-controls.py b/tui/tests/workspace-controls.py
index fedf9d567..3d46732e3 100644
--- a/tui/tests/workspace-controls.py
+++ b/tui/tests/workspace-controls.py
@@ -735,16 +735,13 @@ try:
click_text('Sign in with your phone')
shown('Cancel sign-in')
(BASE / 'approve').touch()
- shown('Sign in as [email protected]')
- assert not (BASE / 'account.json').exists()
- snapshot('confirm-account')
- click_text('Sign in as [email protected]')
- wait(lambda: 'commit' in login_events(), 'explicit account confirmation commits')
+ # The phone that approved is signed in to the account: no second question here.
+ wait(lambda: 'commit' in login_events(), 'a phone approval commits without another step')
shown('Connect a machine')
assert json.loads((BASE / 'account.json').read_text())['loggedIn']
snapshot('signed-in')
- click_text('Back to workspace')
- print('PASS workspace: tab identity survives focus changes; phone login requires explicit account confirmation', flush=True)
+ keys('Escape')
+ print('PASS workspace: tab identity survives focus changes; phone login signs in as soon as the phone approves', flush=True)
# Save failures preserve the session, and a busy session needs an explicit Stop action.
hn('select-window', '-t', workspace)
@@ -896,7 +893,7 @@ try:
shown('Commands')
snapshot(f'workspace-menu-{cols}x{rows}')
click_text('Account')
- shown('Back to workspace')
+ shown('Sign out')
snapshot(f'account-{cols}x{rows}')
keys('Escape')
hn('workspace-menu')