Skip to main content

objectiveai_sdk/cli/command/tasks/list/
mod.rs

1//! `tasks list` — every task, one [`ResponseItem`] per stream frame:
2//! the stored command + schedule, the run counters (a run is ERRORED
3//! iff its last stream item was an error), the last result, and the
4//! creator identity the task runs with. Completed tasks stay listed
5//! until `tasks delete`.
6
7use crate::cli::command::CommandRequest;
8
9/// The outcome of a task's most recent run.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
11#[serde(rename_all = "snake_case")]
12#[schemars(rename = "cli.command.tasks.list.LastResult")]
13pub enum LastResult {
14    Success,
15    Error,
16}
17
18#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
19#[schemars(rename = "cli.command.tasks.list.Request")]
20pub struct Request {
21    pub path_type: Path,
22    #[serde(flatten)]
23    pub base: crate::cli::command::RequestBase,
24}
25
26#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
27#[schemars(rename = "cli.command.tasks.list.Path")]
28pub enum Path {
29    #[serde(rename = "tasks/list")]
30    TasksList,
31}
32
33impl CommandRequest for Request {
34    fn request_base(&self) -> &crate::cli::command::RequestBase {
35        &self.base
36    }
37
38    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
39        Some(&mut self.base)
40    }
41}
42
43/// One task.
44// No `PartialEq`: the embedded root [`crate::cli::command::Request`]
45// doesn't derive it.
46#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
47#[schemars(rename = "cli.command.tasks.list.ResponseItem")]
48pub struct ResponseItem {
49    /// The task id (`tasks delete --id`).
50    pub id: String,
51    /// The stored command — the full typed command request. Unboxed:
52    /// unlike `create::Request`, this type is not part of the request
53    /// enum's own cycle. Schema-opaque (`serde_json::Value`) ON
54    /// PURPOSE: embedding the root request enum's schema in a leaf
55    /// transitively expands the whole command tree (TS7056) — same
56    /// reasoning as `create`. A stored row that no longer parses as
57    /// the current request type (a pre-wire-change task) surfaces as
58    /// an error ITEM in the list stream rather than a listed entry.
59    #[schemars(with = "serde_json::Value")]
60    pub command: crate::cli::command::Request,
61    /// Seconds until the (first) run / between runs.
62    pub delay_secs: u64,
63    pub repeat: bool,
64    /// Cap on SUCCESSFUL runs — absent = unbounded (or one-shot).
65    #[serde(default, skip_serializing_if = "Option::is_none")]
66    #[schemars(extend("omitempty" = true))]
67    pub repeat_count: Option<u64>,
68    /// Completed runs (at-least-once: a run lost to a daemon crash
69    /// re-fires uncounted).
70    pub run_count: u64,
71    /// Runs whose LAST stream item was an error.
72    pub error_count: u64,
73    /// The most recent run's outcome — absent when the task has never
74    /// run.
75    #[serde(default, skip_serializing_if = "Option::is_none")]
76    #[schemars(extend("omitempty" = true))]
77    pub last_result: Option<LastResult>,
78    /// The task will not fire again (one-shot that ran, or a counted
79    /// repeat whose success budget is met). Stays listed until
80    /// deleted.
81    pub complete: bool,
82    /// RFC3339 creation time.
83    pub created_at: String,
84    /// RFC3339 next fire time — absent when complete.
85    #[serde(default, skip_serializing_if = "Option::is_none")]
86    #[schemars(extend("omitempty" = true))]
87    pub next_run_at: Option<String>,
88    /// The creator identity the task runs with.
89    #[serde(default, skip_serializing_if = "Option::is_none")]
90    #[schemars(extend("omitempty" = true))]
91    pub agent_instance_hierarchy: Option<String>,
92    /// The creating plugin (owner/repository/version) — present only
93    /// when a plugin created the task.
94    #[serde(default, skip_serializing_if = "Option::is_none")]
95    #[schemars(extend("omitempty" = true))]
96    pub plugin_owner: Option<String>,
97    #[serde(default, skip_serializing_if = "Option::is_none")]
98    #[schemars(extend("omitempty" = true))]
99    pub plugin_name: Option<String>,
100    #[serde(default, skip_serializing_if = "Option::is_none")]
101    #[schemars(extend("omitempty" = true))]
102    pub plugin_version: Option<String>,
103}
104
105#[derive(clap::Args)]
106pub struct Args {
107    #[command(flatten)]
108    pub base: crate::cli::command::RequestBaseArgs,
109}
110
111#[derive(clap::Args)]
112#[command(args_conflicts_with_subcommands = true)]
113pub struct Command {
114    #[command(flatten)]
115    pub args: Args,
116    #[command(subcommand)]
117    pub schema: Option<Schema>,
118}
119
120#[derive(clap::Subcommand)]
121pub enum Schema {
122    /// Emit the JSON Schema for this leaf's `Request` type and exit.
123    RequestSchema(request_schema::Args),
124    /// Emit the JSON Schema for this leaf's `ResponseItem` type and exit.
125    ResponseSchema(response_schema::Args),
126}
127
128impl TryFrom<Args> for Request {
129    type Error = crate::cli::command::FromArgsError;
130    fn try_from(args: Args) -> Result<Self, Self::Error> {
131        Ok(Self {
132            path_type: Path::TasksList,
133            base: args.base.into(),
134        })
135    }
136}
137
138#[cfg(feature = "mcp")]
139impl crate::cli::command::CommandResponse for ResponseItem {
140    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
141        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
142    }
143}
144
145#[cfg(feature = "cli-executor")]
146pub async fn execute<E: crate::cli::command::CommandExecutor>(
147    executor: &E,
148    mut request: Request,
149    identity: Option<&crate::identity::Identity>,
150) -> Result<E::Stream<ResponseItem>, E::Error> {
151    request.base.clear_transform();
152    executor.execute(request, identity).await
153}
154
155#[cfg(feature = "cli-executor")]
156pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
157    executor: &E,
158    mut request: Request,
159    transform: crate::cli::command::Transform,
160    identity: Option<&crate::identity::Identity>,
161) -> Result<E::Stream<serde_json::Value>, E::Error> {
162    request.base.set_transform(transform);
163    executor.execute(request, identity).await
164}
165
166pub mod request_schema;
167
168pub mod response_schema;
169
170/// One `/listen` broadcast run of `tasks list`: the actual
171/// [`Request`], the producer's
172/// [`Identity`](crate::identity::Identity), and the
173/// item stream. See [`crate::daemon::command_listener`].
174#[cfg(all(feature = "cli", feature = "daemon"))]
175pub struct ListenerExecution {
176    pub request: Request,
177    pub identity: crate::identity::Identity,
178    pub response: crate::daemon::command_listener::ResponseItemStream<ResponseItem>,
179}