Skip to main content

machi_workflow/
run.rs

1//! Workflow outcomes.
2
3use serde::{Deserialize, Serialize};
4
5/// Why a workflow paused.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(rename_all = "snake_case")]
8#[non_exhaustive]
9pub enum PauseKind {
10    /// Waiting on the user.
11    User,
12    /// Temporary backoff.
13    BackOff,
14    /// No progress detected by script.
15    NoProgress,
16    /// Verification / input missing.
17    Verification,
18    /// Infrastructure issue.
19    Infra,
20}
21
22impl PauseKind {
23    /// Stable string.
24    #[must_use]
25    pub const fn as_str(self) -> &'static str {
26        match self {
27            Self::User => "user",
28            Self::BackOff => "back_off",
29            Self::NoProgress => "no_progress",
30            Self::Verification => "verification",
31            Self::Infra => "infra",
32        }
33    }
34}
35
36/// Terminal or pausable workflow outcome.
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(tag = "outcome", rename_all = "snake_case")]
39#[non_exhaustive]
40pub enum WorkflowOutcome {
41    /// Successful completion.
42    Completed {
43        /// Script result value.
44        result: serde_json::Value,
45    },
46    /// Cooperative pause (resumable).
47    Paused {
48        /// Pause classification.
49        kind: PauseKind,
50        /// Human message.
51        message: String,
52    },
53    /// Agent budget exhausted (resumable with higher budget).
54    BudgetExceeded {
55        /// Message.
56        message: String,
57    },
58    /// Cancelled.
59    Cancelled,
60    /// Hard failure.
61    Failed {
62        /// Error text.
63        error: String,
64    },
65}