From 1d61b091b031c7c57f8f835820770aa2313430e1 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Wed, 8 Apr 2026 15:40:36 -0400 Subject: [PATCH] =?UTF-8?q?WIP:=20Agent/AgentState=20=E2=80=94=2036=20erro?= =?UTF-8?q?rs=20remaining,=20all=20.lock()=20=E2=86=92=20.state.lock()=20o?= =?UTF-8?q?r=20.context.lock()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bulk replaced Arc> with Arc across all files. Fixed control.rs, memory.rs tool handlers. Fixed oneshot Backend. Remaining errors are all agent.lock() → agent.state.lock() or agent.context.lock() in mind/, user/, and a few in mod.rs. Co-Authored-By: Proof of Concept --- src/agent/oneshot.rs | 6 +++--- src/agent/tools/control.rs | 6 +++--- src/agent/tools/memory.rs | 14 +++++++------- src/mind/dmn.rs | 8 ++++---- src/mind/mod.rs | 2 +- src/subconscious/digest.rs | 10 +++++----- src/subconscious/learn.rs | 2 +- src/user/chat.rs | 8 ++++---- src/user/context.rs | 4 ++-- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/agent/oneshot.rs b/src/agent/oneshot.rs index 44a109f..dd8358f 100644 --- a/src/agent/oneshot.rs +++ b/src/agent/oneshot.rs @@ -63,11 +63,11 @@ pub struct AutoAgent { } /// Per-run conversation backend — wraps a forked agent. -struct Backend(std::sync::Arc>); +struct Backend(std::sync::Arc); impl Backend { async fn push_node(&mut self, node: AstNode) { - self.0.lock().await.push_node(node); + self.0.push_node(node).await; } } @@ -149,7 +149,7 @@ impl AutoAgent { /// Arc to read entries live during the run. pub async fn run_forked_shared( &mut self, - agent: &std::sync::Arc>, + agent: &std::sync::Arc, memory_keys: &[String], state: &std::collections::BTreeMap, ) -> Result { diff --git a/src/agent/tools/control.rs b/src/agent/tools/control.rs index daa5ef5..6ada846 100644 --- a/src/agent/tools/control.rs +++ b/src/agent/tools/control.rs @@ -14,7 +14,7 @@ pub(super) fn tools() -> [super::Tool; 3] { .ok_or_else(|| anyhow::anyhow!("'model' parameter is required"))?; if model.is_empty() { anyhow::bail!("'model' parameter cannot be empty"); } if let Some(agent) = agent { - let mut a = agent.lock().await; + let mut a = agent.state.lock().await; a.pending_model_switch = Some(model.to_string()); } Ok(format!("Switching to model '{}' after this turn.", model)) @@ -24,7 +24,7 @@ pub(super) fn tools() -> [super::Tool; 3] { parameters_json: r#"{"type":"object","properties":{}}"#, handler: |agent, _v| Box::pin(async move { if let Some(agent) = agent { - let mut a = agent.lock().await; + let mut a = agent.state.lock().await; a.pending_yield = true; a.pending_dmn_pause = true; } @@ -36,7 +36,7 @@ pub(super) fn tools() -> [super::Tool; 3] { handler: |agent, v| Box::pin(async move { let msg = v.get("message").and_then(|v| v.as_str()).unwrap_or("Waiting for input."); if let Some(agent) = agent { - let mut a = agent.lock().await; + let mut a = agent.state.lock().await; a.pending_yield = true; } Ok(format!("Yielding. {}", msg)) diff --git a/src/agent/tools/memory.rs b/src/agent/tools/memory.rs index b7fa4d3..9abc712 100644 --- a/src/agent/tools/memory.rs +++ b/src/agent/tools/memory.rs @@ -23,9 +23,9 @@ async fn cached_store() -> Result>> { Store::cached().await.map_err(|e| anyhow::anyhow!("{}", e)) } -async fn get_provenance(agent: &Option>>) -> String { +async fn get_provenance(agent: &Option>) -> String { match agent { - Some(a) => a.lock().await.provenance.clone(), + Some(a) => a.state.lock().await.provenance.clone(), None => "manual".to_string(), } } @@ -98,7 +98,7 @@ fn render(args: &serde_json::Value) -> Result { .render()) } -async fn write(agent: &Option>>, args: &serde_json::Value) -> Result { +async fn write(agent: &Option>, args: &serde_json::Value) -> Result { let key = get_str(args, "key")?; let content = get_str(args, "content")?; let prov = get_provenance(agent).await; @@ -167,7 +167,7 @@ async fn link_set(args: &serde_json::Value) -> Result { Ok(format!("{} ↔ {} strength {:.2} → {:.2}", s, t, old, strength)) } -async fn link_add(agent: &Option>>, args: &serde_json::Value) -> Result { +async fn link_add(agent: &Option>, args: &serde_json::Value) -> Result { let arc = cached_store().await?; let mut store = arc.lock().await; let s = store.resolve_key(get_str(args, "source")?).map_err(|e| anyhow::anyhow!("{}", e))?; @@ -211,7 +211,7 @@ async fn rename(args: &serde_json::Value) -> Result { Ok(format!("Renamed '{}' → '{}'", resolved, new_key)) } -async fn supersede(agent: &Option>>, args: &serde_json::Value) -> Result { +async fn supersede(agent: &Option>, args: &serde_json::Value) -> Result { let old_key = get_str(args, "old_key")?; let new_key = get_str(args, "new_key")?; let reason = args.get("reason").and_then(|v| v.as_str()).unwrap_or("superseded"); @@ -274,7 +274,7 @@ async fn journal_tail(args: &serde_json::Value) -> Result { } } -async fn journal_new(agent: &Option>>, args: &serde_json::Value) -> Result { +async fn journal_new(agent: &Option>, args: &serde_json::Value) -> Result { let name = get_str(args, "name")?; let title = get_str(args, "title")?; let body = get_str(args, "body")?; @@ -311,7 +311,7 @@ async fn journal_new(agent: &Option>>, args: &serde_json::Value) -> Result { +async fn journal_update(agent: &Option>, args: &serde_json::Value) -> Result { let body = get_str(args, "body")?; let arc = cached_store().await?; let mut store = arc.lock().await; diff --git a/src/mind/dmn.rs b/src/mind/dmn.rs index 2389486..122528f 100644 --- a/src/mind/dmn.rs +++ b/src/mind/dmn.rs @@ -295,7 +295,7 @@ pub struct SubconsciousSnapshot { pub turn: usize, pub last_run_secs_ago: Option, /// Shared handle to the forked agent — UI locks to read entries. - pub forked_agent: Option>>, + pub forked_agent: Option>, /// Entry index where the fork diverged. pub fork_point: usize, /// Shared persistent state — accumulated across all agent runs. @@ -311,7 +311,7 @@ struct SubconsciousAgent { last_run: Option, /// The forked agent for the current/last run. Shared with the /// spawned task so the UI can read entries live. - forked_agent: Option>>, + forked_agent: Option>, /// Entry index where the fork diverged from the conscious agent. fork_point: usize, handle: Option)>>, @@ -428,7 +428,7 @@ impl Subconscious { /// Collect results from finished agents, inject outputs into the /// conscious agent's context. - pub async fn collect_results(&mut self, agent: &Arc>) { + pub async fn collect_results(&mut self, agent: &Arc) { let finished: Vec<(usize, tokio::task::JoinHandle<(AutoAgent, Result)>)> = self.agents.iter_mut().enumerate().filter_map(|(i, sub)| { if sub.handle.as_ref().is_some_and(|h| h.is_finished()) { @@ -511,7 +511,7 @@ impl Subconscious { } /// Trigger subconscious agents that are due to run. - pub async fn trigger(&mut self, agent: &Arc>) { + pub async fn trigger(&mut self, agent: &Arc) { let (conversation_bytes, memory_keys) = { let ag = agent.lock().await; let bytes = ag.context.conversation().iter() diff --git a/src/mind/mod.rs b/src/mind/mod.rs index d869cff..5136123 100644 --- a/src/mind/mod.rs +++ b/src/mind/mod.rs @@ -248,7 +248,7 @@ enum BgEvent { pub type SharedMindState = std::sync::Mutex; pub struct Mind { - pub agent: Arc>, + pub agent: Arc, pub shared: Arc, pub config: SessionConfig, subconscious: tokio::sync::Mutex, diff --git a/src/subconscious/digest.rs b/src/subconscious/digest.rs index 45d4d90..acd5844 100644 --- a/src/subconscious/digest.rs +++ b/src/subconscious/digest.rs @@ -602,7 +602,7 @@ fn str_err(r: Result) -> anyhow::Result { /// digest_daily tool handler: generate a daily digest async fn handle_digest_daily( - _agent: Option>>, + _agent: Option>, args: serde_json::Value, ) -> anyhow::Result { let date = str_err(get_str_required(&args, "date"))?; @@ -613,7 +613,7 @@ async fn handle_digest_daily( /// digest_weekly tool handler: generate a weekly digest async fn handle_digest_weekly( - _agent: Option>>, + _agent: Option>, args: serde_json::Value, ) -> anyhow::Result { let week_label = str_err(get_str_required(&args, "week"))?; @@ -624,7 +624,7 @@ async fn handle_digest_weekly( /// digest_monthly tool handler: generate a monthly digest async fn handle_digest_monthly( - _agent: Option>>, + _agent: Option>, args: serde_json::Value, ) -> anyhow::Result { let month = str_err(get_str_required(&args, "month"))?; @@ -635,7 +635,7 @@ async fn handle_digest_monthly( /// digest_auto tool handler: auto-generate all missing digests async fn handle_digest_auto( - _agent: Option>>, + _agent: Option>, _args: serde_json::Value, ) -> anyhow::Result { let mut store = str_err(Store::load())?; @@ -645,7 +645,7 @@ async fn handle_digest_auto( /// digest_links tool handler: parse and apply digest links async fn handle_digest_links( - _agent: Option>>, + _agent: Option>, _args: serde_json::Value, ) -> anyhow::Result { let mut store = str_err(Store::load())?; diff --git a/src/subconscious/learn.rs b/src/subconscious/learn.rs index 48d6278..905e163 100644 --- a/src/subconscious/learn.rs +++ b/src/subconscious/learn.rs @@ -330,7 +330,7 @@ pub async fn score_memories_incremental( max_age_secs: i64, response_window: usize, client: &ApiClient, - agent: &std::sync::Arc>, + agent: &std::sync::Arc, mut on_score: F, ) -> anyhow::Result where diff --git a/src/user/chat.rs b/src/user/chat.rs index 4ce5cf2..aa73520 100644 --- a/src/user/chat.rs +++ b/src/user/chat.rs @@ -98,7 +98,7 @@ fn dispatch_command(input: &str) -> Option { /// Switch model — used by both /model command and tool-initiated switches. pub async fn cmd_switch_model( - agent: &std::sync::Arc>, + agent: &std::sync::Arc, name: &str, ) { let resolved = { @@ -129,7 +129,7 @@ pub async fn cmd_switch_model( } } -fn notify_help(agent: &std::sync::Arc>) { +fn notify_help(agent: &std::sync::Arc) { if let Ok(mut ag) = agent.try_lock() { let mut help = String::new(); for cmd in &commands() { @@ -380,14 +380,14 @@ pub(crate) struct InteractScreen { last_entries: Vec, pending_display_count: usize, /// Reference to agent for state sync - agent: std::sync::Arc>, + agent: std::sync::Arc, shared_mind: std::sync::Arc, mind_tx: tokio::sync::mpsc::UnboundedSender, } impl InteractScreen { pub fn new( - agent: std::sync::Arc>, + agent: std::sync::Arc, shared_mind: std::sync::Arc, mind_tx: tokio::sync::mpsc::UnboundedSender, ) -> Self { diff --git a/src/user/context.rs b/src/user/context.rs index 8dc9da0..444ae88 100644 --- a/src/user/context.rs +++ b/src/user/context.rs @@ -10,12 +10,12 @@ use super::widgets::{SectionTree, SectionView, section_to_view, pane_block, rend use crate::agent::context::{AstNode, NodeBody, Ast}; pub(crate) struct ConsciousScreen { - agent: std::sync::Arc>, + agent: std::sync::Arc, tree: SectionTree, } impl ConsciousScreen { - pub fn new(agent: std::sync::Arc>) -> Self { + pub fn new(agent: std::sync::Arc) -> Self { Self { agent, tree: SectionTree::new() } }