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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
feat(hn): Models lists what the desktop picker lists, as it lists it
bitcoinbuilder625083ba476a
diff --git a/tui/src/app.rs b/tui/src/app.rsindex 8bf27da7f..c8389f32a 100644--- a/tui/src/app.rs+++ b/tui/src/app.rs@@ -555,8 +555,6 @@ pub struct App {pub dsh: HashMap<String, Vec<Value>>,/// A dismissed New Harness draft, including any pending creation receipt.pub new_harness_draft: Option<Box<crate::new_harness::Form>>,- /// Each harness's selectable models (`models_list`), for ⌥I.- pub models: HashMap<(String, String), Vec<Value>>,/// ── models: the Models view's replies (local models, grids, APIs) and a Use under way ──pub models_view: crate::models::Models,/// Each machine's last measured round trip (the live roster request), for `@`.@@ -1009,7 +1007,6 @@ impl App {daemon_down: false,dsh: HashMap::new(),new_harness_draft: None,- models: HashMap::new(),models_view: Default::default(),rtt: HashMap::new(),homes: HashMap::new(),diff --git a/tui/src/input.rs b/tui/src/input.rsindex 411c9dc13..0d01fb3ca 100644--- a/tui/src/input.rs+++ b/tui/src/input.rs@@ -611,7 +611,7 @@ fn fill_rows(app: &App, kind: &PickerKind, picker: &mut Picker) {// Its spinner turns while what it lists is still coming in, as fzf's does while it reads.let busy = match kind {PickerKind::Store => is_loading(&format!("dsh {}", app.fleet.local_id)),- PickerKind::Models => crate::models::loading(app) || focused_agent(app).is_some_and(|(m, a)| is_loading(&format!("models {m} {a}"))),+ PickerKind::Models => crate::models::loading(app),_ => false,};picker.busy = busy.then(|| "loading".to_string());@@ -661,22 +661,23 @@ fn fill_rows(app: &App, kind: &PickerKind, picker: &mut Picker) {picker.hints = vec![("enter", "its harnesses"), ("C-t", "a session of them"), ("M-n", "new harness there")];picker.empty = "No projects yet.".into();}- // ── models: the Models view's sections (models.rs), then the engine's own models ──+ // ── models: the Models view's sections, as the desktop picker lists them (models.rs) ──PickerKind::Models => {- let mut rows = crate::models::rows(app, crate::models::searched(picker));+ let rows = crate::models::rows(app, crate::models::searched(picker));let in_use = crate::models::in_use_row(&rows);- rows.extend(modal::model_rows(app));+ let top = rows.first().map(|r| r.id.clone());+ let before = picker.selected_id.clone();// (Rebuilt in its sections each time — a model moves to where its state puts it, a// reply come late lands in its section — the cursor staying on its row.)picker.rows.clear();picker.set_rows(rows);- // Start on the model it runs — the grid model it is on, else its engine's model — so- // ↑/↓ are "a little more / less" from where it is.- if picker.query.trim() == ":" && picker.selected_id.is_none() {- if let Some(current) = in_use.or_else(|| focused_agent(app).and_then(|(m, a)| app.fleet.agent(&m, &a).map(|x| x.model.clone()))) {- if let Some(at) = picker.visible.iter().position(|(i, _)| picker.rows[*i].id == current) { picker.cursor = at; picker.selected_id = Some(current) }- }+ // Start on what the harness is on — the model, the API's or its own login — else the+ // top row, as the desktop's picker does; and follow it there as replies arrive, until a+ // key moves the cursor elsewhere.+ if picker.query.trim() == ":" && (before.is_none() || before == picker.placed) {+ if let Some(want) = in_use.or(top) { picker.select(&want); picker.placed = picker.selected_id.clone() }}+ picker.right_half = true;picker.hints = vec![("enter", "use · get"), ("C-s", "stop a local model")];picker.empty = if crate::models::target(app).is_none() { crate::models::no_target_why(app) } else { "Loading its models…".into() };picker.status = app.focused().and_then(|f| app.panes.get(&f)).and_then(|p| app.fleet.agent(&p.machine_id, &p.agent_id)).map(|a| a.name.clone()).unwrap_or_default();@@ -836,16 +837,6 @@ fn prepare(app: &mut App, kind: &PickerKind) {fn load_models(app: &mut App) {// ── models: this computer's models, the grids and the saved APIs (models.rs) ──crate::models::open(app);- // (The focused pane's engine's own models — what `model_rows` lists for that pane.)- let Some((machine, agent)) = focused_agent(app) else { return };- let Some(link) = app.link(&machine) else { return };- let mark = loading(format!("models {machine} {agent}"), true);- let key = (machine, agent.clone());- app.spawn(async move { link.rpc("models_list", json!({ "agentId": agent }), Duration::from_secs(20)).await }, move |app, reply| {- loading(mark, false);- if let Ok(reply) = reply { app.models.insert(key, reply.get("models").and_then(|v| v.as_array()).cloned().unwrap_or_default()); }- refill(app);- });}/// The query changed: when its first character moved the box to another mode, rebuild it as that mode.@@ -2764,23 +2755,8 @@ fn choose(app: &mut App, kind: PickerKind, mut picker: Picker, choice: Choice) {fill(app, &kind, &mut picker);return keep(app, kind, picker);}- PickerKind::Models => {- // (The engine's own models: only Enter switches.)- if choice != Choice::Enter { return keep(app, kind, picker) }- let Some(model) = id else { return keep(app, kind, picker) };- let Some(crate::models::Target { machine, agent, .. }) = crate::models::target(app) else { return };- let Some(link) = app.link(&machine) else { return };- let label = picker.current().map(|r| r.label.clone()).unwrap_or_default();- app.say(format!("Switching to {label}…"), theme::SOFT);- app.spawn(async move { link.rpc("agent_update", json!({ "agentId": agent, "selectedModel": model }), Duration::from_secs(60)).await }, move |app, reply| match reply {- Ok(reply) => {- if let Some(row) = reply.get("agent") { let key = (machine.clone(), row.get("id").and_then(|v| v.as_str()).unwrap_or("").to_string()); let a = crate::fleet::agent_from(&machine, row, app.fleet.agents.get(&key)); app.fleet.agents.insert(key, a); }- crate::models::close(app);- app.say(format!("✓ Now on {label}"), theme::ONLINE);- }- Err(e) => app.say(format!("Could not switch: {e}"), theme::DANGER),- });- }+ // (Every row of the Models view is its own — models.rs — so nothing else is chosen here.)+ PickerKind::Models => return keep(app, kind, picker),PickerKind::Layout => {if let Some(id) = id { app.apply_shared_preset(&id) }}diff --git a/tui/src/keys.rs b/tui/src/keys.rsindex d89768609..306a2eecd 100644--- a/tui/src/keys.rs+++ b/tui/src/keys.rs@@ -158,7 +158,7 @@ impl Keymap {b(ch('T'), "new-terminal", false, "New terminal (a shell) beside this pane");b(ch('a'), "next-harness", false, "Go to the next harness that needs you");b(ch('A'), "choose-tree -a", false, "Harnesses waiting on you — answer from the list");- b(ch('I'), "choose-tree -i", false, "Models: this harness's model and effort, local models");+ b(ch('I'), "choose-tree -i", false, "Models: subscriptions, APIs, your models, downloads, shared");b(ch('S'), "choose-tree -S", false, "The Harness Store");b(ch('g'), "command-prompt -p (send) { send-task \"%%\" }", false, "Send a task — Harness picks the harness");b(ch('B'), "command-prompt -p (broadcast) { broadcast \"%%\" }", false, "Send one message to every harness in this window");diff --git a/tui/src/modal.rs b/tui/src/modal.rsindex 0845076ed..ad762c976 100644--- a/tui/src/modal.rs+++ b/tui/src/modal.rs@@ -431,24 +431,6 @@ pub fn project_rows(app: &App) -> Vec<Row> {rows.into_iter().map(|(_, r)| r).collect()}-/// `:`, after the Models view's sections (models.rs): the focused harness's engine's own models-/// and efforts (`agent_update selectedModel`), the one it runs marked — headed by the engine, so-/// they read as its own section.-pub fn model_rows(app: &App) -> Vec<Row> {- let Some((machine, agent)) = app.focused().and_then(|f| app.panes.get(&f)).map(|p| (p.machine_id.clone(), p.agent_id.clone())) else { return vec![] };- let (current, engine) = app.fleet.agent(&machine, &agent).map(|a| (a.model.clone(), engine_label(&a.engine).to_string())).unwrap_or_default();- let list = app.models.get(&(machine, agent)).cloned().unwrap_or_default();- list.iter().filter_map(|m| {- let id = m.get("id")?.as_str()?.to_string();- let name = m.get("displayName").and_then(Value::as_str).unwrap_or(&id).to_string();- let (family, effort) = name.split_once(" / ").map(|(a, b)| (a.to_string(), b.to_string())).unwrap_or((name.clone(), String::new()));- let on = id == current;- Some(Row::new(id, name.clone()).group(format!("{engine} · {family}")).extra(effort)- .lead(vec![span(if on { "✓ " } else { " " }, fg(theme::ONLINE))])- .right(if on { "current".to_string() } else { String::new() }))- }).collect()-}-/// `?`: what the box does, one prefix per line, then every key.pub fn mode_rows(app: &App) -> Vec<Row> {let hint = |c: &str| app.keymap.hint(c).unwrap_or_default();diff --git a/tui/src/models.rs b/tui/src/models.rsindex 908e21322..3b2e1c04a 100644--- a/tui/src/models.rs+++ b/tui/src/models.rs@@ -1,6 +1,6 @@//! The Models view — `:` in the launcher, and Models… in the Commands panel: every model a harness-//! can run on, in the desktop's sections (This computer, Shared · <grid>, Subscriptions, APIs, the-//! downloads that fit this computer), each row saying what Enter does on it. Enter is **Use**: a+//! can run on, in the desktop picker's sections and order (Subscriptions, APIs, Your models, the+//! downloads that fit this computer, Shared with you), each row saying what Enter does on it. Enter is **Use**: a//! local model is downloaded, started and waited for until it serves, then the focused harness is//! moved onto it (`agent_retarget`); a shared or API model moves it at once; a subscription puts it//! back on its own login. ^S stops a local model. One local model runs at a time: Use stops the one@@ -558,14 +558,6 @@ pub fn this_computer() -> &'static str { if cfg!(target_os = "macos") { "this Mafn capital(s: &str) -> String { let mut c = s.chars(); c.next().map(|f| f.to_uppercase().collect::<String>() + c.as_str()).unwrap_or_default() }-/// `On your machines · this Mac · 64 GB memory · 120 GB free`: this computer's models, then the-/// ones the account's other machines serve.-pub fn local_heading(snap: Option<&Snapshot>) -> String {- let mut parts = vec!["On your machines".to_string(), this_computer().to_string()];- if let Some(m) = snap.and_then(|s| s.memory) { parts.push(format!("{} memory", gb(m))) }- if let Some(d) = snap.and_then(|s| s.free_disk) { parts.push(format!("{} free", gb(d))) }- parts.join(" · ")-}/// `Get for this Mac · 64 GB`: the downloads, and the memory they were chosen for.pub fn catalog_heading(snap: Option<&Snapshot>) -> String {@@ -577,11 +569,13 @@ pub fn catalog_heading(snap: Option<&Snapshot>) -> String {/// A row's size and speed in two columns that line up, then its word: `20 GB ~78 tok/s Get`.fn columns(size: &str, speed: &str, word: &str) -> String { format!("{size:>6} {speed:>9} {word:>9}") }+/// A model's second column, as the desktop's: its speed — measured while it runs, else the catalog's+/// estimate for this machine (`~`) — else the app it runs in (`Ollama`).fn speed(m: &LocalModel) -> String {match (m.running().then_some(m.tok_s).flatten(), m.est_tok_s) {(Some(s), _) => format!("{} tok/s", s.round() as u64),(None, Some(e)) => format!("~{} tok/s", e.round() as u64),- _ => String::new(),+ _ => m.app.clone().unwrap_or_default(),}}@@ -605,15 +599,16 @@ fn local_row(app: &App, m: &LocalModel, t: Option<&Target>, group: &str) -> Row// (No round marks: `✓` in use, `↻` busy, `✗` failed, `▶` running, `·` downloaded, `↓` to get.)let (dot, color) = if f.in_use { ("✓ ", theme::accent()) } else if f.active || f.pending.is_some() { ("↻ ", theme::WARN) } else if f.failed { ("✗ ", theme::DANGER) }else if m.running() { ("▶ ", theme::ONLINE) } else if m.downloaded() { ("· ", theme::SOFT) } else { ("↓ ", theme::MUTED) };+ // As the desktop's row: the name alone, then its size and speed (or the app it runs in) in+ // columns that line up, then the word — the word alone where the list is narrow. Its+ // quantization and app are in the preview, and found by a search.let quant = m.quantization().unwrap_or_default();- // (The app it runs in beside its quantization: `Q4_K_M · Ollama`.)let app_name = m.app.clone().unwrap_or_default();- let detail = [quant.as_str(), app_name.as_str()].into_iter().filter(|s| !s.is_empty()).collect::<Vec<_>>().join(" · ");Row::new(format!("mv:local:{}", m.id), m.name.clone()).group(group.to_string()).extra(format!("{} {quant} {app_name} {word} local{}", m.id, if m.recommended { " recommended" } else { "" })).lead(vec![span(dot, fg(color))])- .detail(vec![span(detail, fg(theme::MUTED))]).right(columns(&m.size.map(gb).unwrap_or_default(), &speed(m), &word))+ .right_narrow(word)}/// The word a grid model's row ends with: in use, Use, or why not.@@ -634,7 +629,7 @@ fn grid_row(app: &App, s: &Section, x: &GridModel, t: Option<&Target>, group: &s.extra(format!("{} {} {} {}", s.name, x.node, if s.own { "local" } else { "shared" }, word)).lead(vec![span(dot, fg(color))]).detail(vec![span(x.node.clone(), fg(theme::MUTED))])- .right(format!("{word:>9}"))+ .right(word)}fn sub_word(app: &App, sub: &Sub, t: Option<&Target>) -> String {@@ -645,29 +640,33 @@ fn sub_word(app: &App, sub: &Sub, t: Option<&Target>) -> String {/// Amber once the tightest window is nearly out (the desktop's low water).const LOW_WATER: f64 = 20.0;-/// The subscription the harness's own login is: its engine's — the account its machine is signed-/// in to, else one with a figure, else any.-fn subscription_for<'a>(app: &App, subs: &'a [Sub], t: &Target) -> Option<&'a Sub> {- let theirs = app.usage.get(&t.machine).and_then(|u| u.iter().find(|u| u.provider == t.engine)).map(|u| u.account.clone().unwrap_or_default());- let mine = || subs.iter().filter(|s| s.engine == t.engine);- mine().find(|s| Some(&s.account) == theirs.as_ref()).or_else(|| mine().find(|s| s.left.is_some())).or_else(|| mine().next())-}-/// A subscription's row: how much is left and whether that is running low, then Use / In use.+/// A subscription's row, as the desktop's: the account (`Anthropic 315df1`), then how much of it is+/// left (`20% remaining`) — the one figure worth a glance; Enter on it is the preview's to say. Its+/// mark says it is in use (✓) or running low (!).fn sub_row(app: &App, sub: &Sub, t: Option<&Target>, group: &str, twin: bool) -> Row {let word = sub_word(app, sub, t);let low = sub.left.is_some_and(|l| l <= LOW_WATER);- let health = match sub.left { Some(_) if low => " · Running low", Some(_) => " · Healthy", None => "" };- let label = if twin && !sub.account.is_empty() { format!("{} · {}", sub.title, sub.account) } else { sub.title.clone() };- let (dot, color) = if low { ("! ", theme::WARN) } else if word.starts_with('✓') { ("✓ ", theme::accent()) } else { ("◇ ", theme::SOFT) };+ let short: String = sub.account.chars().take(6).collect();+ let label = if twin && !short.is_empty() { format!("{} · {short}", sub.title) } else { sub.title.clone() };+ let (dot, color) = if word.starts_with('✓') { ("✓ ", if low { theme::WARN } else { theme::accent() }) } else if low { ("! ", theme::WARN) } else { ("◇ ", theme::SOFT) };+ let left = sub.left.map(|l| format!("{} remaining", left_of(100.0 - l))).unwrap_or_else(|| sub.status.clone());Row::new(format!("mv:sub:{}\t{}", sub.engine, sub.account), label).group(group.to_string()).extra(format!("{} {} subscription own login {word}", sub.engine, sub.account)).lead(vec![span(dot, fg(color))])- .detail(vec![span(if sub.account.is_empty() { String::new() } else { format!("key ···{}", sub.account) }, fg(theme::MUTED))])- .right(format!("{}{health} {word:>9}", sub.status))+ .detail(vec![span(if twin { String::new() } else { short }, fg(theme::MUTED))])+ .right(left)}-/// The rows of the Models view, in its sections. [query]: what is typed (a search lists what+/// The desktop picker's headings (`ModelSearchSection`), in its order.+const SUBSCRIPTIONS: &str = "Subscriptions";+const APIS: &str = "APIs";+const YOUR_MODELS: &str = "Your models";+const SHARED: &str = "Shared with you";++/// The rows of the Models view: the desktop picker's sections in its order (`model_search_catalog.dart`)+/// — Subscriptions, APIs, Your models, the downloads for this computer, Shared with you — drawn from+/// the top as the desktop's are (`settings::top_down`). [query]: what is typed (a search lists what/// "More models" and a folded API hide).pub fn rows(app: &App, query: &str) -> Vec<Row> {let searching = !query.trim().is_empty();@@ -678,76 +677,19 @@ pub fn rows(app: &App, query: &str) -> Vec<Row> {let snap = v.local.get(&machine);let mut out = Vec::new();- // The harness's own login first — its engine's subscription, how much of it is left, and- // whether that is running low (the reason to move it onto a model below). With no harness in- // front, every subscription.+ // Subscriptions: every account's, as the desktop lists them — how much of it is left and whether+ // that is running low; the harness's own login says it is in use.let subs = subscriptions(app);- match t {- Some(t) => out.extend(subscription_for(app, &subs, t).map(|sub| sub_row(app, sub, Some(t), "Subscription", false))),- None => out.extend(subs.iter().map(|sub| sub_row(app, sub, None, "Subscriptions", subs.iter().filter(|s| s.title == sub.title).count() > 1))),- }-- // On your machines: this computer's models — running, downloaded, being got right now — then- // the own grid's models the account's other machines serve.- let head = local_heading(snap);- if let Some(t) = t.filter(|t| v.grids.contains_key(&machine) && !can_run(app, &t.engine)) {- out.push(note("engine", &format!("{} can only run on its own login.", engine_label(&t.engine)), &head));- }- match snap {- None => out.push(note("local", if !up(app, &machine) { "Connect this computer to see its models." } else { v.local_error.get(&machine).map(String::as_str).unwrap_or("Finding models that fit…") }, &head)),- Some(s) => {- if let Some(n) = &s.notice { out.push(note("notice", n, &head)) }- // What can be used now first: one being got or started, one running here, one the own- // grid serves from another machine; then one downloaded and stopped; a grid's offline- // one last. (In the daemon's order within each.)- let rank = |m: &LocalModel| if v.op_for(&machine, m).is_some_and(Operation::active) || v.pending.as_ref().is_some_and(|p| p.1 == m.id) { 0 } else if m.running() { 1 } else if m.downloaded() { 3 } else { 5 };- let mut mine: Vec<(u8, usize, Row)> = s.models.iter().enumerate().map(|(i, m)| (rank(m), i, m)).filter(|(r, _, _)| *r < 5).map(|(r, i, m)| (r, i, local_row(app, m, t, &head))).collect();- let theirs = v.grids.get(&machine).is_some_and(|g| g.sections.iter().any(|s| s.own && !s.models.is_empty()));- if let Some(g) = v.grids.get(&machine) {- // (This computer's running ones are listed by their local names.)- let here: Vec<&LocalModel> = s.models.iter().filter(|m| m.running()).collect();- let served = g.sections.iter().filter(|s| s.own).flat_map(|s| s.models.iter().map(move |x| (s, x)))- .filter(|(_, x)| !here.iter().any(|m| x.id.eq_ignore_ascii_case(&m.id) || x.id.eq_ignore_ascii_case(&m.name)));- mine.extend(served.enumerate().map(|(i, (s, x))| (if x.offline.is_some() { 4 } else { 2 }, i, grid_row(app, s, x, t, &head))));- }- mine.sort_by_key(|(r, i, _)| (*r, *i));- if mine.is_empty() && !theirs && !searching { out.push(note("none", "No models here yet — get one below", &head)) }- out.extend(mine.into_iter().map(|(_, _, r)| r));- }- }-- if let Some(g) = v.grids.get(&machine) {- // (Without this computer's list yet, the own grid's models as they come.)- if snap.is_none() {- for s in g.sections.iter().filter(|s| s.own) { for x in &s.models { out.push(grid_row(app, s, x, t, &head)) } }- }- for s in g.sections.iter().filter(|s| !s.own) {- let words = section_words(s, v.asking.contains(&s.name));- // (A grid with no model to show is not shown — "Nobody was serving here…" says nothing- // you can use; one that is resting with models to wake keeps its "Show models".)- let asleep_empty = s.state == "asleep" && !words.offer_wake && !v.asking.contains(&s.name);- if s.models.is_empty() && (searching || asleep_empty || (words.subtitle.is_none() && words.sentence.is_none() && !words.offer_wake)) { continue }- let head = match &words.subtitle { Some(sub) => format!("Shared · {} · {sub}", s.name), None => format!("Shared · {}", s.name) };- if !searching {- if let Some(sentence) = &words.sentence { out.push(note(&format!("grid:{}", s.name), sentence, &head)) }- if words.offer_wake {- out.push(Row::new(format!("mv:wake:{}", s.name), "Show models").group(head.clone()).extra(format!("{} wake", s.name))- .lead(vec![span("↻ ", fg(theme::accent()))]).right("usually 15–40 s"));- }- }- out.extend(s.models.iter().map(|x| grid_row(app, s, x, t, &head)));- }- if !g.reachable && !searching { out.push(note("shared", "Shared models are unavailable.", "Shared")) }- }+ out.extend(subs.iter().map(|sub| sub_row(app, sub, t, SUBSCRIPTIONS, subs.iter().filter(|s| s.title == sub.title).count() > 1)));// APIs saved on this computer: each folds its models until Enter (or a search) opens it.match &v.apis {- Some(Err(why)) if !searching => out.push(note("apis", why, "APIs")),+ Some(Err(why)) if !searching => out.push(note("apis", why, APIS)),Some(Ok(apis)) => for api in apis {let listed = v.api_models.get(&api.id);let open = v.api_open.contains(&api.id) || searching;let hint = match listed { _ if !api.serves_models() => "Tools".to_string(), Some(Ok(l)) if !l.is_empty() => format!("{} model{}", l.len(), if l.len() == 1 { "" } else { "s" }), None => "Loading…".into(), _ => "Tools".into() };- out.push(Row::new(format!("mv:api:{}", api.id), api.name.clone()).group("APIs").extra(format!("{} api", api.host()))+ out.push(Row::new(format!("mv:api:{}", api.id), api.name.clone()).group(APIS).extra(format!("{} api", api.host())).lead(vec![span(if open && api.serves_models() { "▾ " } else { "▸ " }, fg(theme::MUTED))]).detail(vec![span(api.host(), fg(theme::MUTED))]).right(hint));if !open { continue }@@ -757,7 +699,7 @@ pub fn rows(app: &App, query: &str) -> Vec<Row> {_ if switching_for(app, t) == Some(m.id.as_str()) => SWITCHING.to_string(),Ok(_) => "Use".to_string(), Err(w) if w == IN_USE => "✓ In use".into(), Err(_) => String::new(),};- out.push(Row::new(format!("mv:apimodel:{}\t{}", api.id, m.id), m.id.clone()).group("APIs")+ out.push(Row::new(format!("mv:apimodel:{}\t{}", api.id, m.id), m.id.clone()).group(APIS).extra(format!("{} {} api", api.name, m.name.clone().unwrap_or_default())).lead(vec![span(" ", Style::default()), span(if word.starts_with('✓') { "✓ " } else { "· " }, fg(if word.starts_with('✓') { theme::accent() } else { theme::MUTED }))]).detail(vec![span(m.context.map(|w| format!("{} context", context_label(w))).unwrap_or_default(), fg(theme::MUTED))])@@ -768,23 +710,82 @@ pub fn rows(app: &App, query: &str) -> Vec<Row> {_ => {}}- // The downloads that fit this computer, in the daemon's order (its best for a coding agent- // first): five, then "More models".+ // Your models: this computer's — being started, running, downloaded, in the daemon's order+ // within each — then the own grid's models the account's other machines serve.+ if let Some(t) = t.filter(|t| v.grids.contains_key(&machine) && !can_run(app, &t.engine)) {+ out.push(note("engine", &format!("{} can only run on its own login.", engine_label(&t.engine)), YOUR_MODELS));+ }+ let own = |g: &Grids| -> Vec<(Section, GridModel)> {+ g.sections.iter().filter(|s| s.own).flat_map(|s| s.models.iter().map(move |x| (s.clone(), x.clone()))).collect()+ };+ match snap {+ None => {+ out.push(note("local", if !up(app, &machine) { "Connect this computer to see its models." } else { v.local_error.get(&machine).map(String::as_str).unwrap_or("Finding models that fit…") }, YOUR_MODELS));+ // (Without this computer's list yet, the own grid's models as they come.)+ if let Some(g) = v.grids.get(&machine) { for (s, x) in own(g) { out.push(grid_row(app, &s, &x, t, YOUR_MODELS)) } }+ }+ Some(s) => {+ if let Some(n) = &s.notice { out.push(note("notice", n, YOUR_MODELS)) }+ let rank = |m: &LocalModel| if v.op_for(&machine, m).is_some_and(Operation::active) || v.pending.as_ref().is_some_and(|p| p.1 == m.id) { 0 } else if m.running() { 1 } else { 2 };+ let mut mine: Vec<(u8, usize, Row)> = s.models.iter().enumerate().filter(|(_, m)| m.downloaded() || m.can_stop)+ .map(|(i, m)| (rank(m), i, local_row(app, m, t, YOUR_MODELS))).collect();+ mine.sort_by_key(|(r, i, _)| (*r, *i));+ // (This computer's running ones are listed by their local names, above.)+ let here: Vec<&LocalModel> = s.models.iter().filter(|m| m.running()).collect();+ let theirs: Vec<Row> = v.grids.get(&machine).map(own).unwrap_or_default().into_iter()+ .filter(|(_, x)| !here.iter().any(|m| x.id.eq_ignore_ascii_case(&m.id) || x.id.eq_ignore_ascii_case(&m.name)))+ .map(|(s, x)| grid_row(app, &s, &x, t, YOUR_MODELS)).collect();+ if mine.is_empty() && theirs.is_empty() && !searching { out.push(note("none", "No models here yet — get one below", YOUR_MODELS)) }+ out.extend(mine.into_iter().map(|(_, _, r)| r));+ out.extend(theirs);+ }+ }++ // The downloads that fit this computer, under `Get for this Mac · 64 GB`: one being got first,+ // then the daemon's order (its best for a coding agent first) — five, then "More models".if let Some(s) = snap {- let get: Vec<&LocalModel> = s.models.iter().filter(|m| !m.downloaded() && !v.op_for(&machine, m).is_some_and(Operation::active) && v.pending.as_ref().is_none_or(|p| p.1 != m.id)).collect();let head = catalog_heading(snap);- let shown = if v.more || searching { get.len() } else { get.len().min(SHOWN_DOWNLOADS) };- out.extend(get.iter().take(shown).map(|m| local_row(app, m, t, &head)));- if !searching && get.len() > SHOWN_DOWNLOADS {- let label = if v.more { "Show fewer".to_string() } else { format!("More models ({})", get.len() - SHOWN_DOWNLOADS) };+ let busy = |m: &LocalModel| v.op_for(&machine, m).is_some_and(Operation::active) || v.pending.as_ref().is_some_and(|p| p.1 == m.id);+ let (now, rest): (Vec<&LocalModel>, Vec<&LocalModel>) = s.models.iter().filter(|m| !m.downloaded() && !m.can_stop).partition(|m| busy(m));+ let shown = if v.more || searching { rest.len() } else { rest.len().min(SHOWN_DOWNLOADS) };+ out.extend(now.iter().chain(rest.iter().take(shown)).map(|m| local_row(app, m, t, &head)));+ if !searching && rest.len() > SHOWN_DOWNLOADS {+ let label = if v.more { "Show fewer".to_string() } else { format!("More models ({})", rest.len() - SHOWN_DOWNLOADS) };out.push(Row::new("mv:more", label).group(head).extra("more models").lead(vec![span(if v.more { "− " } else { "+ " }, fg(theme::accent()))]));}}++ // Shared with you: every grid shared with this account, one section as on the desktop — each+ // row naming the machine and the grid it is on, and a resting grid saying so.+ if let Some(g) = v.grids.get(&machine) {+ for s in g.sections.iter().filter(|s| !s.own) {+ let words = section_words(s, v.asking.contains(&s.name));+ // (A grid with no model to show is not shown — "Nobody was serving here…" says nothing+ // you can use; one that is resting with models to wake keeps its "Show models".)+ let asleep_empty = s.state == "asleep" && !words.offer_wake && !v.asking.contains(&s.name);+ if s.models.is_empty() && (searching || asleep_empty || (words.subtitle.is_none() && words.sentence.is_none() && !words.offer_wake)) { continue }+ if !searching {+ if let Some(sentence) = &words.sentence { out.push(note(&format!("grid:{}", s.name), &format!("{} · {sentence}", s.name), SHARED)) }+ if words.offer_wake {+ out.push(Row::new(format!("mv:wake:{}", s.name), format!("Show models · {}", s.name)).group(SHARED).extra(format!("{} wake", s.name))+ .lead(vec![span("↻ ", fg(theme::accent()))]).right("usually 15–40 s"));+ }+ }+ for x in &s.models {+ let detail = [x.node.as_str(), s.name.as_str(), words.subtitle.as_deref().unwrap_or("")].into_iter().filter(|w| !w.is_empty()).collect::<Vec<_>>().join(" · ");+ out.push(grid_row(app, s, x, t, SHARED).detail(vec![span(detail, fg(theme::MUTED))]));+ }+ }+ if !g.reachable && !searching { out.push(note("shared", "Shared models are unavailable.", SHARED)) }+ }+out}/// The row the harness is on now, if the view lists it: where the cursor starts.-pub fn in_use_row(rows: &[Row]) -> Option<String> { rows.iter().find(|r| is_row(&r.id) && r.right.trim_end().ends_with("✓ In use")).map(|r| r.id.clone()) }+pub fn in_use_row(rows: &[Row]) -> Option<String> {+ rows.iter().find(|r| is_row(&r.id) && (r.right.trim_end().ends_with("✓ In use") || (r.id.starts_with("mv:sub:") && r.extra.ends_with("✓ In use")))).map(|r| r.id.clone())+}// ── what Enter and ^S do ─────────────────────────────────────────────────────────@@ -1601,17 +1602,17 @@ mod tests {app.fleet.agents.insert(key, a);}- /// On your machines: what can be used now first — a model running here, then one the own grid- /// serves from another machine — then one downloaded and stopped; a grid's offline one last.+ /// Your models, as the desktop's: this computer's — running, then downloaded — then the own+ /// grid's models the account's other machines serve, in the grid's order.#[test]- fn models_ready_now_come_before_ones_not_running() {+ fn your_models_are_this_computer_s_then_the_own_grid_s() {let mut app = app();on_local(&mut app, "local", Ok(local_reply(qwen("running", Value::Null), false)));let mut g = grids_reply(&["box-model"]);g["grids"][0]["models"].as_array_mut().unwrap().push(json!({ "id": "away-model", "node": "lap", "unavailable": { "reason": "offline", "machine": "lap" } }));on_grids(&mut app, "local", Ok(g));- let mine: Vec<String> = super::rows(&app, "").into_iter().filter(|r| r.group.as_deref().is_some_and(|g| g.starts_with("On your machines")) && is_row(&r.id)).map(|r| r.id).collect();- assert_eq!(mine, vec!["mv:local:qwen-35b".to_string(), "mv:grid:own-grid\tstudio\tbox-model".into(), "mv:local:gemma-12b".into(), "mv:grid:own-grid\tlap\taway-model".into()]);+ let mine: Vec<String> = super::rows(&app, "").into_iter().filter(|r| r.group.as_deref() == Some("Your models") && is_row(&r.id)).map(|r| r.id).collect();+ assert_eq!(mine, vec!["mv:local:qwen-35b".to_string(), "mv:local:gemma-12b".into(), "mv:grid:own-grid\tstudio\tbox-model".into(), "mv:grid:own-grid\tlap\taway-model".into()]);}/// Which harness Enter moves: the focused pane's. A focused terminal is the one meant — never@@ -1691,9 +1692,11 @@ mod tests {fn the_focused_harness_moves_onto_a_local_model_and_back() {let mut app = loaded();let rows = rows(&app, "");- // The harness's own login first, running low, and it is on it.- assert_eq!(rows[0].group.as_deref(), Some("Subscription"));- assert!(rows[0].right.contains("12% left · Running low") && rows[0].right.ends_with("✓ In use"), "{}", rows[0].right);+ // The subscriptions first, as on the desktop: the harness's own login, how much is left, its+ // mark saying it is in use (amber: running low).+ assert_eq!(rows[0].group.as_deref(), Some("Subscriptions"));+ assert_eq!((rows[0].label.as_str(), rows[0].right.as_str()), ("Anthropic", "12% remaining"));+ assert_eq!(rows[0].lead[0].content, "✓ ");assert_eq!(in_use_row(&rows).as_deref(), Some("mv:sub:claude\t7f0c"));assert!(row(&rows, "mv:local:qwen-35b").right.ends_with("Get"));@@ -1752,16 +1755,17 @@ mod tests {let rows = rows_of(&app);assert!(row(&rows, "mv:local:qwen-35b").right.ends_with("✓ In use"));assert!(pane_note(&app, "local", "a1").is_none());- assert!(rows[0].right.ends_with("Use"), "its own login is a Use away: {}", rows[0].right);+ // (A subscription's row says how much is left; what Enter does is its preview's, and its mark's.)+ assert!(rows[0].extra.ends_with("Use") && rows[0].lead[0].content != "✓ ", "its own login is a Use away: {}", rows[0].extra);// And back to the subscription.let before = app.models_view.sent.len();choose(&mut app, &mut picker, "mv:sub:claude\t7f0c", false);assert_eq!(app.models_view.sent.len(), before + 1);assert_eq!(last_sent(&app), ("local".into(), "agent_retarget".into(), json!({ "agentId": "a1", "clearGrid": true })));- assert!(rows_of(&app)[0].right.ends_with(SWITCHING));+ assert!(rows_of(&app)[0].extra.ends_with(SWITCHING));frame(&mut app, json!({}));- assert!(rows_of(&app)[0].right.ends_with("✓ In use"));+ assert!(rows_of(&app)[0].extra.ends_with("✓ In use") && rows_of(&app)[0].lead[0].content == "✓ ");}fn rows_of(app: &App) -> Vec<Row> { rows(app, "") }@@ -2018,8 +2022,9 @@ mod tests {assert_eq!(next(&stopping, Some(&still), None, false, None, Instant::now() + USE_WAIT + Duration::from_secs(1)), Next::Fail("Phi is still stopping. Try again in a moment.".into()));}- /// The app a model runs in — Ollama, LM Studio, llama.cpp, or Grid's own engine — beside its- /// quantization on its row, as "Runs in" in its preview, and found by a search for it.+ /// A model's row as the desktop's: its name, then its size and speed — the catalog's estimate+ /// here (`~`), else the app it runs in (Ollama, LM Studio, llama.cpp, Grid) — then its word, the+ /// word alone in a narrow list. The app is "Runs in" in its preview, and a search finds it.#[test]fn a_model_says_the_app_it_runs_in() {let mut app = app();@@ -2029,9 +2034,11 @@ mod tests {on_local(&mut app, "local", Ok(reply));on_grids(&mut app, "local", Ok(grids_reply(&[])));let rows = rows_of(&app);- let detail = |r: &Row| r.detail.iter().map(|s| s.content.as_ref()).collect::<String>();- assert_eq!(detail(row(&rows, "mv:local:qwen-35b")), "Q4_K_M · Grid");- assert_eq!(detail(row(&rows, "mv:local:app:ollama:llama3.2:3b")), "Ollama");+ let squeezed = |r: &Row| r.right.split_whitespace().collect::<Vec<_>>().join(" ");+ assert_eq!(squeezed(row(&rows, "mv:local:qwen-35b")), "20 GB ~78 tok/s Use");+ assert_eq!(squeezed(row(&rows, "mv:local:app:ollama:llama3.2:3b")), "1.9 GB Ollama Use");+ assert!(row(&rows, "mv:local:qwen-35b").detail.iter().all(|s| s.content.is_empty()), "the name alone");+ assert_eq!(row(&rows, "mv:local:qwen-35b").right_at(40), "Use", "a narrow list: the word");assert!(text(&preview(&app, "mv:local:app:ollama:llama3.2:3b")).contains("Runs in Ollama"), "{}", text(&preview(&app, "mv:local:app:ollama:llama3.2:3b")));assert!(!text(&preview(&app, "mv:local:gemma-12b")).contains("Runs in"), "an older daemon says nothing");assert!(row(&rows, "mv:local:app:ollama:llama3.2:3b").extra.contains("Ollama"), "typing its app finds it");@@ -2062,19 +2069,22 @@ mod tests {assert_eq!(target(&app).map(|t| t.agent).as_deref(), Some("a1"));}- /// The sections, in the order the per-pane picker has them: Subscription, On your machines- /// (with this computer's memory and free disk), Shared · <grid> (a resting one offering "Show- /// models"), APIs, then five downloads and "More models (N)".+ /// The sections, in the desktop picker's order (`ModelSearchSection`): Subscriptions, APIs, Your+ /// models, the downloads under `Get for this Mac · 64 GB` (five, then "More models (N)"), Shared+ /// with you (every shared grid's rows, a resting one offering "Show models").#[test]fn rows_are_in_sections() {let mut app = loaded();+ on_apis(&mut app, Ok(json!({ "connections": [{ "id": "or", "name": "OpenRouter", "baseUrl": "https://openrouter.ai/api/v1" }], "presets": [] })));let rows = rows_of(&app);let mut groups: Vec<&str> = rows.iter().filter_map(|r| r.group.as_deref()).collect();groups.dedup();let here = this_computer();- assert_eq!(groups, vec!["Subscription".to_string(), format!("On your machines · {here} · 64 GB memory · 120 GB free"), "Shared · team".into(), "Shared · night".into(), format!("Get for {here} · 64 GB")]);+ assert_eq!(groups, vec!["Subscriptions".to_string(), "APIs".into(), "Your models".into(), format!("Get for {here} · 64 GB"), "Shared with you".into()]);assert!(row(&rows, "mv:grid:team\tlap\tmistral").right.ends_with("Offline"));- assert!(row(&rows, "mv:wake:night").label == "Show models");+ let detail = |r: &Row| r.detail.iter().map(|s| s.content.as_ref()).collect::<String>();+ assert_eq!(detail(row(&rows, "mv:grid:team\tgpu-box\tllama-70b")), "gpu-box · team", "the machine and the grid it is on");+ assert!(row(&rows, "mv:wake:night").label == "Show models · night");let downloads: Vec<&Row> = rows.iter().filter(|r| r.group.as_deref().is_some_and(|g| g.starts_with("Get for"))).collect();assert_eq!(downloads.len(), 6, "five, then More models");assert_eq!(downloads[5].label, "More models (2)");@@ -2125,7 +2135,7 @@ mod tests {let mut picker = Picker::new("models", "");choose(&mut app, &mut picker, "mv:wake:night", false);assert_eq!(last_sent(&app), ("local".into(), "grid_models_list".into(), json!({ "rowState": true, "wake": ["night"] })));- assert!(rows_of(&app).iter().any(|r| r.label == STARTING_UP_WAIT), "the wake in flight says so");+ assert!(rows_of(&app).iter().any(|r| r.label == format!("night · {STARTING_UP_WAIT}")), "the wake in flight says so");assert_eq!(plan_enter(&app, "mv:wake:night"), Plan::Say(STARTING_UP_WAIT.into()), "once, however often it is pressed");let mut waking = grids_reply(&[]);waking["grids"][2]["state"] = json!("waking");@@ -2133,7 +2143,7 @@ mod tests {assert!(app.models_view.follow_until.is_some());assert_eq!(grids_every(false, false, true), Some(Duration::from_secs(5)));let rows = rows_of(&app);- assert!(rows.iter().any(|r| r.label == STARTING_UP_WAIT && r.group.as_deref() == Some("Shared · night")));+ assert!(rows.iter().any(|r| r.label == format!("night · {STARTING_UP_WAIT}") && r.group.as_deref() == Some("Shared with you")));}#[test]@@ -2307,22 +2317,22 @@ mod tests {let Some(crate::modal::Modal::Picker { kind: crate::modal::PickerKind::Models, picker }) = &app.modal else { panic!("not open") };assert_eq!(picker.current_id().as_deref(), Some("mv:sub:claude\t7f0c"), "on the row the harness is on");let s = screen(&mut app, 150, 42);- for want in ["Models", "Subscription", "Anthropic", "12% left · Running low", "On your machines", "gemma-12b", "Shared · team", "llama-70b", "Show models"] {+ for want in ["Models", "Subscriptions", "Anthropic", "12% left · Running low", "Your models", "gemma-12b", "Shared with you", "llama-70b", "Show models"] {assert!(s.contains(want), "{want:?} missing at 150×42:\n{s}");}let at = |w: &str| s.find(w).unwrap_or(usize::MAX);- // (The launcher's lists read bottom up: the first section by the query, the rest over it,- // each heading over its rows.)- // ("Subscription" is in the preview too, higher up: the list's is the last.)- let sub = s.rfind("Subscription").unwrap_or(0);- assert!(at("Get for") < at("Shared · team") && at("Shared · team") < at("On your machines") && at("On your machines") < at("gemma-12b") && at("gemma-12b") < sub, "sections out of order:\n{s}");+ // Top to bottom as on the desktop, each heading over its rows (the launcher's lists read+ // from the bottom, so the last section is by the query).+ assert!(at("Subscriptions") < at("Your models") && at("Your models") < at("gemma-12b") && at("gemma-12b") < at("Get for")+ && at("Get for") < at("Shared with you") && at("Shared with you") < at("llama-70b"), "sections out of order:\n{s}");app.size = (80, 24);app.fit_panes();let s = screen(&mut app, 80, 24);- for want in ["Models", "Subscription", "Anthropic", "On your machines"] { assert!(s.contains(want), "{want:?} missing at 80×24:\n{s}") }- // Scrolled up (the list reads from the bottom), the downloads and More models are there.- let s = { crate::input::modal_key(&mut app, crossterm::event::KeyEvent::new(crossterm::event::KeyCode::PageUp, crossterm::event::KeyModifiers::NONE)); crate::input::modal_key(&mut app, crossterm::event::KeyEvent::new(crossterm::event::KeyCode::PageUp, crossterm::event::KeyModifiers::NONE)); screen(&mut app, 80, 24) };- assert!(s.contains("More models (2)") || s.contains("Get for"), "{s}");+ // (On the row in use, the top one: at this height the list starts at it, its heading above.)+ for want in ["Models", "Anthropic", "Your models"] { assert!(s.contains(want), "{want:?} missing at 80×24:\n{s}") }+ // Further down, the downloads and what is shared.+ let s = { crate::input::modal_key(&mut app, crossterm::event::KeyEvent::new(crossterm::event::KeyCode::PageDown, crossterm::event::KeyModifiers::NONE)); crate::input::modal_key(&mut app, crossterm::event::KeyEvent::new(crossterm::event::KeyCode::PageDown, crossterm::event::KeyModifiers::NONE)); screen(&mut app, 80, 24) };+ assert!(s.contains("Shared with you") || s.contains("llama-70b"), "{s}");// It is in the Commands panel, in the Harness group.assert!(crate::modal::command_rows(&app).iter().any(|r| r.id == "cmd:models" && r.group.as_deref() == Some("Harness")));}diff --git a/tui/src/picker.rs b/tui/src/picker.rsindex 308f28bf7..bee485c4a 100644--- a/tui/src/picker.rs+++ b/tui/src/picker.rs@@ -105,6 +105,11 @@ pub struct Picker {pub selected_id: Option<String>,/// The cursor was put on an item when the list opened (not moved by you since).pub preselected: bool,+ /// The row a list put the cursor on itself, which it may move again as rows arrive — until the+ /// cursor is somewhere else, which only a key puts it (the Models view: the row in use).+ pub placed: Option<String>,+ /// Its rows' right column may take half the list's width, not a third (the Models view's).+ pub right_half: bool,/// When the list opened (a question on it since then has only just appeared).pub opened: std::time::Instant,pub status: String,@@ -260,6 +265,8 @@ impl Picker {cursor: 0,selected_id: None,preselected: false,+ placed: None,+ right_half: false,opened: std::time::Instant::now(),status: String::new(),hints: Vec::new(),diff --git a/tui/src/settings.rs b/tui/src/settings.rsindex ee24c8248..9daa9ef09 100644--- a/tui/src/settings.rs+++ b/tui/src/settings.rs@@ -27,9 +27,10 @@ pub fn is_panel(kind: &PickerKind) -> bool {/// Whether [kind]'s list reads top-down (↑ toward its first row): fzf's under --layout=reverse,/// and the panel's menus; the launcher's lists read bottom-up in the panel too, their query-/// under them, as fzf's do.+/// under them, as fzf's do — except Models, which reads from the top as the desktop's picker does+/// (its sections in the desktop's order, and no blank space over a short list).pub fn top_down(kind: &PickerKind) -> bool {- if is_panel(kind) { !crate::modal::is_launcher(kind) } else { theme::fzf().reverse }+ if is_panel(kind) { !crate::modal::is_launcher(kind) || matches!(kind, PickerKind::Models) } else { theme::fzf().reverse }}/// Step into [section]: its options in the same list, the cursor on the one in use.@@ -509,8 +510,10 @@ pub fn draw(buf: &mut Buffer, app: &App, body: Rect, kind: &PickerKind, picker:let side = inner_w >= 64 && kind.size() == PanelSize::Large && (settings || (picker.preview && !matches!(kind, PickerKind::Commands | PickerKind::Theme)));// (A list's preview gets at least half: a harness's screen, a machine's, a model's facts —// the list room for a row's name and what it says, a harness's doing.)- let list_w = if !side { inner_w } else if settings { (inner_w * 2 / 5).clamp(28, 40) } else { (inner_w / 2).clamp(30, 56) };- list_from(buf, picker, Rect::new(x, top, list_w, rows as u16), &c, !side, launcher);+ // (Models: a model's name, its size and speed, and its word side by side, as the desktop's rows.)+ let widest = if matches!(kind, PickerKind::Models) { 72 } else { 56 };+ let list_w = if !side { inner_w } else if settings { (inner_w * 2 / 5).clamp(28, 40) } else { (inner_w / 2).clamp(30, widest) };+ list_from(buf, picker, Rect::new(x, top, list_w, rows as u16), &c, !side, !top_down(kind));picker.preview_area.set(None);picker.bar.set(None);let mut shown = None;@@ -664,9 +667,10 @@ pub fn list_from(buf: &mut Buffer, picker: &mut Picker, r: Rect, c: &Chrome, det}// The right column as the row has it for this width (its short form in a narrow list:// a harness's age, not its project and machine), and never more than a third of the- // row — so it can not run off the panel or over the name.+ // row — so it can not run off the panel or over the name. (Half, in a list that asks: the+ // Models view's size, speed and word, side by side as the desktop's rows have them.)let right_text = row.right_at(r.width as usize);- let right_w = (right_text.width() as u16).min(r.width / 3);+ let right_w = (right_text.width() as u16).min(if picker.right_half { r.width / 2 } else { r.width / 3 });// (The last column is the scroll mark's, with a blank before it.)let end = r.right().saturating_sub(if right_w > 0 { right_w + 3 } else { 2 });// The hint after the name, in a column of its own, where there is room for both.