Skip to main content

hm_plugin_protocol/
events.rs

1//! Build-time events. Produced by the orchestrator (host) and fanned
2//! out to output formatters, lifecycle hooks, and (via the host
3//! re-broadcast of `hm_emit_step_log`) any subscriber.
4
5use chrono::{DateTime, Utc};
6use schemars::JsonSchema as DeriveJsonSchema;
7use serde::{Deserialize, Serialize};
8use uuid::Uuid;
9
10use crate::executor::SnapshotRef;
11
12#[derive(
13    Debug,
14    Clone,
15    Copy,
16    PartialEq,
17    Eq,
18    Serialize,
19    Deserialize,
20    DeriveJsonSchema,
21    derive_more::IsVariant,
22)]
23#[serde(rename_all = "snake_case")]
24pub enum StdStream {
25    Stdout,
26    Stderr,
27}
28
29#[derive(
30    Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema, derive_more::IsVariant,
31)]
32#[serde(tag = "kind", rename_all = "snake_case")]
33pub enum BuildEvent {
34    BuildStart {
35        run_id: Uuid,
36        plan: PlanSummary,
37        started_at: DateTime<Utc>,
38    },
39    StepQueued {
40        step_id: Uuid,
41        key: String,
42        chain_idx: usize,
43        /// Key of this step's `BuildsIn` parent, if any. Lets renderers
44        /// nest progress bars to reflect the pipeline's DAG structure.
45        parent_key: Option<String>,
46        /// Human-readable name for display. Falls back to a truncated
47        /// command when no explicit label was set in the pipeline DSL.
48        display_name: String,
49    },
50    StepStart {
51        step_id: Uuid,
52        runner: String,
53        image: Option<String>,
54    },
55    StepLog {
56        step_id: Uuid,
57        stream: StdStream,
58        line: String,
59        ts: DateTime<Utc>,
60    },
61    StepCacheHit {
62        step_id: Uuid,
63        key: String,
64        tag: String,
65    },
66    StepEnd {
67        step_id: Uuid,
68        exit_code: i32,
69        duration_ms: u64,
70        snapshot: Option<SnapshotRef>,
71    },
72    /// Emitted when any step in a chain returns non-zero. Carries the
73    /// failing step's identity so output plugins can render a precise
74    /// diagnostic. Distinct from `StepEnd` (per-step) and `BuildEnd`
75    /// (per-run).
76    ChainFailed {
77        chain_idx: usize,
78        failed_step_id: Uuid,
79        failed_step_key: String,
80        exit_code: i32,
81        message: String,
82        ts: DateTime<Utc>,
83    },
84    BuildEnd {
85        exit_code: i32,
86        duration_ms: u64,
87    },
88}
89
90/// Compact summary of the resolved IR included in `BuildStart`. Lets
91/// output formatters print a header without needing the full pipeline.
92#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
93pub struct PlanSummary {
94    pub step_count: usize,
95    pub chain_count: usize,
96    pub default_runner: String,
97}