codex-mobile-bridge 0.3.14

Remote bridge and service manager for codex-mobile.
Documentation
use crate::bridge_protocol::{ThreadRenderNode, ThreadRenderSnapshot};
use crate::state::BridgeState;

fn merge_missing_exec_output(snapshot: &mut ThreadRenderSnapshot, cached: &ThreadRenderSnapshot) {
    for node in &mut snapshot.nodes {
        let ThreadRenderNode::ExecGroup {
            item_id,
            output_text,
            ..
        } = node
        else {
            continue;
        };
        if output_text
            .as_ref()
            .is_some_and(|text| !text.trim().is_empty())
        {
            continue;
        }
        *output_text = cached
            .nodes
            .iter()
            .find_map(|cached_node| match cached_node {
                ThreadRenderNode::ExecGroup {
                    item_id: cached_item_id,
                    output_text: Some(cached_output),
                    ..
                } if !cached_output.trim().is_empty()
                    && item_id.as_deref() == cached_item_id.as_deref() =>
                {
                    Some(cached_output.clone())
                }
                _ => None,
            });
    }
}

impl BridgeState {
    pub(in crate::state) fn cache_thread_render_snapshot(
        &self,
        mut snapshot: ThreadRenderSnapshot,
    ) -> ThreadRenderSnapshot {
        let mut snapshots = self
            .thread_render_snapshots
            .lock()
            .expect("thread render snapshots poisoned");
        if let Some(cached) = snapshots.get(&snapshot.thread_id) {
            merge_missing_exec_output(&mut snapshot, cached);
        }
        snapshots.insert(snapshot.thread_id.clone(), snapshot.clone());
        snapshot
    }
}