WIP: Rename context_new → context, delete old files, fix UI layer
Renamed context_new.rs to context.rs, deleted context_old.rs, types.rs, openai.rs, parsing.rs. Updated all imports. Rewrote user/context.rs and user/widgets.rs for new types. Stubbed working_stack tool. Killed tokenize_conv_entry. Remaining: mind/mod.rs, mind/dmn.rs, learn.rs, chat.rs, subconscious.rs, oneshot.rs. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
22146156d4
commit
bf3e2a9b73
9 changed files with 1063 additions and 1636 deletions
|
|
@ -1,8 +1,3 @@
|
|||
// context_screen.rs — F2 context/debug overlay
|
||||
//
|
||||
// Full-screen overlay showing model info, context window breakdown,
|
||||
// and runtime state. Uses SectionTree for the expand/collapse tree.
|
||||
|
||||
use ratatui::{
|
||||
layout::Rect,
|
||||
style::{Color, Style},
|
||||
|
|
@ -12,6 +7,7 @@ use ratatui::{
|
|||
|
||||
use super::{App, ScreenView, screen_legend};
|
||||
use super::widgets::{SectionTree, SectionView, section_to_view, pane_block, render_scrollable, tree_legend};
|
||||
use crate::agent::context::{AstNode, NodeBody, Ast};
|
||||
|
||||
pub(crate) struct ConsciousScreen {
|
||||
agent: std::sync::Arc<tokio::sync::Mutex<crate::agent::Agent>>,
|
||||
|
|
@ -24,8 +20,6 @@ impl ConsciousScreen {
|
|||
}
|
||||
|
||||
fn read_context_views(&self) -> Vec<SectionView> {
|
||||
use crate::agent::context::ConversationEntry;
|
||||
|
||||
let ag = match self.agent.try_lock() {
|
||||
Ok(ag) => ag,
|
||||
Err(_) => return Vec::new(),
|
||||
|
|
@ -33,28 +27,29 @@ impl ConsciousScreen {
|
|||
|
||||
let mut views: Vec<SectionView> = Vec::new();
|
||||
|
||||
// System, Identity, Journal — simple section-to-view
|
||||
views.push(section_to_view(&ag.context.system));
|
||||
views.push(section_to_view(&ag.context.identity));
|
||||
views.push(section_to_view(&ag.context.journal));
|
||||
views.push(section_to_view("System", ag.context.system()));
|
||||
views.push(section_to_view("Identity", ag.context.identity()));
|
||||
views.push(section_to_view("Journal", ag.context.journal()));
|
||||
|
||||
// Memory nodes — extracted from conversation, shown as children
|
||||
// Memory nodes extracted from conversation
|
||||
let mut mem_children: Vec<SectionView> = Vec::new();
|
||||
let mut scored = 0usize;
|
||||
let mut unscored = 0usize;
|
||||
for ce in ag.context.conversation.entries() {
|
||||
if let ConversationEntry::Memory { key, score, .. } = &ce.entry {
|
||||
let status = match score {
|
||||
Some(s) => { scored += 1; format!("score: {:.2}", s) }
|
||||
None => { unscored += 1; String::new() }
|
||||
};
|
||||
mem_children.push(SectionView {
|
||||
name: key.clone(),
|
||||
tokens: ce.tokens(),
|
||||
content: ce.entry.message().content_text().to_string(),
|
||||
children: Vec::new(),
|
||||
status,
|
||||
});
|
||||
for node in ag.context.conversation() {
|
||||
if let AstNode::Leaf(leaf) = node {
|
||||
if let NodeBody::Memory { key, score, text } = leaf.body() {
|
||||
let status = match score {
|
||||
Some(s) => { scored += 1; format!("score: {:.2}", s) }
|
||||
None => { unscored += 1; String::new() }
|
||||
};
|
||||
mem_children.push(SectionView {
|
||||
name: key.clone(),
|
||||
tokens: node.tokens(),
|
||||
content: text.clone(),
|
||||
children: Vec::new(),
|
||||
status,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if !mem_children.is_empty() {
|
||||
|
|
@ -68,9 +63,7 @@ impl ConsciousScreen {
|
|||
});
|
||||
}
|
||||
|
||||
// Conversation — each entry as a child
|
||||
views.push(section_to_view(&ag.context.conversation));
|
||||
|
||||
views.push(section_to_view("Conversation", ag.context.conversation()));
|
||||
views
|
||||
}
|
||||
}
|
||||
|
|
@ -88,7 +81,6 @@ impl ScreenView for ConsciousScreen {
|
|||
}
|
||||
}
|
||||
|
||||
// Draw
|
||||
let mut lines: Vec<Line> = Vec::new();
|
||||
let section_style = Style::default().fg(Color::Yellow);
|
||||
|
||||
|
|
@ -105,9 +97,7 @@ impl ScreenView for ConsciousScreen {
|
|||
|
||||
lines.push(Line::styled("── Context State ──", section_style));
|
||||
lines.push(Line::raw(format!(" Prompt tokens: {}K", app.status.prompt_tokens / 1000)));
|
||||
if !app.status.context_budget.is_empty() {
|
||||
lines.push(Line::raw(format!(" Budget: {}", app.status.context_budget)));
|
||||
}
|
||||
|
||||
let context_state = self.read_context_views();
|
||||
if !context_state.is_empty() {
|
||||
let total: usize = context_state.iter().map(|s| s.tokens).sum();
|
||||
|
|
|
|||
|
|
@ -8,10 +8,8 @@ use ratatui::{
|
|||
Frame,
|
||||
crossterm::event::KeyCode,
|
||||
};
|
||||
use crate::agent::context::{ContextSection, ConversationEntry};
|
||||
use crate::agent::context::{AstNode, NodeBody, Ast};
|
||||
|
||||
/// UI-only tree node for the section tree display.
|
||||
/// Built from ContextSection data; not used for budgeting.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SectionView {
|
||||
pub name: String,
|
||||
|
|
@ -22,26 +20,30 @@ pub struct SectionView {
|
|||
pub status: String,
|
||||
}
|
||||
|
||||
/// Build a SectionView tree from a ContextSection.
|
||||
/// Each entry becomes a child with label + expandable content.
|
||||
pub fn section_to_view(section: &ContextSection) -> SectionView {
|
||||
let children: Vec<SectionView> = section.entries().iter().map(|ce| {
|
||||
let content = match &ce.entry {
|
||||
ConversationEntry::Log(_) => String::new(),
|
||||
ConversationEntry::Thinking(text) => text.clone(),
|
||||
_ => ce.entry.message().content_text().to_string(),
|
||||
pub fn section_to_view(name: &str, nodes: &[AstNode]) -> SectionView {
|
||||
let children: Vec<SectionView> = nodes.iter().map(|node| {
|
||||
let content = match node.leaf().map(|l| l.body()) {
|
||||
Some(NodeBody::Log(_)) => String::new(),
|
||||
Some(body) => body.text().to_string(),
|
||||
None => node.children().iter()
|
||||
.filter_map(|c| c.leaf())
|
||||
.filter(|l| matches!(l.body(), NodeBody::Content(_)))
|
||||
.map(|l| l.body().text())
|
||||
.collect::<Vec<_>>()
|
||||
.join(""),
|
||||
};
|
||||
SectionView {
|
||||
name: ce.entry.label(),
|
||||
tokens: ce.tokens(),
|
||||
name: node.label(),
|
||||
tokens: node.tokens(),
|
||||
content,
|
||||
children: Vec::new(),
|
||||
status: String::new(),
|
||||
}
|
||||
}).collect();
|
||||
let total_tokens: usize = nodes.iter().map(|n| n.tokens()).sum();
|
||||
SectionView {
|
||||
name: section.name.clone(),
|
||||
tokens: section.tokens(),
|
||||
name: name.to_string(),
|
||||
tokens: total_tokens,
|
||||
content: String::new(),
|
||||
children,
|
||||
status: String::new(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue