Read Bifrost bridge readiness in status

This commit is contained in:
Meta Vens 2026-06-22 17:15:52 +01:00
commit de7424d310
5 changed files with 144 additions and 1 deletions

View file

@ -528,6 +528,7 @@ fn run_native_status(args: &Args) -> Result<Value> {
"tools": tool_invocations,
"heartbeat": native_aux.heartbeat,
"persona": native_aux.persona,
"bifrostBridge": native_aux.bifrost_bridge,
"voidMemory": native_aux.void_memory,
});
Ok(sanitize_for_operator(status))
@ -644,6 +645,7 @@ fn run_codex_status(args: &Args) -> Result<Value> {
"tools": tool_invocations,
"heartbeat": native_aux.heartbeat,
"persona": native_aux.persona,
"bifrostBridge": native_aux.bifrost_bridge,
"voidMemory": native_aux.void_memory,
});
Ok(sanitize_for_operator(status))
@ -652,6 +654,7 @@ fn run_codex_status(args: &Args) -> Result<Value> {
struct NativeAuxiliaryStatus {
heartbeat: Value,
persona: Value,
bifrost_bridge: Value,
void_memory: Value,
}
@ -734,6 +737,7 @@ fn native_auxiliary_status(root: &Path) -> Result<NativeAuxiliaryStatus> {
"latestArtifacts": latest_artifacts,
"availableActions": ["personaBubble", "characterTurn", "discordPersonaPost", "redditPersonaPost", "otherWorldPersonaRequest"],
});
let bifrost_bridge = bifrost_bridge_readiness(root);
let void_memory = native_json(
"epiphany-void-memory",
&["status", "--config", "state/void-memory.toml"],
@ -743,10 +747,112 @@ fn native_auxiliary_status(root: &Path) -> Result<NativeAuxiliaryStatus> {
Ok(NativeAuxiliaryStatus {
heartbeat,
persona,
bifrost_bridge,
void_memory,
})
}
fn bifrost_bridge_readiness(root: &Path) -> Value {
let bifrost_root = root
.parent()
.map(|parent| parent.join("Bifrost"))
.unwrap_or_else(|| root.join("../Bifrost"));
let advertisement_tool = bifrost_root.join("tools").join("provider-advertisement.mjs");
if !advertisement_tool.exists() {
return json!({
"status": "unavailable",
"owner": "Bifrost",
"tool": advertisement_tool,
"note": "Bifrost provider advertisement tool was not found; Epiphany cannot infer outside-world bridge readiness locally.",
"privateStateExposed": false,
});
}
let output = Command::new("node")
.arg(&advertisement_tool)
.arg("print-surface")
.current_dir(&bifrost_root)
.output();
let Ok(output) = output else {
return json!({
"status": "unavailable",
"owner": "Bifrost",
"tool": advertisement_tool,
"note": "Failed to invoke Bifrost provider advertisement tool.",
"privateStateExposed": false,
});
};
if !output.status.success() {
return json!({
"status": "unavailable",
"owner": "Bifrost",
"tool": advertisement_tool,
"note": format!("Bifrost provider advertisement failed: {}", String::from_utf8_lossy(&output.stderr)),
"privateStateExposed": false,
});
}
let parsed: Value = match serde_json::from_slice(&output.stdout) {
Ok(value) => value,
Err(error) => {
return json!({
"status": "unavailable",
"owner": "Bifrost",
"tool": advertisement_tool,
"note": format!("Bifrost provider advertisement returned invalid JSON: {error}"),
"privateStateExposed": false,
});
}
};
let bridge = &parsed["stats"]["bridge"];
let surfaces = bridge["surfaces"]
.as_array()
.cloned()
.unwrap_or_default()
.into_iter()
.map(|surface| {
let ready = surface["ready"].as_bool().unwrap_or(false);
let prepared = surface["prepared"].as_bool().unwrap_or(false);
json!({
"id": surface["id"].clone(),
"label": surface["label"].clone(),
"status": if ready { "live" } else if prepared { "prepared" } else { "missing" },
"ready": ready,
"prepared": prepared,
"authority": surface["authority"].clone(),
"credentialSource": surface["credentialSource"].clone(),
"note": surface["note"].clone(),
})
})
.collect::<Vec<_>>();
let ready_count = surfaces
.iter()
.filter(|surface| surface["ready"].as_bool().unwrap_or(false))
.count();
let prepared_count = surfaces
.iter()
.filter(|surface| {
surface["prepared"].as_bool().unwrap_or(false)
&& !surface["ready"].as_bool().unwrap_or(false)
})
.count();
json!({
"status": if bridge["ready"].as_bool().unwrap_or(false) { "live" } else if bridge["prepared"].as_bool().unwrap_or(false) { "prepared" } else { "unavailable" },
"owner": "Bifrost",
"authority": "Bifrost owns outside-world crossing gates, bridge receipts, and readiness projection; Heimdall owns provider OAuth, account links, and capability truth; Epiphany consumes this as read-only bridge sight.",
"source": "Bifrost provider advertisement print-surface",
"tool": advertisement_tool,
"generatedAt": parsed["stats"]["generatedAt"].clone(),
"ready": bridge["ready"].clone(),
"prepared": bridge["prepared"].clone(),
"readySurfaceCount": ready_count,
"preparedSurfaceCount": prepared_count,
"surfaceCount": surfaces.len(),
"surfaces": surfaces,
"privateStateExposed": false,
})
}
fn native_role_result(
state: Option<&EpiphanyThreadState>,
runtime_store: &Path,
@ -1413,6 +1519,7 @@ pub fn render_status(status: &Value) -> String {
let coordinator = &status["coordinator"];
let heartbeat = &status["heartbeat"];
let persona = &status["persona"];
let bifrost_bridge = &status["bifrostBridge"];
let planning_response = &status["planning"];
let planning_summary = &planning_response["summary"];
let checkpoint = &scene["investigationCheckpoint"];
@ -1488,6 +1595,16 @@ pub fn render_status(status: &Value) -> String {
"- latest content: {}",
maybe(&latest_persona["content"], "none")
),
format!(
"- Bifrost bridge: {} ({}/{})",
maybe(&bifrost_bridge["status"], "unavailable"),
maybe(&bifrost_bridge["readySurfaceCount"], "0"),
maybe(&bifrost_bridge["surfaceCount"], "0")
),
format!(
"- bridge surfaces: {}",
bifrost_bridge_surface_text(bifrost_bridge)
),
String::new(),
"Planning".to_string(),
format!(
@ -1794,3 +1911,23 @@ fn list_text(value: &Value, fallback: &str) -> String {
}
items.iter().map(text).collect::<Vec<_>>().join(", ")
}
fn bifrost_bridge_surface_text(value: &Value) -> String {
let Some(items) = value["surfaces"].as_array() else {
return "none".to_string();
};
if items.is_empty() {
return "none".to_string();
}
items
.iter()
.map(|surface| {
format!(
"{}={}",
maybe(&surface["id"], "unknown"),
maybe(&surface["status"], "unknown")
)
})
.collect::<Vec<_>>()
.join(", ")
}