Skip to main content

coda_core/
task.rs

1//! Task types for CODA execution.
2//!
3//! Defines `Task`, `TaskResult`, and `TaskStatus` which represent the
4//! units of work in CODA's execution pipeline.
5
6use std::path::PathBuf;
7use std::time::Duration;
8
9/// A unit of work in CODA's execution pipeline.
10///
11/// Each CLI command or execution phase maps to a `Task` variant.
12#[derive(Debug, Clone)]
13#[non_exhaustive]
14pub enum Task {
15    /// Initialize a repository as a CODA project.
16    Init,
17
18    /// Plan a new feature interactively.
19    Plan {
20        /// URL-safe feature slug (e.g., `"add-user-auth"`).
21        feature_slug: String,
22    },
23
24    /// A development phase derived from the design spec's
25    /// "Development Phases" section.
26    DevPhase {
27        /// Human-readable phase name (e.g., `"pub-item-extraction"`).
28        name: String,
29        /// URL-safe feature slug.
30        feature_slug: String,
31    },
32
33    /// Review the implemented code for issues.
34    Review {
35        /// URL-safe feature slug.
36        feature_slug: String,
37    },
38
39    /// Verify the implementation against the verification plan.
40    Verify {
41        /// URL-safe feature slug.
42        feature_slug: String,
43    },
44
45    /// Create a pull request after all phases complete.
46    CreatePr {
47        /// URL-safe feature slug.
48        feature_slug: String,
49    },
50}
51
52/// Result of executing a task, extracted from SDK's `ResultMessage`.
53///
54/// Contains execution metrics (turns, cost, duration) alongside the
55/// task identity and outcome status.
56///
57/// # Examples
58///
59/// ```
60/// use std::time::Duration;
61///
62/// use coda_core::task::{Task, TaskResult, TaskStatus};
63///
64/// let result = TaskResult {
65///     task: Task::DevPhase {
66///         name: "setup-types".to_string(),
67///         feature_slug: "add-auth".to_string(),
68///     },
69///     status: TaskStatus::Completed,
70///     turns: 3,
71///     cost_usd: 0.12,
72///     duration: Duration::from_secs(300),
73///     artifacts: vec![],
74/// };
75///
76/// assert_eq!(result.turns, 3);
77/// assert!(matches!(result.status, TaskStatus::Completed));
78/// ```
79#[derive(Debug)]
80pub struct TaskResult {
81    /// The task that was executed.
82    pub task: Task,
83
84    /// Whether the task completed successfully or failed.
85    pub status: TaskStatus,
86
87    /// Number of agent conversation turns used.
88    pub turns: u32,
89
90    /// Total cost in USD from `ResultMessage.total_cost_usd`.
91    pub cost_usd: f64,
92
93    /// Wall-clock duration from `ResultMessage.duration_ms`.
94    pub duration: Duration,
95
96    /// Paths to files created or modified by this task.
97    pub artifacts: Vec<PathBuf>,
98}
99
100/// Outcome status of a task execution.
101#[derive(Debug, Clone)]
102#[non_exhaustive]
103pub enum TaskStatus {
104    /// Task completed successfully.
105    Completed,
106
107    /// Task failed with an error message.
108    Failed {
109        /// Description of what went wrong.
110        error: String,
111    },
112}