Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

v2.5.0 X1+X4: B6 tracing JSON mode + B7 system_health command

purpled50a124662da
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index 6e12b3eb..78e4464d 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -2425,6 +2425,12 @@ dependencies = [
"selectors 0.24.0",
]
+[[package]]
+name = "lazy_static"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
+
[[package]]
name = "leb128fmt"
version = "0.1.0"
@@ -2541,6 +2547,8 @@ dependencies = [
"tokio-tungstenite 0.26.2",
"tokio-util",
"tower-http",
+ "tracing",
+ "tracing-subscriber",
"url",
"urlencoding",
"uuid",
@@ -2629,6 +2637,15 @@ dependencies = [
"syn 2.0.117",
]
+[[package]]
+name = "matchers"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9"
+dependencies = [
+ "regex-automata",
+]
+
[[package]]
name = "matches"
version = "0.1.10"
@@ -2827,6 +2844,15 @@ dependencies = [
"winapi",
]
+[[package]]
+name = "nu-ansi-term"
+version = "0.50.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
+dependencies = [
+ "windows-sys 0.61.2",
+]
+
[[package]]
name = "num-bigint"
version = "0.4.6"
@@ -4493,6 +4519,15 @@ dependencies = [
"digest",
]
+[[package]]
+name = "sharded-slab"
+version = "0.1.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
+dependencies = [
+ "lazy_static",
+]
+
[[package]]
name = "shared_child"
version = "1.1.1"
@@ -5260,6 +5295,15 @@ dependencies = [
"syn 2.0.117",
]
+[[package]]
+name = "thread_local"
+version = "1.1.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185"
+dependencies = [
+ "cfg-if",
+]
+
[[package]]
name = "time"
version = "0.3.47"
@@ -5577,6 +5621,49 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
dependencies = [
"once_cell",
+ "valuable",
+]
+
+[[package]]
+name = "tracing-log"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
+dependencies = [
+ "log",
+ "once_cell",
+ "tracing-core",
+]
+
+[[package]]
+name = "tracing-serde"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "704b1aeb7be0d0a84fc9828cae51dab5970fee5088f83d1dd7ee6f6246fc6ff1"
+dependencies = [
+ "serde",
+ "tracing-core",
+]
+
+[[package]]
+name = "tracing-subscriber"
+version = "0.3.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319"
+dependencies = [
+ "matchers",
+ "nu-ansi-term",
+ "once_cell",
+ "regex-automata",
+ "serde",
+ "serde_json",
+ "sharded-slab",
+ "smallvec",
+ "thread_local",
+ "tracing",
+ "tracing-core",
+ "tracing-log",
+ "tracing-serde",
]
[[package]]
@@ -5790,6 +5877,12 @@ dependencies = [
"wasm-bindgen",
]
+[[package]]
+name = "valuable"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
+
[[package]]
name = "vcpkg"
version = "0.2.15"
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index eccb3fd9..6ac35d15 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -46,6 +46,11 @@ rand = "0.8"
sha2 = "0.10"
local-ip-address = "0.6"
socket2 = "0.5"
+# Structured tracing — used for the JSON-log mode behind `LU_LOG_FORMAT=json`
+# (uselu Phase 3 parity). Default formatter is the compact text layer so
+# the existing console output stays readable for a desktop user.
+tracing = "0.1"
+tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.59", features = ["Win32_System_JobObjects", "Win32_System_Threading", "Win32_Foundation", "Win32_Security"] }
diff --git a/src-tauri/src/commands/health.rs b/src-tauri/src/commands/health.rs
new file mode 100644
index 00000000..6f8660e2
--- /dev/null
+++ b/src-tauri/src/commands/health.rs
@@ -0,0 +1,162 @@
+// B7 — system_health Tauri command. Returns a structured probe of every
+// local backend LU cares about plus a couple of host facts, so the
+// Settings → Troubleshoot panel can render an "everything in one
+// glance" diagnostic. Each probe is bounded by a short HTTP timeout and
+// classified into one of `ok` / `unreachable` / `not_installed` /
+// `error` so the UI can colour-code without re-parsing strings.
+//
+// This is intentionally a one-shot synchronous probe (300 ms per
+// backend, ~1 s total worst case) — Settings opens infrequently and a
+// long-lived background poll would be more code for less value. The
+// v2.4.5 "60s actionable ComfyUI panel" stays where it is; this is the
+// broader picture.
+
+use crate::state::AppState;
+use serde::Serialize;
+use std::time::Duration;
+use sysinfo::{Disks, System};
+use tauri::State;
+
+#[derive(Debug, Serialize)]
+#[serde(rename_all = "snake_case")]
+#[allow(dead_code)] // NotInstalled reserved for future "binary not on PATH" probes
+pub enum ProbeStatus {
+ Ok,
+ Unreachable,
+ NotInstalled,
+ Error,
+}
+
+#[derive(Debug, Serialize)]
+pub struct BackendProbe {
+ pub status: ProbeStatus,
+ /// Free-form detail (HTTP status code, error string head). Empty when ok.
+ pub detail: String,
+ /// Endpoint that was probed. Useful for the "wait, was I looking at
+ /// the wrong port?" debugging case.
+ pub endpoint: String,
+}
+
+#[derive(Debug, Serialize)]
+pub struct HostFacts {
+ pub os: String,
+ pub os_version: String,
+ pub arch: String,
+ pub cpu_count: u32,
+ /// Total physical memory, in GB rounded to 1 decimal.
+ pub ram_gb: f64,
+ /// Free disk space on the LU install drive, in GB.
+ pub disk_free_gb: f64,
+}
+
+#[derive(Debug, Serialize)]
+pub struct SystemHealthReport {
+ pub version: String,
+ pub host: HostFacts,
+ pub ollama: BackendProbe,
+ pub comfyui: BackendProbe,
+ pub lm_studio: BackendProbe,
+}
+
+fn probe_http(url: &str) -> BackendProbe {
+ let endpoint = url.to_string();
+ let client = match reqwest::blocking::Client::builder()
+ .timeout(Duration::from_millis(300))
+ .build()
+ {
+ Ok(c) => c,
+ Err(e) => {
+ return BackendProbe {
+ status: ProbeStatus::Error,
+ detail: format!("client build failed: {}", e),
+ endpoint,
+ };
+ }
+ };
+ match client.get(url).send() {
+ Ok(resp) => {
+ let code = resp.status();
+ if code.is_success() {
+ BackendProbe { status: ProbeStatus::Ok, detail: String::new(), endpoint }
+ } else {
+ BackendProbe {
+ status: ProbeStatus::Error,
+ detail: format!("HTTP {}", code.as_u16()),
+ endpoint,
+ }
+ }
+ }
+ Err(e) => {
+ // Connection-refused is the dominant "backend not running"
+ // case — we classify it as `unreachable` instead of `error`
+ // so the UI can render a friendlier hint.
+ let msg = e.to_string();
+ let head = msg.chars().take(160).collect::<String>();
+ if msg.contains("Connection refused") || msg.contains("ConnectFailed") {
+ BackendProbe { status: ProbeStatus::Unreachable, detail: head, endpoint }
+ } else {
+ BackendProbe { status: ProbeStatus::Error, detail: head, endpoint }
+ }
+ }
+ }
+}
+
+fn collect_host_facts() -> HostFacts {
+ let mut sys = System::new_all();
+ sys.refresh_memory();
+ let total_kb = sys.total_memory(); // bytes in sysinfo 0.33
+ let ram_gb = (total_kb as f64) / 1_073_741_824.0;
+ let cpu_count = num_cpus::get() as u32;
+ let os = std::env::consts::OS.to_string();
+ let os_version = System::os_version().unwrap_or_else(|| "unknown".to_string());
+ let arch = std::env::consts::ARCH.to_string();
+ // Free space on the drive that holds $HOME (or the closest mount
+ // point sysinfo reports for it). Covers the "is the model dir
+ // running out?" question without needing a separate probe.
+ let disk_free_gb = {
+ let home = dirs::home_dir().unwrap_or_else(|| std::path::PathBuf::from("."));
+ let disks = Disks::new_with_refreshed_list();
+ // Pick the longest mount-point prefix that matches HOME — that's
+ // the drive HOME actually lives on (vs. some unrelated drive
+ // sysinfo also enumerated).
+ let mut best: Option<(usize, u64)> = None;
+ for disk in disks.list() {
+ let mp = disk.mount_point();
+ if let Some(s) = mp.to_str() {
+ if home.starts_with(s) {
+ let len = s.len();
+ if best.map(|(b, _)| len > b).unwrap_or(true) {
+ best = Some((len, disk.available_space()));
+ }
+ }
+ }
+ }
+ let bytes = best.map(|(_, b)| b).unwrap_or(0);
+ (bytes as f64) / 1_073_741_824.0
+ };
+ HostFacts {
+ os,
+ os_version,
+ arch,
+ cpu_count,
+ ram_gb: (ram_gb * 10.0).round() / 10.0,
+ disk_free_gb: (disk_free_gb * 10.0).round() / 10.0,
+ }
+}
+
+#[tauri::command]
+pub async fn system_health(_state: State<'_, AppState>) -> Result<SystemHealthReport, String> {
+ // All three probes are tiny — run them serially to keep error
+ // handling readable. Total worst case is 3 × 300 ms = 900 ms.
+ let ollama = probe_http("http://127.0.0.1:11434/api/tags");
+ let comfyui = probe_http("http://127.0.0.1:8188/system_stats");
+ let lm_studio = probe_http("http://127.0.0.1:1234/v1/models");
+
+ Ok(SystemHealthReport {
+ version: env!("CARGO_PKG_VERSION").to_string(),
+ host: collect_host_facts(),
+ ollama,
+ comfyui,
+ lm_studio,
+ })
+}
diff --git a/src-tauri/src/commands/mod.rs b/src-tauri/src/commands/mod.rs
index a6b9b6e8..56d35178 100644
--- a/src-tauri/src/commands/mod.rs
+++ b/src-tauri/src/commands/mod.rs
@@ -4,6 +4,7 @@ pub mod repo_map;
pub mod claude_code;
pub mod download;
pub mod filesystem;
+pub mod health;
pub mod install;
pub mod process;
pub mod proxy;
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 9c62b7de..a9ccf268 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -36,10 +36,45 @@ fn apply_linux_webkit_workarounds() {
}
}
+/// Initialise tracing-subscriber once on app start. `LU_LOG_FORMAT=json`
+/// switches to single-line JSON output (one object per event) for users
+/// who pipe LU's stdout into Loki / Vector / a log file consumed by
+/// something machine-readable. Default is the compact text formatter
+/// because most desktop users just want a readable terminal.
+///
+/// `RUST_LOG` is honored as the filter — common values are `info`,
+/// `locally_uncensored=debug`, or a per-module spec.
+fn init_tracing() {
+ use tracing_subscriber::{fmt, prelude::*, EnvFilter};
+ // `try_init` instead of `init` so we never panic if something else
+ // (a test harness, a re-import) already set the global subscriber.
+ let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
+ let json_mode = std::env::var("LU_LOG_FORMAT")
+ .map(|v| v.eq_ignore_ascii_case("json"))
+ .unwrap_or(false);
+ if json_mode {
+ let _ = tracing_subscriber::registry()
+ .with(filter)
+ .with(fmt::layer().json().with_current_span(false).with_span_list(false))
+ .try_init();
+ } else {
+ let _ = tracing_subscriber::registry()
+ .with(filter)
+ .with(fmt::layer().compact())
+ .try_init();
+ }
+}
+
fn main() {
#[cfg(target_os = "linux")]
apply_linux_webkit_workarounds();
+ init_tracing();
+ tracing::info!(
+ version = env!("CARGO_PKG_VERSION"),
+ "Locally Uncensored starting"
+ );
+
let app_state = AppState::new();
tauri::Builder::default()
@@ -158,6 +193,8 @@ fn main() {
commands::proxy::proxy_localhost_stream,
commands::proxy::pull_model_stream,
commands::proxy::cancel_model_pull,
+ // B7 (uselu Phase 4 inspiration) — one-shot diagnostic probe
+ commands::health::system_health,
// Codex / Sprint A #2 — Repo-Map with Aider PageRank
commands::repo_map::repo_map,
// Codex / Sprint C #7 — long-running background shell tasks