Skip to main content

vtcode_exec_events/
tracker.rs

1//! Canonical durable contract for task-tracker checklist snapshots.
2//!
3//! Every successful `task_tracker` mutation publishes a [`TrackerSnapshot`]
4//! through [`ThreadEvent::TrackerUpdated`](crate::ThreadEvent::TrackerUpdated)
5//! so timeline consumers (desktop Tasks viewer, session archives) replay typed
6//! checklist state instead of re-parsing rendered tool output. The snapshot
7//! carries the user-facing surface only — title, progress counts, and the
8//! compact item tree — mirroring the CLI transcript/panel split; structured
9//! step metadata (`files`/`outcome`/`verify`) stays in the tool payload and
10//! the persisted tracker artifacts.
11use serde::{Deserialize, Serialize};
12use std::str::FromStr;
13
14/// Lifecycle status of one checklist item, using the canonical `task_tracker`
15/// wire strings (`pending`, `in_progress`, `completed`, `blocked`).
16#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
17#[cfg_attr(feature = "schema-export", derive(schemars::JsonSchema))]
18#[serde(rename_all = "snake_case")]
19pub enum TrackerItemStatus {
20    /// Item is queued and not started.
21    #[default]
22    Pending,
23    /// Item is actively being worked on.
24    InProgress,
25    /// Item finished successfully.
26    Completed,
27    /// Item cannot proceed without external input.
28    Blocked,
29    /// Catch-all for statuses added in newer schema versions.
30    #[serde(other)]
31    Unknown,
32}
33
34impl TrackerItemStatus {
35    /// Statuses with a canonical wire spelling (`Unknown` is a decode catch-all).
36    const KNOWN: [Self; 4] = [Self::Pending, Self::InProgress, Self::Completed, Self::Blocked];
37
38    /// Canonical wire string for this status.
39    #[must_use]
40    pub const fn as_str(self) -> &'static str {
41        match self {
42            Self::Pending => "pending",
43            Self::InProgress => "in_progress",
44            Self::Completed => "completed",
45            Self::Blocked => "blocked",
46            Self::Unknown => "unknown",
47        }
48    }
49}
50
51impl FromStr for TrackerItemStatus {
52    type Err = ();
53
54    /// Parse a canonical status string; unknown shapes fail closed to `Err`
55    /// so producers skip unparseable items instead of mislabeling them.
56    fn from_str(raw: &str) -> Result<Self, Self::Err> {
57        Self::KNOWN.into_iter().find(|status| status.as_str() == raw).ok_or(())
58    }
59}
60
61/// One checklist row in a tracker snapshot.
62#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
63#[cfg_attr(feature = "schema-export", derive(schemars::JsonSchema))]
64pub struct TrackerItemState {
65    /// Dotted (`1.2`) or flat (`1`) position of the item in the checklist.
66    pub index_path: String,
67    /// Short leading-clause description of the item.
68    pub description: String,
69    /// Lifecycle status of the item.
70    pub status: TrackerItemStatus,
71}
72
73/// Bounded checklist snapshot published after a `task_tracker` mutation.
74///
75/// `completed`/`total` always describe the full checklist even when `items`
76/// is empty (explicit counts win over derived ones, mirroring the CLI
77/// progress line). Derived views replay the newest snapshot per session.
78#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
79#[cfg_attr(feature = "schema-export", derive(schemars::JsonSchema))]
80pub struct TrackerSnapshot {
81    /// Raw checklist title; views humanize generated timestamp slugs.
82    pub title: String,
83    /// Finished items in the full checklist.
84    pub completed: usize,
85    /// Renderable items in the full checklist.
86    pub total: usize,
87    /// Item tree in checklist order. Tool-assigned index paths are unique
88    /// within a snapshot, so views may key rows on them.
89    pub items: Vec<TrackerItemState>,
90}