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_unified_exec_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_unified_exec(&self, args: Value) -> Result<Value> {
let value = self.execute_unified_exec(args).await?;
self.process_harness_unified_exec_output(value).await
}
pub async fn execute_harness_unified_exec_terminal_run(&self, args: Value) -> Result<Value> {
let value = self
.execute_harness_unified_exec_terminal_run_raw(args)
.await?;
self.process_harness_unified_exec_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 async fn harness_exec_session_completed(&self, session_id: &str) -> Result<Option<i32>> {
self.exec_sessions.is_session_completed(session_id).await
}
pub async fn terminate_harness_exec_session(&self, session_id: &str) -> Result<()> {
self.exec_sessions.terminate_session(session_id).await
}
pub async fn close_harness_exec_session(&self, session_id: &str) -> Result<()> {
self.close_exec_session(session_id).await?;
Ok(())
}
}