use std::sync::{Arc, Mutex};
use crate::session::delegation::DelegationState;
use crate::session::delegation_skills::SWARM_DISPATCH;
use crate::session::relevance::{Bucket, Dependency, Difficulty, ToolUse};
pub fn bucket_for_specialty(specialty: &str) -> Bucket {
let s = specialty.to_ascii_lowercase();
let difficulty = if s.contains("security") || s.contains("architect") {
Difficulty::Hard
} else if s.contains("review") || s.contains("test") {
Difficulty::Medium
} else {
Difficulty::Easy
};
let tool_use = if s.contains("deploy") || s.contains("infra") || s.contains("debug") {
ToolUse::Yes
} else {
ToolUse::No
};
Bucket {
difficulty,
dependency: Dependency::Isolated,
tool_use,
}
}
pub fn record_subtask_outcome(
state: &Arc<Mutex<DelegationState>>,
provider: &str,
specialty: &str,
success: bool,
) {
let bucket = bucket_for_specialty(specialty);
match state.lock() {
Ok(mut guard) => {
if !guard.enabled() {
return;
}
guard.update(provider, SWARM_DISPATCH, bucket, success);
}
Err(err) => {
tracing::warn!(%err, "delegation state mutex poisoned; skipping swarm outcome update");
}
}
}