Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Split what Detect found into provider and harness tabs (#687)

Firefly5af849535404
diff --git a/crates/ai/src/lib.rs b/crates/ai/src/lib.rs
index 9b5692b4..eab52251 100644
--- a/crates/ai/src/lib.rs
+++ b/crates/ai/src/lib.rs
@@ -81,6 +81,14 @@ impl BackendKind {
}
}
+ /// A coding agent run as a program, rather than an HTTP API.
+ pub fn is_harness(self) -> bool {
+ match self {
+ BackendKind::AgentCli => true,
+ BackendKind::Anthropic | BackendKind::Openai | BackendKind::Openrouter | BackendKind::Gemini | BackendKind::OpenaiCompatible => false,
+ }
+ }
+
pub fn needs_key(self) -> bool {
matches!(self, BackendKind::Anthropic | BackendKind::Openai | BackendKind::Openrouter | BackendKind::Gemini)
}
diff --git a/crates/ui-egui/src/detect_tabs.rs b/crates/ui-egui/src/detect_tabs.rs
new file mode 100644
index 00000000..242d8456
--- /dev/null
+++ b/crates/ui-egui/src/detect_tabs.rs
@@ -0,0 +1,90 @@
+//! Splitting what Detect found into the two things a person is choosing between: an API provider
+//! (a key, billed per token) and a harness (a coding agent already installed). Without the split,
+//! eight more providers push the harnesses off the screen.
+
+use craft_anything_ai::Detected;
+
+/// Which half of the detected list is showing.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+pub enum DetectTab {
+ #[default]
+ Providers,
+ Harnesses,
+}
+
+/// The tab a found backend belongs to: an agent program is a harness, everything else answers over
+/// HTTP and is a provider (a local model server included).
+pub fn tab_of(d: &Detected) -> DetectTab {
+ if d.suggestion.kind.is_harness() { DetectTab::Harnesses } else { DetectTab::Providers }
+}
+
+/// How many of each were found, for the tab labels.
+pub fn counts(detected: &[Detected]) -> (usize, usize) {
+ detected.iter().fold((0, 0), |(p, h), d| match tab_of(d) {
+ DetectTab::Providers => (p + 1, h),
+ DetectTab::Harnesses => (p, h + 1),
+ })
+}
+
+/// Which tab to show. A tab the person clicked stays, even when it is empty: that is how its "nothing
+/// of this kind was found" line is read. Only the automatic first choice prefers the tab that has
+/// something, so adding the only provider never opens on an empty screen.
+pub fn resolve(chosen: Option<DetectTab>, providers: usize, harnesses: usize) -> DetectTab {
+ match chosen {
+ Some(tab) => tab,
+ None if providers == 0 && harnesses > 0 => DetectTab::Harnesses,
+ None => DetectTab::Providers,
+ }
+}
+
+/// Draw the two tabs and return the one that is showing. An empty tab is dimmed, not disabled: it
+/// still opens, and says what is missing.
+pub fn bar(ui: &mut egui::Ui, chosen: &mut Option<DetectTab>, detected: &[Detected]) -> DetectTab {
+ let (providers, harnesses) = counts(detected);
+ let showing = resolve(*chosen, providers, harnesses);
+ ui.horizontal_wrapped(|ui| {
+ for (tab, label, count) in [(DetectTab::Providers, "Providers", providers), (DetectTab::Harnesses, "Harnesses", harnesses)] {
+ let mut text = egui::RichText::new(format!("{} ({count})", crate::i18n::tr(label)));
+ if count == 0 {
+ text = text.weak();
+ }
+ if ui.selectable_label(showing == tab, text).clicked() {
+ *chosen = Some(tab);
+ }
+ }
+ });
+ showing
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use craft_anything_ai::{BackendConfig, BackendKind, Detected};
+
+ fn detected(kind: BackendKind) -> Detected {
+ let suggestion = BackendConfig { name: "X".into(), kind, model: "m".into(), base_url: None, ssh_host: None, enabled: true };
+ Detected { suggestion, reason: String::new(), needs_key: false }
+ }
+
+ /// An agent app is a harness; an API backend and a local server are providers.
+ #[test]
+ fn the_two_kinds_land_on_their_own_tab() {
+ assert_eq!(tab_of(&detected(BackendKind::AgentCli)), DetectTab::Harnesses);
+ assert_eq!(tab_of(&detected(BackendKind::Openai)), DetectTab::Providers);
+ assert_eq!(tab_of(&detected(BackendKind::OpenaiCompatible)), DetectTab::Providers);
+ let all = [detected(BackendKind::AgentCli), detected(BackendKind::Anthropic), detected(BackendKind::Gemini)];
+ assert_eq!(counts(&all), (2, 1));
+ }
+
+ /// The first choice prefers the tab with something; a click is always honoured, so an empty tab
+ /// can show what it is missing.
+ #[test]
+ fn the_default_gives_way_but_a_click_does_not() {
+ assert_eq!(resolve(None, 0, 3), DetectTab::Harnesses, "only harnesses were found");
+ assert_eq!(resolve(None, 2, 0), DetectTab::Providers);
+ assert_eq!(resolve(None, 0, 0), DetectTab::Providers, "nothing at all: the first tab");
+ assert_eq!(resolve(Some(DetectTab::Harnesses), 2, 0), DetectTab::Harnesses, "a clicked empty tab stays");
+ assert_eq!(resolve(Some(DetectTab::Providers), 0, 3), DetectTab::Providers, "a clicked empty tab stays");
+ assert_eq!(resolve(Some(DetectTab::Harnesses), 2, 3), DetectTab::Harnesses);
+ }
+}
diff --git a/crates/ui-egui/src/first_run.rs b/crates/ui-egui/src/first_run.rs
index abbd3617..fc680b62 100644
--- a/crates/ui-egui/src/first_run.rs
+++ b/crates/ui-egui/src/first_run.rs
@@ -120,6 +120,7 @@ fn brain(app: &mut CraftApp, ui: &mut Ui, width: f32) {
}
ui.add_space(10.0);
let detected: Vec<Detected> = app.detected.clone().unwrap_or_default();
+ let tab = crate::detect_tabs::bar(ui, &mut app.state.detect_tab, &detected);
let list_h = (ui.ctx().content_rect().height() - 330.0).clamp(220.0, 520.0);
egui::ScrollArea::vertical().max_height(list_h).show(ui, |ui| {
ui.set_width(width);
@@ -130,9 +131,15 @@ fn brain(app: &mut CraftApp, ui: &mut Ui, width: f32) {
});
ui.add_space(8.0);
}
- for d in &detected {
+ ui.add_space(4.0);
+ let mut shown = 0;
+ for d in detected.iter().filter(|d| crate::detect_tabs::tab_of(d) == tab) {
brain_card(app, ui, d);
ui.add_space(8.0);
+ shown += 1;
+ }
+ if !app.detecting && shown == 0 && !detected.is_empty() {
+ ui.label(RichText::new(tr("Nothing of this kind was found.")).color(t.text_faint));
}
if !app.detecting && detected.is_empty() {
widgets::card(&t).show(ui, |ui| {
diff --git a/crates/ui-egui/src/fr.tsv b/crates/ui-egui/src/fr.tsv
index 2c6815b7..a87b641a 100644
--- a/crates/ui-egui/src/fr.tsv
+++ b/crates/ui-egui/src/fr.tsv
@@ -848,3 +848,6 @@ Log Journal
Hide the console Masquer la console
No jobs yet. Long tasks show their progress here, and you can cancel them. Aucune tâche pour l'instant. Les longues tâches affichent ici leur progression, et vous pouvez les annuler.
Clear finished Effacer les terminées
+Providers Fournisseurs
+Harnesses Agents
+Nothing of this kind was found. Rien de ce type n'a été trouvé.
diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv
index 8b5f41ef..c66d8c21 100644
--- a/crates/ui-egui/src/i18n/cs.tsv
+++ b/crates/ui-egui/src/i18n/cs.tsv
@@ -1408,3 +1408,6 @@ your files there are the app, edited in place vaše soubory ve složce jsou apli
… {} older … starší: {}
← Back ← Zpět
↑↓ to move · Enter to run · Esc to close ↑↓ pro pohyb · Enter pro spuštění · Esc pro zavření
+Providers Poskytovatelé
+Harnesses Agenti
+Nothing of this kind was found. Nic takového nebylo nalezeno.
diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv
index e2340792..55925b4b 100644
--- a/crates/ui-egui/src/i18n/de.tsv
+++ b/crates/ui-egui/src/i18n/de.tsv
@@ -1408,3 +1408,6 @@ your files there are the app, edited in place deine Dateien dort sind die App, d
… {} older … {} ältere
← Back ← Zurück
↑↓ to move · Enter to run · Esc to close ↑↓ zum Bewegen · Enter zum Ausführen · Esc zum Schließen
+Providers Anbieter
+Harnesses Agenten
+Nothing of this kind was found. Nichts dieser Art wurde gefunden.
diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv
index 6d15100a..da80e40e 100644
--- a/crates/ui-egui/src/i18n/ko.tsv
+++ b/crates/ui-egui/src/i18n/ko.tsv
@@ -1408,3 +1408,6 @@ your files there are the app, edited in place 그 파일이 곧 앱이며 그
… {} older … 이전 항목 {}개
← Back ← 뒤로
↑↓ to move · Enter to run · Esc to close ↑↓ 이동 · Enter 실행 · Esc 닫기
+Providers 제공자
+Harnesses 에이전트
+Nothing of this kind was found. 이런 종류는 찾지 못했습니다.
diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv
index 03d15c5a..ecbd1212 100644
--- a/crates/ui-egui/src/i18n/ru.tsv
+++ b/crates/ui-egui/src/i18n/ru.tsv
@@ -1408,3 +1408,6 @@ your files there are the app, edited in place ваши файлы там — э
… {} older … {} старых
← Back ← Назад
↑↓ to move · Enter to run · Esc to close ↑↓ для перемещения · Enter для запуска · Esc для закрытия
+Providers Провайдеры
+Harnesses Агенты
+Nothing of this kind was found. Ничего такого не найдено.
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index 7cf638f6..f362a799 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -1408,3 +1408,6 @@ your files there are the app, edited in place 该位置的文件就是应用,
… {} older … 还有 {} 条较早内容
← Back ← 返回
↑↓ to move · Enter to run · Esc to close ↑↓ 选择 · Enter 运行 · Esc 关闭
+Providers 提供商
+Harnesses 代理
+Nothing of this kind was found. 没有找到这类项目。
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index 21ed23b9..26fc80ba 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -1408,3 +1408,6 @@ your files there are the app, edited in place 該位置的檔案就是應用程
… {} older … 還有 {} 則較早內容
← Back ← 返回
↑↓ to move · Enter to run · Esc to close ↑↓ 選擇 · Enter 執行 · Esc 關閉
+Providers 供應商
+Harnesses 代理
+Nothing of this kind was found. 沒有找到這類項目。
diff --git a/crates/ui-egui/src/ja.tsv b/crates/ui-egui/src/ja.tsv
index 83435faa..77eb4193 100644
--- a/crates/ui-egui/src/ja.tsv
+++ b/crates/ui-egui/src/ja.tsv
@@ -850,3 +850,6 @@ your files there are the app, edited in place そこにあるファイルがア
— use the filter to find the rest. — 残りは絞り込みで探してください。
← Back ← 戻る
↑↓ to move · Enter to run · Esc to close ↑↓ で移動 · Enter で実行 · Esc で閉じる
+Providers プロバイダ
+Harnesses ハーネス
+Nothing of this kind was found. この種類のものは見つかりませんでした。
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 5d894e29..577446f7 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -10,6 +10,7 @@
pub mod builders;
pub mod chat;
pub mod demo;
+pub mod detect_tabs;
pub mod engine_ui;
pub mod evidence_ui;
pub mod first_run;
diff --git a/crates/ui-egui/src/settings_ui.rs b/crates/ui-egui/src/settings_ui.rs
index da6e5e4b..7d9850b2 100644
--- a/crates/ui-egui/src/settings_ui.rs
+++ b/crates/ui-egui/src/settings_ui.rs
@@ -609,8 +609,15 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
app.set_role(craft_anything_ai::Role::Extractor, e);
}
ui.add_space(8.0);
+ let detected = app.detected.clone().unwrap_or_default();
+ let mut tab = {
+ let (providers, harnesses) = crate::detect_tabs::counts(&detected);
+ crate::detect_tabs::resolve(app.state.detect_tab, providers, harnesses)
+ };
ui.horizontal(|ui| {
widgets::caption(ui, "Found on this computer");
+ ui.add_space(12.0);
+ tab = crate::detect_tabs::bar(ui, &mut app.state.detect_tab, &detected);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if app.detecting {
ui.add(crate::widgets::Spinner::new().color(t.accent));
@@ -620,14 +627,17 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
});
});
ui.add_space(4.0);
- let detected = app.detected.clone().unwrap_or_default();
if detected.is_empty() && !app.detecting {
ui.label(
RichText::new(tr("Nothing found yet. We look for API keys, local model servers (Ollama, LM Studio) and agent apps you already have. One on another port or computer can be added by its address below."))
.color(t.text_faint),
);
}
- for d in detected {
+ let shown = detected.iter().filter(|d| crate::detect_tabs::tab_of(d) == tab).count();
+ if shown == 0 && !detected.is_empty() && !app.detecting {
+ ui.label(RichText::new(tr("Nothing of this kind was found.")).color(t.text_faint));
+ }
+ for d in detected.into_iter().filter(|d| crate::detect_tabs::tab_of(d) == tab) {
let configured = app.backends.iter().any(|b| b.name == d.suggestion.name);
widgets::panel(&t).show(ui, |ui| {
ui.set_width(ui.available_width());
diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs
index a154abfd..c5bc3a73 100644
--- a/crates/ui-egui/src/state.rs
+++ b/crates/ui-egui/src/state.rs
@@ -401,6 +401,9 @@ pub struct PaletteState {
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct UiState {
+ /// Which half of Detect's findings is showing (a view choice, not part of the project).
+ #[serde(skip)]
+ pub detect_tab: Option<crate::detect_tabs::DetectTab>,
pub screen: Screen,
pub first_run: FirstRunStep,
pub purpose: Purpose,
@@ -530,6 +533,7 @@ impl PluginForm {
impl Default for UiState {
fn default() -> Self {
UiState {
+ detect_tab: None,
screen: Screen::Home,
first_run: FirstRunStep::Welcome,
purpose: Purpose::OwnOrAuthorized,