Delete ui_channel.rs — relocate types, remove all UiMessage/UiSender plumbing
Types relocated: - StreamTarget → mind/mod.rs (Mind decides Conversation vs Autonomous) - SharedActiveTools + shared_active_tools() → agent/tools/mod.rs - ContextSection + SharedContextState → agent/context.rs (already there) - StatusInfo + ContextInfo → user/mod.rs (UI display state) Removed UiSender from: Agent::turn, Mind, learn.rs, all function signatures. The entire message-passing layer is gone. All state flows through Agent fields (activities, entries, streaming) read by the UI via try_lock. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
cfddb55ed9
commit
f390fa1617
11 changed files with 72 additions and 165 deletions
|
|
@ -28,7 +28,8 @@ use context::{ConversationEntry, ContextState, ContextBudget};
|
|||
use tools::{summarize_args, working_stack};
|
||||
|
||||
use crate::mind::log::ConversationLog;
|
||||
use crate::user::ui_channel::{ContextSection, SharedContextState, StreamTarget, UiSender};
|
||||
use crate::agent::context::{ContextSection, SharedContextState};
|
||||
use crate::mind::StreamTarget;
|
||||
use crate::subconscious::learn;
|
||||
|
||||
// --- Activity tracking (RAII guards) ---
|
||||
|
|
@ -177,7 +178,7 @@ pub struct Agent {
|
|||
/// TODO: move to Session — it's session-level, not agent-level.
|
||||
pub agent_cycles: crate::subconscious::subconscious::AgentCycleState,
|
||||
/// Shared active tools — Agent writes, TUI reads.
|
||||
pub active_tools: crate::user::ui_channel::SharedActiveTools,
|
||||
pub active_tools: crate::agent::tools::SharedActiveTools,
|
||||
}
|
||||
|
||||
fn render_journal(entries: &[context::JournalEntry]) -> String {
|
||||
|
|
@ -199,7 +200,7 @@ impl Agent {
|
|||
prompt_file: String,
|
||||
conversation_log: Option<ConversationLog>,
|
||||
shared_context: SharedContextState,
|
||||
active_tools: crate::user::ui_channel::SharedActiveTools,
|
||||
active_tools: tools::SharedActiveTools,
|
||||
) -> Self {
|
||||
let tokenizer = tiktoken_rs::cl100k_base()
|
||||
.expect("failed to load cl100k_base tokenizer");
|
||||
|
|
@ -325,7 +326,6 @@ impl Agent {
|
|||
pub async fn turn(
|
||||
agent: Arc<tokio::sync::Mutex<Agent>>,
|
||||
user_input: &str,
|
||||
ui_tx: &UiSender,
|
||||
target: StreamTarget,
|
||||
) -> Result<TurnResult> {
|
||||
// --- Pre-loop setup (lock 1): agent cycle, memories, user input ---
|
||||
|
|
@ -382,7 +382,7 @@ impl Agent {
|
|||
let mut me = agent.lock().await;
|
||||
let mut bg_ds = DispatchState::new();
|
||||
for (call, output) in bg_results {
|
||||
me.apply_tool_result(&call, output, ui_tx, &mut bg_ds);
|
||||
me.apply_tool_result(&call, output, &mut bg_ds);
|
||||
}
|
||||
me.push_message(Message::user(user_input));
|
||||
}
|
||||
|
|
@ -408,7 +408,6 @@ impl Agent {
|
|||
me.client.start_stream(
|
||||
&api_messages,
|
||||
&me.tools,
|
||||
ui_tx,
|
||||
&me.reasoning_effort,
|
||||
sampling,
|
||||
None,
|
||||
|
|
@ -522,7 +521,7 @@ impl Agent {
|
|||
// Reacquire to apply results
|
||||
let mut me = agent.lock().await;
|
||||
for (call, output) in results {
|
||||
me.apply_tool_result(&call, output, ui_tx, &mut ds);
|
||||
me.apply_tool_result(&call, output, &mut ds);
|
||||
}
|
||||
me.publish_context_state();
|
||||
continue;
|
||||
|
|
@ -536,7 +535,7 @@ impl Agent {
|
|||
// Drop lock before tool dispatch
|
||||
for call in &calls {
|
||||
Agent::dispatch_tool_call_unlocked(
|
||||
&agent, &active_tools, call, ui_tx, &mut ds,
|
||||
&agent, &active_tools, call, &mut ds,
|
||||
).await;
|
||||
}
|
||||
continue;
|
||||
|
|
@ -568,9 +567,8 @@ impl Agent {
|
|||
/// Used by `turn()` which manages its own locking.
|
||||
async fn dispatch_tool_call_unlocked(
|
||||
agent: &Arc<tokio::sync::Mutex<Agent>>,
|
||||
active_tools: &crate::user::ui_channel::SharedActiveTools,
|
||||
active_tools: &crate::agent::tools::SharedActiveTools,
|
||||
call: &ToolCall,
|
||||
ui_tx: &UiSender,
|
||||
ds: &mut DispatchState,
|
||||
) {
|
||||
let args: serde_json::Value = match serde_json::from_str(&call.function.arguments) {
|
||||
|
|
@ -579,7 +577,7 @@ impl Agent {
|
|||
let err = format!("Error: malformed tool call arguments: {e}");
|
||||
let _act = start_activity(agent, format!("rejected: {} (bad args)", call.function.name)).await;
|
||||
let mut me = agent.lock().await;
|
||||
me.apply_tool_result(call, err, ui_tx, ds);
|
||||
me.apply_tool_result(call, err, ds);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
|
@ -613,7 +611,7 @@ impl Agent {
|
|||
if let Ok((call, output)) = entry.handle.await {
|
||||
// Brief lock to apply result
|
||||
let mut me = agent.lock().await;
|
||||
me.apply_tool_result(&call, output, ui_tx, ds);
|
||||
me.apply_tool_result(&call, output, ds);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -622,7 +620,6 @@ impl Agent {
|
|||
&mut self,
|
||||
call: &ToolCall,
|
||||
output: String,
|
||||
ui_tx: &UiSender,
|
||||
ds: &mut DispatchState,
|
||||
) {
|
||||
let args: serde_json::Value =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue