WIP: Agent/AgentState — 36 errors remaining, all .lock() → .state.lock() or .context.lock()
Bulk replaced Arc<Mutex<Agent>> with Arc<Agent> 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 <poc@bcachefs.org>
This commit is contained in:
parent
e73135a8d0
commit
1d61b091b0
9 changed files with 30 additions and 30 deletions
|
|
@ -63,11 +63,11 @@ pub struct AutoAgent {
|
|||
}
|
||||
|
||||
/// Per-run conversation backend — wraps a forked agent.
|
||||
struct Backend(std::sync::Arc<tokio::sync::Mutex<Agent>>);
|
||||
struct Backend(std::sync::Arc<Agent>);
|
||||
|
||||
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<tokio::sync::Mutex<Agent>>,
|
||||
agent: &std::sync::Arc<Agent>,
|
||||
memory_keys: &[String],
|
||||
state: &std::collections::BTreeMap<String, String>,
|
||||
) -> Result<String, String> {
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ async fn cached_store() -> Result<std::sync::Arc<tokio::sync::Mutex<Store>>> {
|
|||
Store::cached().await.map_err(|e| anyhow::anyhow!("{}", e))
|
||||
}
|
||||
|
||||
async fn get_provenance(agent: &Option<std::sync::Arc<tokio::sync::Mutex<crate::agent::Agent>>>) -> String {
|
||||
async fn get_provenance(agent: &Option<std::sync::Arc<crate::agent::Agent>>) -> 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<String> {
|
|||
.render())
|
||||
}
|
||||
|
||||
async fn write(agent: &Option<std::sync::Arc<tokio::sync::Mutex<crate::agent::Agent>>>, args: &serde_json::Value) -> Result<String> {
|
||||
async fn write(agent: &Option<std::sync::Arc<crate::agent::Agent>>, args: &serde_json::Value) -> Result<String> {
|
||||
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<String> {
|
|||
Ok(format!("{} ↔ {} strength {:.2} → {:.2}", s, t, old, strength))
|
||||
}
|
||||
|
||||
async fn link_add(agent: &Option<std::sync::Arc<tokio::sync::Mutex<crate::agent::Agent>>>, args: &serde_json::Value) -> Result<String> {
|
||||
async fn link_add(agent: &Option<std::sync::Arc<crate::agent::Agent>>, args: &serde_json::Value) -> Result<String> {
|
||||
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<String> {
|
|||
Ok(format!("Renamed '{}' → '{}'", resolved, new_key))
|
||||
}
|
||||
|
||||
async fn supersede(agent: &Option<std::sync::Arc<tokio::sync::Mutex<crate::agent::Agent>>>, args: &serde_json::Value) -> Result<String> {
|
||||
async fn supersede(agent: &Option<std::sync::Arc<crate::agent::Agent>>, args: &serde_json::Value) -> Result<String> {
|
||||
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<String> {
|
|||
}
|
||||
}
|
||||
|
||||
async fn journal_new(agent: &Option<std::sync::Arc<tokio::sync::Mutex<crate::agent::Agent>>>, args: &serde_json::Value) -> Result<String> {
|
||||
async fn journal_new(agent: &Option<std::sync::Arc<crate::agent::Agent>>, args: &serde_json::Value) -> Result<String> {
|
||||
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<std::sync::Arc<tokio::sync::Mutex<crate::age
|
|||
Ok(format!("New entry '{}' ({} words)", title, word_count))
|
||||
}
|
||||
|
||||
async fn journal_update(agent: &Option<std::sync::Arc<tokio::sync::Mutex<crate::agent::Agent>>>, args: &serde_json::Value) -> Result<String> {
|
||||
async fn journal_update(agent: &Option<std::sync::Arc<crate::agent::Agent>>, args: &serde_json::Value) -> Result<String> {
|
||||
let body = get_str(args, "body")?;
|
||||
let arc = cached_store().await?;
|
||||
let mut store = arc.lock().await;
|
||||
|
|
|
|||
|
|
@ -295,7 +295,7 @@ pub struct SubconsciousSnapshot {
|
|||
pub turn: usize,
|
||||
pub last_run_secs_ago: Option<f64>,
|
||||
/// Shared handle to the forked agent — UI locks to read entries.
|
||||
pub forked_agent: Option<Arc<tokio::sync::Mutex<crate::agent::Agent>>>,
|
||||
pub forked_agent: Option<Arc<crate::agent::Agent>>,
|
||||
/// 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<Instant>,
|
||||
/// The forked agent for the current/last run. Shared with the
|
||||
/// spawned task so the UI can read entries live.
|
||||
forked_agent: Option<Arc<tokio::sync::Mutex<crate::agent::Agent>>>,
|
||||
forked_agent: Option<Arc<crate::agent::Agent>>,
|
||||
/// Entry index where the fork diverged from the conscious agent.
|
||||
fork_point: usize,
|
||||
handle: Option<tokio::task::JoinHandle<(AutoAgent, Result<String, String>)>>,
|
||||
|
|
@ -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<tokio::sync::Mutex<Agent>>) {
|
||||
pub async fn collect_results(&mut self, agent: &Arc<Agent>) {
|
||||
let finished: Vec<(usize, tokio::task::JoinHandle<(AutoAgent, Result<String, String>)>)> =
|
||||
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<tokio::sync::Mutex<Agent>>) {
|
||||
pub async fn trigger(&mut self, agent: &Arc<Agent>) {
|
||||
let (conversation_bytes, memory_keys) = {
|
||||
let ag = agent.lock().await;
|
||||
let bytes = ag.context.conversation().iter()
|
||||
|
|
|
|||
|
|
@ -248,7 +248,7 @@ enum BgEvent {
|
|||
pub type SharedMindState = std::sync::Mutex<MindState>;
|
||||
|
||||
pub struct Mind {
|
||||
pub agent: Arc<tokio::sync::Mutex<Agent>>,
|
||||
pub agent: Arc<Agent>,
|
||||
pub shared: Arc<SharedMindState>,
|
||||
pub config: SessionConfig,
|
||||
subconscious: tokio::sync::Mutex<Subconscious>,
|
||||
|
|
|
|||
|
|
@ -602,7 +602,7 @@ fn str_err<T>(r: Result<T, String>) -> anyhow::Result<T> {
|
|||
|
||||
/// digest_daily tool handler: generate a daily digest
|
||||
async fn handle_digest_daily(
|
||||
_agent: Option<std::sync::Arc<tokio::sync::Mutex<super::super::agent::Agent>>>,
|
||||
_agent: Option<std::sync::Arc<super::super::agent::Agent>>,
|
||||
args: serde_json::Value,
|
||||
) -> anyhow::Result<String> {
|
||||
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<std::sync::Arc<tokio::sync::Mutex<super::super::agent::Agent>>>,
|
||||
_agent: Option<std::sync::Arc<super::super::agent::Agent>>,
|
||||
args: serde_json::Value,
|
||||
) -> anyhow::Result<String> {
|
||||
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<std::sync::Arc<tokio::sync::Mutex<super::super::agent::Agent>>>,
|
||||
_agent: Option<std::sync::Arc<super::super::agent::Agent>>,
|
||||
args: serde_json::Value,
|
||||
) -> anyhow::Result<String> {
|
||||
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<std::sync::Arc<tokio::sync::Mutex<super::super::agent::Agent>>>,
|
||||
_agent: Option<std::sync::Arc<super::super::agent::Agent>>,
|
||||
_args: serde_json::Value,
|
||||
) -> anyhow::Result<String> {
|
||||
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<std::sync::Arc<tokio::sync::Mutex<super::super::agent::Agent>>>,
|
||||
_agent: Option<std::sync::Arc<super::super::agent::Agent>>,
|
||||
_args: serde_json::Value,
|
||||
) -> anyhow::Result<String> {
|
||||
let mut store = str_err(Store::load())?;
|
||||
|
|
|
|||
|
|
@ -330,7 +330,7 @@ pub async fn score_memories_incremental<F, Fut>(
|
|||
max_age_secs: i64,
|
||||
response_window: usize,
|
||||
client: &ApiClient,
|
||||
agent: &std::sync::Arc<tokio::sync::Mutex<crate::agent::Agent>>,
|
||||
agent: &std::sync::Arc<crate::agent::Agent>,
|
||||
mut on_score: F,
|
||||
) -> anyhow::Result<usize>
|
||||
where
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ fn dispatch_command(input: &str) -> Option<SlashCommand> {
|
|||
|
||||
/// Switch model — used by both /model command and tool-initiated switches.
|
||||
pub async fn cmd_switch_model(
|
||||
agent: &std::sync::Arc<tokio::sync::Mutex<crate::agent::Agent>>,
|
||||
agent: &std::sync::Arc<crate::agent::Agent>,
|
||||
name: &str,
|
||||
) {
|
||||
let resolved = {
|
||||
|
|
@ -129,7 +129,7 @@ pub async fn cmd_switch_model(
|
|||
}
|
||||
}
|
||||
|
||||
fn notify_help(agent: &std::sync::Arc<tokio::sync::Mutex<crate::agent::Agent>>) {
|
||||
fn notify_help(agent: &std::sync::Arc<crate::agent::Agent>) {
|
||||
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<AstNode>,
|
||||
pending_display_count: usize,
|
||||
/// Reference to agent for state sync
|
||||
agent: std::sync::Arc<tokio::sync::Mutex<crate::agent::Agent>>,
|
||||
agent: std::sync::Arc<crate::agent::Agent>,
|
||||
shared_mind: std::sync::Arc<crate::mind::SharedMindState>,
|
||||
mind_tx: tokio::sync::mpsc::UnboundedSender<crate::mind::MindCommand>,
|
||||
}
|
||||
|
||||
impl InteractScreen {
|
||||
pub fn new(
|
||||
agent: std::sync::Arc<tokio::sync::Mutex<crate::agent::Agent>>,
|
||||
agent: std::sync::Arc<crate::agent::Agent>,
|
||||
shared_mind: std::sync::Arc<crate::mind::SharedMindState>,
|
||||
mind_tx: tokio::sync::mpsc::UnboundedSender<crate::mind::MindCommand>,
|
||||
) -> Self {
|
||||
|
|
|
|||
|
|
@ -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<tokio::sync::Mutex<crate::agent::Agent>>,
|
||||
agent: std::sync::Arc<crate::agent::Agent>,
|
||||
tree: SectionTree,
|
||||
}
|
||||
|
||||
impl ConsciousScreen {
|
||||
pub fn new(agent: std::sync::Arc<tokio::sync::Mutex<crate::agent::Agent>>) -> Self {
|
||||
pub fn new(agent: std::sync::Arc<crate::agent::Agent>) -> Self {
|
||||
Self { agent, tree: SectionTree::new() }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue