Skip to main content

cosh_tools/plan/
types.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4/// Input for `plan_todo_write`: the full desired TODO list, replacing the
5/// previous one.
6#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
7pub struct TodoWriteInput {
8    pub todos: Vec<TodoItemInput>,
9}
10
11/// One task as submitted by the model in a `plan_todo_write` call.
12#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
13pub struct TodoItemInput {
14    /// Optional alias other tasks in this same call reference in
15    /// `depends_on`; resolved to the assigned `task-N` id.
16    pub key: Option<String>,
17    pub description: String,
18    /// Defaults to `pending` when omitted.
19    #[serde(default = "default_status")]
20    pub status: TodoStatus,
21    /// Dependencies: sibling `key`s or `task-N` ids.
22    pub depends_on: Option<Vec<String>>,
23}
24
25fn default_status() -> TodoStatus {
26    TodoStatus::Pending
27}
28
29#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
30#[serde(rename_all = "snake_case")]
31pub enum TodoStatus {
32    Pending,
33    InProgress,
34    Completed,
35    Cancelled,
36}
37
38impl std::fmt::Display for TodoStatus {
39    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        f.write_str(match self {
41            TodoStatus::Pending => "pending",
42            TodoStatus::InProgress => "in_progress",
43            TodoStatus::Completed => "completed",
44            TodoStatus::Cancelled => "cancelled",
45        })
46    }
47}
48
49/// One task in the flat TODO list.
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct TodoItem {
52    pub id: String,
53    pub description: String,
54    pub status: TodoStatus,
55    pub depends_on: Vec<String>,
56}
57
58/// The full mutable state of the todo system: a flat list of tasks.
59#[derive(Debug, Clone, Default, Serialize, Deserialize)]
60pub struct TodoList {
61    pub items: Vec<TodoItem>,
62}
63
64#[derive(Debug, Clone, Serialize)]
65pub struct Nag {
66    pub message: String,
67}
68
69/// Output produced by `todo_write`.
70#[derive(Debug, Clone, Serialize)]
71pub struct TodoWriteOutput {
72    pub list: TodoList,
73    pub nags: Vec<Nag>,
74}
75
76/// Error type for plan operations.
77/// Wraps human-readable error messages intended as correction prompts for the model.
78#[derive(Debug, Clone, thiserror::Error)]
79#[error("{0}")]
80pub struct PlanError(pub String);