bbb9a9d2f5
Cierra el último pendiente de feature: el broker ahora puede operar
bajo un contexto (test/prod/foreground/secure/etc) que activa biases
declarados en las Cards.
Schema (brahman-card):
- ContextBias { pin_to: Option<String>, priority_offset: i8 }.
- Card.priority_contexts: BTreeMap<String, ContextBias>, también en
WireCard. Las conversiones From propagan el campo.
Comportamiento (brahman-broker):
- BrokerConfig.current_context: Option<String>. Cuando es Some(ctx) y
una Card tiene priority_contexts.get(ctx), el bias aplica:
- Consumer-side: bias.pin_to sobreescribe Flow.pin_to estático.
- Producer-side: bias.priority_offset se suma a la priority base
(clamp en [Low=0, Critical=3]).
- BrokeredCard propaga priority_contexts. find_producer_for usa
effective_priority y context_bias en lugar de comparar Priority
directo.
Observabilidad:
- AdminConfig.current_context + StatusSnapshot.current_context.
- brahman-status imprime "Context: <nombre>" si está activo.
Wiring:
- ente-zero lee BRAHMAN_BROKER_CONTEXT del entorno y la propaga al
broker y al admin. Sin var, biases inactivos (back-compat total).
Tests nuevos (brahman-broker, +4):
- context_priority_offset_lifts_producer_above_alphabetic_winner:
sin contexto a-prod gana por alfabético; con context "test" b-prod
gana por offset +1.
- context_pin_to_overrides_static_pin: static pin "real-dht", test
override "mock-dht" → mock gana en context "test".
- unknown_context_no_op: biases declarados para "test" no aplican
cuando broker está en "prod".
- priority_offset_clamps_to_critical: offset enorme se clampa a 3.
Validación end-to-end manual:
$ BRAHMAN_BROKER_CONTEXT=test ente-zero &
$ brahman-status
Init: server=0.1.0 protocol=0.1.0 attached=true
Context: test
Tests acumulados: 39 (card 11, broker 15, handshake codec+transport 2 +
integ 7, card-wit 4, admin 0). cargo check --workspace: 0 errores, 0
warnings.
Con esto cierran TODOS los pendientes técnicos abiertos. El único
"pendiente" que queda es el caso real para extender (priority
contexts per-deployment, scheduling biases dinámicos, etc.).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
69 lines
2.3 KiB
Rust
69 lines
2.3 KiB
Rust
//! `brahman-status` — CLI para inspeccionar el estado del Init.
|
|
//!
|
|
//! Conecta al socket admin (default `$XDG_RUNTIME_DIR/brahman-admin.sock`,
|
|
//! override con `$BRAHMAN_ADMIN_SOCKET`), recibe el snapshot, y lo imprime.
|
|
|
|
use brahman_admin::{client, transport};
|
|
|
|
#[tokio::main(flavor = "current_thread")]
|
|
async fn main() -> anyhow::Result<()> {
|
|
let path = transport::default_socket_path();
|
|
let snap = client::query(&path).await?;
|
|
|
|
println!(
|
|
"Init: server={} protocol={} attached={}",
|
|
snap.server_version, snap.protocol_version, snap.init_attached
|
|
);
|
|
if let Some(ctx) = &snap.current_context {
|
|
println!("Context: {}", ctx);
|
|
}
|
|
println!();
|
|
println!("Sessions ({}):", snap.sessions.len());
|
|
if snap.sessions.is_empty() {
|
|
println!(" (ninguna)");
|
|
} else {
|
|
for s in &snap.sessions {
|
|
let conscious_marker = if s.wit.is_some() { " 🧠" } else { "" };
|
|
println!(
|
|
" {} {}{} lifecycle={:?} priority={:?}",
|
|
s.session, s.label, conscious_marker, s.lifecycle, s.priority
|
|
);
|
|
if let Some(wit) = &s.wit {
|
|
println!(" wit: {} / {}", wit.package, wit.world);
|
|
if !wit.imports.is_empty() {
|
|
println!(" imports: {}", wit.imports.join(", "));
|
|
}
|
|
if !wit.exports.is_empty() {
|
|
println!(" exports: {}", wit.exports.join(", "));
|
|
}
|
|
}
|
|
for f in &s.inputs {
|
|
println!(" in {}: {:?}", f.name, f.ty);
|
|
}
|
|
for f in &s.outputs {
|
|
println!(" out {}: {:?}", f.name, f.ty);
|
|
}
|
|
}
|
|
}
|
|
println!();
|
|
println!("Matches ({}):", snap.matches.len());
|
|
if snap.matches.is_empty() {
|
|
println!(" (ninguno)");
|
|
} else {
|
|
for m in &snap.matches {
|
|
let pin_marker = if m.pinned { "📌" } else { " " };
|
|
println!(
|
|
" {} {}.{} ← {}.{} via {:?}",
|
|
pin_marker,
|
|
m.consumer_label,
|
|
m.consumer.flow_name,
|
|
m.producer_label,
|
|
m.producer.flow_name,
|
|
m.via
|
|
);
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|