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(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
13#[serde(rename_all = "snake_case")]
14pub enum StdStream {
15    Stdout,
16    Stderr,
17}
18
19#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
20#[serde(tag = "kind", rename_all = "snake_case")]
21pub enum BuildEvent {
22    BuildStart {
23        run_id: Uuid,
24        plan: PlanSummary,
25        started_at: DateTime<Utc>,
26    },
27    StepQueued {
28        step_id: Uuid,
29        key: String,
30        chain_idx: usize,
31    },
32    StepStart {
33        step_id: Uuid,
34        runner: String,
35        image: Option<String>,
36    },
37    StepLog {
38        step_id: Uuid,
39        stream: StdStream,
40        line: String,
41        ts: DateTime<Utc>,
42    },
43    StepCacheHit {
44        step_id: Uuid,
45        key: String,
46        tag: String,
47    },
48    StepEnd {
49        step_id: Uuid,
50        exit_code: i32,
51        duration_ms: u64,
52        snapshot: Option<SnapshotRef>,
53    },
54    /// Emitted when any step in a chain returns non-zero. Carries the
55    /// failing step's identity so output plugins can render a precise
56    /// diagnostic. Distinct from `StepEnd` (per-step) and `BuildEnd`
57    /// (per-run).
58    ChainFailed {
59        chain_idx: usize,
60        failed_step_id: Uuid,
61        failed_step_key: String,
62        exit_code: i32,
63        message: String,
64        ts: DateTime<Utc>,
65    },
66    BuildEnd {
67        exit_code: i32,
68        duration_ms: u64,
69    },
70}
71
72/// Compact summary of the resolved IR included in `BuildStart`. Lets
73/// output formatters print a header without needing the full pipeline.
74#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
75pub struct PlanSummary {
76    pub step_count: usize,
77    pub chain_count: usize,
78    pub default_runner: String,
79}