use serde::Serialize;
#[derive(Debug, Clone, Serialize, schemars::JsonSchema)]
pub struct AgentSpawnedPayload {
pub agent_id: String,
pub role: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub model: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub stage_name: Option<String>,
pub background: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub parent_tool_use_id: Option<String>,
}
#[derive(Debug, Clone, Serialize, schemars::JsonSchema)]
pub struct AgentCompletedPayload {
pub agent_id: String,
pub role: String,
pub had_error: bool,
pub duration_ms: u64,
}
#[derive(Debug, Clone, Serialize, schemars::JsonSchema)]
pub struct TeamStageCompletePayload {
pub stage_name: String,
pub agent_count: usize,
pub duration_ms: u64,
pub success: bool,
pub agents_with_errors: usize,
}
#[cfg(test)]
mod tests {
use super::*;
use crate::telemetry::TelemetryEvent;
#[test]
fn agent_spawned_serializes() {
let event = TelemetryEvent::agent_spawned(
"sess",
5,
None,
AgentSpawnedPayload {
agent_id: "agent_02".into(),
role: "researcher".into(),
model: Some("claude-sonnet-4-6".into()),
stage_name: Some("research".into()),
background: false,
parent_tool_use_id: None,
},
);
assert_eq!(event.kind(), "agent_spawned");
let v =
serde_json::to_value(event).expect("serialization of telemetry event should not fail");
assert_eq!(v["type"], "agent_spawned");
assert_eq!(v["role"], "researcher");
}
#[test]
fn agent_completed_serializes() {
let event = TelemetryEvent::agent_completed(
"sess",
8,
None,
AgentCompletedPayload {
agent_id: "agent_02".into(),
role: "researcher".into(),
had_error: false,
duration_ms: 45000,
},
);
assert_eq!(event.kind(), "agent_completed");
let v =
serde_json::to_value(event).expect("serialization of telemetry event should not fail");
assert_eq!(v["type"], "agent_completed");
assert_eq!(v["duration_ms"], 45000);
}
#[test]
fn team_stage_complete_serializes() {
let event = TelemetryEvent::team_stage_complete(
"sess",
10,
None,
TeamStageCompletePayload {
stage_name: "implementation".into(),
agent_count: 3,
duration_ms: 120000,
success: true,
agents_with_errors: 0,
},
);
assert_eq!(event.kind(), "team_stage_complete");
let v =
serde_json::to_value(event).expect("serialization of telemetry event should not fail");
assert_eq!(v["type"], "team_stage_complete");
assert_eq!(v["agent_count"], 3);
}
}