Skip to main content

envoy/task/
mod.rs

1pub mod store;
2
3use std::str::FromStr;
4
5use serde::{Deserialize, Serialize};
6
7pub const KIND_TASK: &str = "EnvoyTask";
8
9impl FromStr for TaskState {
10    type Err = crate::error::EnvoyError;
11
12    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
13        match s {
14            "proposed" => Ok(Self::Proposed),
15            "claimed" => Ok(Self::Claimed),
16            "in_progress" => Ok(Self::InProgress),
17            "waiting_review" => Ok(Self::WaitingReview),
18            "done" => Ok(Self::Done),
19            _ => Err(crate::error::EnvoyError::InvalidMessage(format!(
20                "unknown state: {}",
21                s
22            ))),
23        }
24    }
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
28#[serde(rename_all = "snake_case")]
29pub enum TaskState {
30    Proposed,
31    Claimed,
32    InProgress,
33    WaitingReview,
34    Done,
35}
36
37impl TaskState {
38    pub fn as_str(&self) -> &'static str {
39        match self {
40            Self::Proposed => "proposed",
41            Self::Claimed => "claimed",
42            Self::InProgress => "in_progress",
43            Self::WaitingReview => "waiting_review",
44            Self::Done => "done",
45        }
46    }
47
48    pub fn can_transition_to(&self, next: &TaskState) -> bool {
49        matches!(
50            (self, next),
51            (Self::Proposed, Self::Claimed)
52                | (Self::Claimed, Self::InProgress)
53                | (Self::Claimed, Self::Proposed)
54                | (Self::InProgress, Self::WaitingReview)
55                | (Self::InProgress, Self::Proposed)
56                | (Self::WaitingReview, Self::Done)
57                | (Self::WaitingReview, Self::InProgress)
58                | (Self::Done, _)
59        )
60    }
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct Task {
65    pub id: String,
66    pub project: String,
67    pub description: String,
68    pub state: TaskState,
69    pub claimed_by: Option<String>,
70    pub blocked_by: Vec<String>,
71    pub checkpoint: Option<String>,
72    pub created_at: String,
73    pub updated_at: String,
74}
75
76#[derive(Debug, Deserialize)]
77pub struct ProposeTaskRequest {
78    pub project: String,
79    pub description: String,
80    #[serde(default)]
81    pub blocked_by: Vec<String>,
82}
83
84#[derive(Debug, Deserialize)]
85pub struct ClaimTaskRequest {
86    pub agent_id: String,
87}
88
89#[derive(Debug, Deserialize)]
90pub struct ClaimNextRequest {
91    pub agent_id: String,
92    pub project: String,
93}
94
95#[derive(Debug, Deserialize)]
96pub struct UpdateTaskStateRequest {
97    pub state: String,
98    #[serde(default)]
99    pub checkpoint: Option<String>,
100}