//! Red team API methods. //! //! This module provides API client methods for red team tasks to: //! - Notify supervisors about potential issues //! - Get status of the red team monitoring //! - Access monitored task information //! - Request diffs from work tasks (read-only) use serde::{Deserialize, Serialize}; use uuid::Uuid; use super::client::{ApiClient, ApiError}; use super::supervisor::JsonValue; /// Request body for red team notify endpoint. #[derive(Serialize)] #[serde(rename_all = "camelCase")] pub struct RedTeamNotifyRequest { /// The issue message pub message: String, /// Severity level: info, warning, critical pub severity: String, /// The specific task this relates to (optional) #[serde(skip_serializing_if = "Option::is_none")] pub related_task_id: Option, /// The file path where the issue was detected (optional) #[serde(skip_serializing_if = "Option::is_none")] pub file_path: Option, /// Additional context about the issue (optional) #[serde(skip_serializing_if = "Option::is_none")] pub context: Option, } /// Response from the notify endpoint. #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct RedTeamNotifyResponse { /// Unique ID for this notification pub notification_id: Uuid, /// Whether the notification was successfully delivered to the supervisor pub delivered: bool, /// The supervisor task ID that received the notification pub supervisor_task_id: Option, } /// Response from the status endpoint. #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct RedTeamStatusResponse { /// Contract ID being monitored pub contract_id: Uuid, /// Red team task ID pub red_team_task_id: Uuid, /// Current task status pub status: String, /// Number of notifications sent so far pub notifications_sent: i64, } /// Information about a task being monitored. #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct MonitoredTaskInfo { pub task_id: Uuid, pub name: String, pub status: String, pub created_at: chrono::DateTime, } /// Response from the monitored-tasks endpoint. #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct MonitoredTasksResponse { /// Whether subscription was successful pub success: bool, /// Contract ID being monitored pub contract_id: Uuid, /// Message about the subscription pub message: String, /// List of work tasks currently active in the contract pub active_tasks: Vec, } /// Response from the task diff endpoint. #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct RedTeamDiffResponse { /// Task ID that was queried pub task_id: Uuid, /// Whether the request was successful pub success: bool, /// The diff content (if available) pub diff: Option, /// Error message if any pub error: Option, } impl ApiClient { /// Send a red team notification about an issue found during adversarial review. /// /// POST /api/v1/mesh/red-team/notify /// /// This sends an alert to the supervisor task, who can then take action /// such as pausing the work task or providing feedback. pub async fn red_team_notify(&self, req: RedTeamNotifyRequest) -> Result { self.post("/api/v1/mesh/red-team/notify", &req).await } /// Get the current status of the red team task. /// /// GET /api/v1/mesh/red-team/status /// /// Returns information about the red team task including the contract /// being monitored and notification statistics. pub async fn red_team_status(&self) -> Result { self.get("/api/v1/mesh/red-team/status").await } /// Get the list of active work tasks that can be monitored. /// /// GET /api/v1/mesh/red-team/monitored-tasks /// /// Returns information about all active work tasks in the contract that /// the red team can monitor. This helps understand what tasks are running. pub async fn red_team_monitored_tasks(&self) -> Result { self.get("/api/v1/mesh/red-team/monitored-tasks").await } /// Get the diff of changes for a specific work task (read-only). /// /// GET /api/v1/mesh/red-team/tasks/{task_id}/diff /// /// This allows the red team to see what code changes a work task has made. /// Access is read-only - the red team cannot modify any code. pub async fn red_team_task_diff(&self, task_id: Uuid) -> Result { self.get(&format!("/api/v1/mesh/red-team/tasks/{}/diff", task_id)) .await } }