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:
parent
dc07c92b28
commit
0d40f27098
1 changed files with 20 additions and 7 deletions
|
|
@ -149,6 +149,17 @@ impl SubconsciousScreen {
|
||||||
self.history_scroll = 0;
|
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> {
|
fn output_sections(&self, app: &App) -> Vec<SectionView> {
|
||||||
let snap = match app.agent_state.get(self.selected()) {
|
let snap = match app.agent_state.get(self.selected()) {
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
|
|
@ -166,16 +177,18 @@ impl SubconsciousScreen {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_sections(&self, app: &App) -> Vec<SectionView> {
|
fn read_sections(&self, app: &App) -> Vec<SectionView> {
|
||||||
let snap = match app.agent_state.get(self.selected()) {
|
let agent = match self.selected_agent(app) {
|
||||||
Some(s) => s,
|
Some(a) => a,
|
||||||
None => return Vec::new(),
|
None => return Vec::new(),
|
||||||
};
|
};
|
||||||
snap.forked_agent.as_ref()
|
let fork_point = app.agent_state.get(self.selected())
|
||||||
.and_then(|agent| agent.context.try_lock().ok())
|
.map(|s| s.fork_point).unwrap_or(0);
|
||||||
|
|
||||||
|
agent.context.try_lock().ok()
|
||||||
.map(|ctx| {
|
.map(|ctx| {
|
||||||
let conv = ctx.conversation();
|
let conv = ctx.conversation();
|
||||||
let mut view = section_to_view("Conversation", conv);
|
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);
|
view.children = view.children.split_off(fork);
|
||||||
vec![view]
|
vec![view]
|
||||||
})
|
})
|
||||||
|
|
@ -350,8 +363,8 @@ impl SubconsciousScreen {
|
||||||
self.context_tree.render_sections(sections, &mut lines);
|
self.context_tree.render_sections(sections, &mut lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
let title = app.agent_state.get(self.selected())
|
let name = self.selected_agent_name(app);
|
||||||
.map(|s| s.name.as_str())
|
let title = name.as_deref()
|
||||||
.unwrap_or("—");
|
.unwrap_or("—");
|
||||||
|
|
||||||
let mut block = pane_block_focused(title, self.focus == Pane::Context);
|
let mut block = pane_block_focused(title, self.focus == Pane::Context);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue