1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
//! 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<Uuid>,
/// The file path where the issue was detected (optional)
#[serde(skip_serializing_if = "Option::is_none")]
pub file_path: Option<String>,
/// Additional context about the issue (optional)
#[serde(skip_serializing_if = "Option::is_none")]
pub context: Option<String>,
}
/// 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<Uuid>,
}
/// 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<chrono::Utc>,
}
/// 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<MonitoredTaskInfo>,
}
/// 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<String>,
/// Error message if any
pub error: Option<String>,
}
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<JsonValue, ApiError> {
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<JsonValue, ApiError> {
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<JsonValue, ApiError> {
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<JsonValue, ApiError> {
self.get(&format!("/api/v1/mesh/red-team/tasks/{}/diff", task_id))
.await
}
}
|