5c41ef920d
Bin GPUI standalone que consulta brahman-admin cada 2s y renderea
todas las sesiones del Init como cards. Cierra el círculo visual
del ecosistema brahman.
- Crate nuevo crates/apps/nouser-explorer (deps: brahman-admin,
brahman-card, gpui).
- Ventana 900x640 con header del estado del Init, banner de error
cuando no conecta, y lista de cards (una por sesión).
- Cada card muestra: kind + label + lifecycle, ULID corto, summary
(si data), keywords, lens hint, service_socket si está, y refs
(RelationshipKind → target_label). El borde izquierdo coloreado
diferencia ente (azul) de data (lavanda).
- cx.spawn(async move |this, cx| { ... }) corre el loop de refresh
en el GPUI executor; query_blocking porque GPUI no tiene runtime
tokio.
- Helper nuevo en brahman-admin: client::query_blocking(path) —
versión sync de query(), para callers con su propio executor.
Uso:
$ ente-zero & nouser daemon crates/core &
$ cargo run -p nouser-explorer
# ventana 900x640, ~6 cards en vivo, refrescando cada 2s.
cargo check --workspace: 0 errores, 0 warnings.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
49 lines
1.5 KiB
Rust
49 lines
1.5 KiB
Rust
//! Cliente admin: lee un `StatusSnapshot` desde un socket admin.
|
|
|
|
use std::path::Path;
|
|
|
|
use thiserror::Error;
|
|
use tokio::io::{AsyncBufReadExt, BufReader};
|
|
use tokio::net::UnixStream;
|
|
|
|
use crate::snapshot::StatusSnapshot;
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum AdminError {
|
|
#[error("E/S: {0}")]
|
|
Io(#[from] std::io::Error),
|
|
#[error("respuesta vacía")]
|
|
Empty,
|
|
#[error("JSON inválido: {0}")]
|
|
Json(#[from] serde_json::Error),
|
|
}
|
|
|
|
/// Conecta al socket admin, lee la línea JSON y deserializa.
|
|
pub async fn query(path: impl AsRef<Path>) -> Result<StatusSnapshot, AdminError> {
|
|
let stream = UnixStream::connect(path).await?;
|
|
let mut reader = BufReader::new(stream);
|
|
let mut line = String::new();
|
|
let n = reader.read_line(&mut line).await?;
|
|
if n == 0 {
|
|
return Err(AdminError::Empty);
|
|
}
|
|
let snapshot = serde_json::from_str(&line)?;
|
|
Ok(snapshot)
|
|
}
|
|
|
|
/// Variante sync de [`query`] para callers que no tienen runtime tokio
|
|
/// (típicamente: GUIs con su propio executor, como GPUI).
|
|
pub fn query_blocking(path: impl AsRef<Path>) -> Result<StatusSnapshot, AdminError> {
|
|
use std::io::{BufRead, BufReader as StdBufReader};
|
|
use std::os::unix::net::UnixStream as StdUnixStream;
|
|
let stream = StdUnixStream::connect(path)?;
|
|
let mut reader = StdBufReader::new(stream);
|
|
let mut line = String::new();
|
|
let n = reader.read_line(&mut line)?;
|
|
if n == 0 {
|
|
return Err(AdminError::Empty);
|
|
}
|
|
let snapshot = serde_json::from_str(&line)?;
|
|
Ok(snapshot)
|
|
}
|