Skip to main content

vtcode_exec_events/
event_wire.rs

1//! Canonical wire `type` values for [`crate::ThreadEvent`].
2//!
3//! Kept in its own module so the wire vocabulary and its invariant test stay
4//! together without pushing `lib.rs` past the 1000-line ceiling.
5
6/// Canonical wire `type` values of [`crate::ThreadEvent`].
7///
8/// Consumers that *compare* recorded event types by string use these consts;
9/// producers that *emit* the name use [`crate::ThreadEvent::wire_name`]. Both
10/// resolve to the same spellings, which `wire_name_matches_serialized_type_tag`
11/// keeps aligned with the serde tags.
12pub mod wire_type {
13    pub const MATRIX_UPDATED: &str = "matrix.updated";
14    pub const TRACKER_UPDATED: &str = "tracker.updated";
15    pub const GOAL_UPDATED: &str = "goal.updated";
16    pub const THREAD_STARTED: &str = "thread.started";
17    pub const THREAD_COMPLETED: &str = "thread.completed";
18    pub const THREAD_COMPACT_BOUNDARY: &str = "thread.compact_boundary";
19    pub const CONTEXT_RESET: &str = "context.reset";
20    pub const TURN_STARTED: &str = "turn.started";
21    pub const TURN_COMPLETED: &str = "turn.completed";
22    pub const TURN_FAILED: &str = "turn.failed";
23    pub const TURN_BLOCKED: &str = "turn.blocked";
24    pub const ITEM_STARTED: &str = "item.started";
25    pub const ITEM_UPDATED: &str = "item.updated";
26    pub const ITEM_COMPLETED: &str = "item.completed";
27    pub const APP_SANDBOX_DENIED: &str = "app.sandbox_denied";
28    pub const PERMISSION_REQUESTED: &str = "permission.requested";
29    pub const PERMISSION_RESOLVED: &str = "permission.resolved";
30    pub const INTERJECTED: &str = "interjected";
31    pub const PLAN_DELTA: &str = "plan.delta";
32    pub const PLAN_APPROVAL_REQUESTED: &str = "plan.approval.requested";
33    pub const PLAN_APPROVAL_RESOLVED: &str = "plan.approval.resolved";
34    pub const ERROR: &str = "error";
35    /// `Unknown` is a serde catch-all with no serde rename, so its serialized
36    /// type tag is the variant name — capital U. Keep this aligned with
37    /// `wire_name_matches_serialized_type_tag`.
38    pub const UNKNOWN: &str = "Unknown";
39}
40
41impl crate::ThreadEvent {
42    /// Canonical wire `type` value for this event.
43    ///
44    /// Consumers that record, filter, or compare event types by string (the
45    /// share-log timeline, log viewer, and OTel emitter) reference this
46    /// instead of re-spelling a `#[serde(rename)]` at their own call site.
47    #[must_use]
48    pub const fn wire_name(&self) -> &'static str {
49        use crate::ThreadEvent as E;
50        use wire_type as w;
51        match self {
52            E::MatrixUpdated(_) => w::MATRIX_UPDATED,
53            E::TrackerUpdated(_) => w::TRACKER_UPDATED,
54            E::GoalUpdated(_) => w::GOAL_UPDATED,
55            E::ThreadStarted(_) => w::THREAD_STARTED,
56            E::ThreadCompleted(_) => w::THREAD_COMPLETED,
57            E::ThreadCompactBoundary(_) => w::THREAD_COMPACT_BOUNDARY,
58            E::ContextReset(_) => w::CONTEXT_RESET,
59            E::TurnStarted(_) => w::TURN_STARTED,
60            E::TurnCompleted(_) => w::TURN_COMPLETED,
61            E::TurnFailed(_) => w::TURN_FAILED,
62            E::TurnBlocked(_) => w::TURN_BLOCKED,
63            E::ItemStarted(_) => w::ITEM_STARTED,
64            E::ItemUpdated(_) => w::ITEM_UPDATED,
65            E::ItemCompleted(_) => w::ITEM_COMPLETED,
66            E::AppSandboxDenied(_) => w::APP_SANDBOX_DENIED,
67            E::PermissionRequested(_) => w::PERMISSION_REQUESTED,
68            E::PermissionResolved(_) => w::PERMISSION_RESOLVED,
69            E::Interjected(_) => w::INTERJECTED,
70            E::PlanDelta(_) => w::PLAN_DELTA,
71            E::PlanApprovalRequested(_) => w::PLAN_APPROVAL_REQUESTED,
72            E::PlanApprovalResolved(_) => w::PLAN_APPROVAL_RESOLVED,
73            E::Error(_) => w::ERROR,
74            E::Unknown => w::UNKNOWN,
75        }
76    }
77}