Fix F3 context pane for unconscious agents

read_sections and draw_context now use selected_agent() which maps the
selected index to either a subconscious forked_agent or an unconscious
agent Arc. Context title uses selected_agent_name for both types.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
ProofOfConcept 2026-04-09 01:03:16 -04:00
parent dc07c92b28
commit 0d40f27098

View file

@ -149,6 +149,17 @@ impl SubconsciousScreen {
self.history_scroll = 0;
}
/// Get the agent Arc for the selected item, whether subconscious or unconscious.
fn selected_agent(&self, app: &App) -> Option<std::sync::Arc<crate::agent::Agent>> {
let idx = self.selected();
let sub_count = app.agent_state.len();
if idx < sub_count {
return app.agent_state[idx].forked_agent.clone();
}
let unc_idx = idx.checked_sub(sub_count + 1)?; // +1 for separator
app.unconscious_state.get(unc_idx)?.agent.clone()
}
fn output_sections(&self, app: &App) -> Vec<SectionView> {
let snap = match app.agent_state.get(self.selected()) {
Some(s) => s,
@ -166,16 +177,18 @@ impl SubconsciousScreen {
}
fn read_sections(&self, app: &App) -> Vec<SectionView> {
let snap = match app.agent_state.get(self.selected()) {
Some(s) => s,
let agent = match self.selected_agent(app) {
Some(a) => a,
None => return Vec::new(),
};
snap.forked_agent.as_ref()
.and_then(|agent| agent.context.try_lock().ok())
let fork_point = app.agent_state.get(self.selected())
.map(|s| s.fork_point).unwrap_or(0);
agent.context.try_lock().ok()
.map(|ctx| {
let conv = ctx.conversation();
let mut view = section_to_view("Conversation", conv);
let fork = snap.fork_point.min(view.children.len());
let fork = fork_point.min(view.children.len());
view.children = view.children.split_off(fork);
vec![view]
})
@ -350,8 +363,8 @@ impl SubconsciousScreen {
self.context_tree.render_sections(sections, &mut lines);
}
let title = app.agent_state.get(self.selected())
.map(|s| s.name.as_str())
let name = self.selected_agent_name(app);
let title = name.as_deref()
.unwrap_or("");
let mut block = pane_block_focused(title, self.focus == Pane::Context);