chore: fix clippy warnings and run rustfmt
This commit is contained in:
1 parent
fecd8bf33f
commit
3765e6b05d
21 files changed
+420
-369
No files matched your search
+62
-58
@@ -107,9 +107,10 @@ pub async fn ttl_sweeper_worker(state: Arc<MemoryState>) {
|
||||
state.project.tasks.read_with(|tasks| {
|
||||
for t in tasks.iter() {
|
||||
if let Some(exp) = t.expires_at
|
||||
&& t.is_active() {
|
||||
next_expiry = Some(next_expiry.map_or(exp, |curr| curr.min(exp)));
|
||||
}
|
||||
&& t.is_active()
|
||||
{
|
||||
next_expiry = Some(next_expiry.map_or(exp, |curr| curr.min(exp)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -140,7 +141,7 @@ pub async fn ttl_sweeper_worker(state: Arc<MemoryState>) {
|
||||
let sleep_duration = match next_expiry {
|
||||
Some(exp) if exp > now => {
|
||||
let diff = exp - now;
|
||||
std::time::Duration::from_secs(diff.min(60).max(1))
|
||||
std::time::Duration::from_secs(diff.clamp(1, 60))
|
||||
}
|
||||
Some(_) => std::time::Duration::from_millis(50),
|
||||
None => std::time::Duration::from_secs(60),
|
||||
@@ -161,11 +162,13 @@ pub async fn ttl_sweeper_worker(state: Arc<MemoryState>) {
|
||||
state.project.tasks.modify(|tasks| {
|
||||
for t in tasks.iter_mut() {
|
||||
if let Some(exp) = t.expires_at
|
||||
&& exp <= now && t.is_active() {
|
||||
t.status = "expired".to_string();
|
||||
t.updated_at = now;
|
||||
expired_tasks.push(t.id.clone());
|
||||
}
|
||||
&& exp <= now
|
||||
&& t.is_active()
|
||||
{
|
||||
t.status = "expired".to_string();
|
||||
t.updated_at = now;
|
||||
expired_tasks.push(t.id.clone());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -249,27 +252,28 @@ pub async fn condense_graph_worker(state: Arc<MemoryState>) {
|
||||
});
|
||||
|
||||
if let Some((content, names)) = snippet_condensation
|
||||
&& !content.is_empty() {
|
||||
let name = format!("Snippet History {}", now);
|
||||
state.modify_graph(|graph| {
|
||||
graph.entities.insert(
|
||||
name.clone(),
|
||||
crate::models::Entity {
|
||||
name: name.clone(),
|
||||
entity_type: "Historical Summary".to_string(),
|
||||
observations: vec![content],
|
||||
namespace: crate::models::default_namespace(),
|
||||
git_branch: None,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
});
|
||||
let name_set: std::collections::HashSet<String> = names.into_iter().collect();
|
||||
state.code.snippets.modify(|snippets| {
|
||||
snippets.retain(|s| !name_set.contains(&s.name));
|
||||
});
|
||||
tracing::info!("Condensed snippets into Historical Summary.");
|
||||
}
|
||||
&& !content.is_empty()
|
||||
{
|
||||
let name = format!("Snippet History {}", now);
|
||||
state.modify_graph(|graph| {
|
||||
graph.entities.insert(
|
||||
name.clone(),
|
||||
crate::models::Entity {
|
||||
name: name.clone(),
|
||||
entity_type: "Historical Summary".to_string(),
|
||||
observations: vec![content],
|
||||
namespace: crate::models::default_namespace(),
|
||||
git_branch: None,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
});
|
||||
let name_set: std::collections::HashSet<String> = names.into_iter().collect();
|
||||
state.code.snippets.modify(|snippets| {
|
||||
snippets.retain(|s| !name_set.contains(&s.name));
|
||||
});
|
||||
tracing::info!("Condensed snippets into Historical Summary.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,36 +323,37 @@ pub async fn memory_consolidation_worker(state: Arc<MemoryState>) {
|
||||
.trim_end_matches("```")
|
||||
.trim();
|
||||
if let Ok(duplicates) = serde_json::from_str::<Vec<String>>(cleaned)
|
||||
&& duplicates.len() == 2 {
|
||||
let e1_name = &duplicates[0];
|
||||
let e2_name = &duplicates[1];
|
||||
&& duplicates.len() == 2
|
||||
{
|
||||
let e1_name = &duplicates[0];
|
||||
let e2_name = &duplicates[1];
|
||||
|
||||
if e1_name != e2_name {
|
||||
tracing::info!(
|
||||
"Memory Consolidation Daemon: Merging '{}' into '{}'",
|
||||
e2_name,
|
||||
e1_name
|
||||
);
|
||||
state.modify_graph(|g| {
|
||||
if let Some(mut e2) = g.entities.remove(e2_name) {
|
||||
if let Some(e1) = g.entities.get_mut(e1_name) {
|
||||
e1.observations.append(&mut e2.observations);
|
||||
} else {
|
||||
g.entities.insert(e2_name.clone(), e2);
|
||||
}
|
||||
if e1_name != e2_name {
|
||||
tracing::info!(
|
||||
"Memory Consolidation Daemon: Merging '{}' into '{}'",
|
||||
e2_name,
|
||||
e1_name
|
||||
);
|
||||
state.modify_graph(|g| {
|
||||
if let Some(mut e2) = g.entities.remove(e2_name) {
|
||||
if let Some(e1) = g.entities.get_mut(e1_name) {
|
||||
e1.observations.append(&mut e2.observations);
|
||||
} else {
|
||||
g.entities.insert(e2_name.clone(), e2);
|
||||
}
|
||||
}
|
||||
|
||||
for rel in g.relations.iter_mut() {
|
||||
if rel.from == *e2_name {
|
||||
rel.from = e1_name.clone();
|
||||
}
|
||||
if rel.to == *e2_name {
|
||||
rel.to = e1_name.clone();
|
||||
}
|
||||
for rel in g.relations.iter_mut() {
|
||||
if rel.from == *e2_name {
|
||||
rel.from = e1_name.clone();
|
||||
}
|
||||
});
|
||||
}
|
||||
if rel.to == *e2_name {
|
||||
rel.to = e1_name.clone();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -466,13 +471,12 @@ pub async fn run_server(state: Arc<MemoryState>) -> Result<(), Box<dyn std::erro
|
||||
event.payload.get("action").and_then(|a| a.as_str()),
|
||||
event.payload.get("target").and_then(|t| t.as_str()),
|
||||
event.payload.get("status").and_then(|s| s.as_str()),
|
||||
) {
|
||||
if (status == "authorized" || status == "blocked")
|
||||
)
|
||||
&& (status == "authorized" || status == "blocked")
|
||||
&& let Some(addr) = subscribers.remove(&(action.to_string(), target.to_string())) {
|
||||
let response = if status == "authorized" { b"APPROVED" } else { b"REJECTED" };
|
||||
let _ = socket.send_to(response, addr).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user