use std::future::Future;
use std::sync::Arc;
use anyhow::Result;
use serde_json::Value;
use super::HarnessContextSnapshot;
use super::ToolRegistry;
use crate::config::constants::tools;
impl ToolRegistry {
async fn process_harness_command_session_output(&self, value: Value) -> Result<Value> {
let processed = self.process_tool_output(tools::UNIFIED_EXEC, value, false).await;
Ok(super::normalize_tool_output(processed))
}
pub fn set_harness_session(&self, session_id: impl Into<String>) {
self.harness_context.set_session_id(session_id);
}
pub fn set_harness_task(&self, task_id: Option<String>) {
self.harness_context.set_task_id(task_id);
}
pub fn harness_context_snapshot(&self) -> HarnessContextSnapshot {
self.harness_context.snapshot()
}
pub fn set_shared_circuit_breaker(&self, circuit_breaker: Arc<crate::tools::circuit_breaker::CircuitBreaker>) {
if let Ok(mut slot) = self.shared_circuit_breaker.write() {
*slot = Some(circuit_breaker);
}
}
pub fn shared_circuit_breaker(&self) -> Option<Arc<crate::tools::circuit_breaker::CircuitBreaker>> {
self.shared_circuit_breaker.read().ok().and_then(|g| g.clone())
}
pub async fn execute_harness_command_session(&self, args: Value) -> Result<Value> {
let value = self.execute_command_session(args).await?;
self.process_harness_command_session_output(value).await
}
pub async fn execute_harness_command_session_terminal_run(&self, args: Value) -> Result<Value> {
let value = self.execute_harness_command_session_terminal_run_raw(args).await?;
self.process_harness_command_session_output(value).await
}
pub async fn read_harness_exec_session_output(&self, session_id: &str, drain: bool) -> Result<Option<String>> {
self.exec_sessions.read_session_output(session_id, drain).await
}
pub fn harness_exec_session_completed<'a>(
&'a self,
session_id: &'a str,
) -> impl Future<Output = Result<Option<i32>>> + 'a {
self.exec_sessions.is_session_completed(session_id)
}
pub fn terminate_harness_exec_session<'a>(&'a self, session_id: &'a str) -> impl Future<Output = Result<()>> + 'a {
self.exec_sessions.terminate_session(session_id)
}
pub async fn close_harness_exec_session(&self, session_id: &str) -> Result<()> {
self.close_exec_session(session_id).await?;
Ok(())
}
}