Skip to main content

muse_code_sdk/msp/method/
task.rs

1// @generated from the MSP stable schema and protocol sources; do not edit by hand.
2
3use crate::msp::method::turn::CommandStatus;
4use crate::msp::view::item_content::BackgroundInitiator;
5use serde::Deserialize;
6use serde::Deserializer;
7use serde::Serialize;
8use serde::Serializer;
9
10mod catch_all;
11
12/// `task/background` params: durably send a running foreground tool task to the
13/// background.
14#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
15#[serde(rename_all = "camelCase")]
16pub struct TaskBackgroundParams {
17    /// The target session.
18    pub session_id: String,
19    /// The idempotency handle (UUIDv7).
20    pub command_id: String,
21    /// The task to background, exactly as the view names it: the `toolCall`
22    /// item's `itemId` IS the task id.
23    pub task_id: String,
24}
25
26/// `task/stop` params: stop one named background task. Required target, never
27/// "whichever is loudest" — is the blanket verb.
28#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
29#[serde(rename_all = "camelCase")]
30pub struct TaskStopParams {
31    /// The target session.
32    pub session_id: String,
33    /// The idempotency handle (UUIDv7).
34    pub command_id: String,
35    /// The task to stop, the `toolCall` item's `itemId`.
36    pub task_id: String,
37}
38
39/// `task/stopAll` params: stop every stoppable background workload live at
40/// admission.
41#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
42#[serde(rename_all = "camelCase")]
43pub struct TaskStopAllParams {
44    /// The target session.
45    pub session_id: String,
46    /// The idempotency handle (UUIDv7).
47    pub command_id: String,
48}
49
50/// The `task/background` / `task/stop` ack: admission-only, echoing the
51/// targeted task.
52#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
53#[serde(rename_all = "camelCase")]
54#[non_exhaustive]
55pub struct TaskCommandResult {
56    /// Echoes the client's id.
57    pub command_id: String,
58    /// Admission status.
59    pub status: CommandStatus,
60    /// Echoes the targeted task id.
61    pub task_id: String,
62}
63
64/// The `task/stopAll` ack: always `accepted`, including over an empty set — a
65/// blanket stop over nothing is a satisfied gesture. The ack deliberately
66/// carries no stopped-task list; count the kills from the view.
67#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
68#[serde(rename_all = "camelCase")]
69#[non_exhaustive]
70pub struct TaskStopAllResult {
71    /// Echoes the client's id.
72    pub command_id: String,
73    /// Admission status.
74    pub status: CommandStatus,
75}
76
77/// `task/list` params: the session whose background-task inventory to read. A
78/// read-only query in the `skill/list` mold: no `commandId`, no durable record,
79/// no view event.
80#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
81#[serde(rename_all = "camelCase")]
82pub struct TaskListParams {
83    /// The target session.
84    pub session_id: String,
85}
86
87/// `task/list` result: one row per live workload, background and foreground,
88/// oldest first; empty when nothing is running.
89#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
90#[serde(rename_all = "camelCase")]
91#[non_exhaustive]
92pub struct TaskListResult {
93    /// The session's live task rows.
94    pub tasks: Vec<TaskListEntry>,
95}
96
97/// One task inventory row. The row is the stable contract: `kind` and `status`
98/// stay open so a future state extends them without breaking clients.
99#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
100#[serde(rename_all = "camelCase")]
101#[non_exhaustive]
102pub struct TaskListEntry {
103    /// The `toolCall` item's `itemId` for item rows; the runtime registry
104    /// id for registry-only rows.
105    pub task_id: String,
106    /// What the workload is: `"tool"` or `"tool.*"` for item rows (the
107    /// recorded kind when the registry records one, else `"tool"`); the
108    /// recorded registry kind string verbatim for registry-only rows.
109    /// Open vocabulary — clients MUST ignore unknown kinds. A `String`,
110    /// not an enum: registry kind strings are unbounded.
111    pub kind: String,
112    /// `"inProgress"` — the only value at this increment, since every
113    /// listed row is non-terminal by construction.
114    pub status: TaskListStatus,
115    /// The short tool name on item-visible tool rows only; never a label,
116    /// never arguments. **Additive-optional**: absent elsewhere.
117    #[serde(skip_serializing_if = "Option::is_none")]
118    pub tool: Option<String>,
119    /// The host-known task start, RFC3339. **Additive-optional**: omitted,
120    /// never guessed, when the host does not know it.
121    #[serde(skip_serializing_if = "Option::is_none")]
122    pub started_at: Option<String>,
123    /// Who backgrounded the task, mirroring the item field.
124    /// **Additive-optional**: absent on pre-split records and
125    /// registry-only rows, never inferred.
126    #[serde(skip_serializing_if = "Option::is_none")]
127    pub background_initiator: Option<BackgroundInitiator>,
128    /// `"foreground" | "background"`. **Additive-optional**: absent means
129    /// `"background"` (only pre-change hosts omit it, and those list background
130    /// rows only); never guessed.
131    #[serde(skip_serializing_if = "Option::is_none")]
132    pub execution_mode: Option<TaskExecutionMode>,
133    /// The raw command text: the joined `toolCall` item's `command` argument
134    /// verbatim. **Additive-optional**: omitted when the row has no item or the
135    /// item carries no command. Monitors join raw — clients redact.
136    #[serde(skip_serializing_if = "Option::is_none")]
137    pub command: Option<String>,
138}
139
140/// A task row's status. Open: a future state is additive, and clients MUST
141/// ignore unknown statuses.
142#[derive(Debug, Clone, PartialEq, Eq)]
143#[non_exhaustive]
144pub enum TaskListStatus {
145    /// The workload is live; every listed row carries this today.
146    InProgress,
147    /// A value from a newer host, kept verbatim so an older client decodes the
148    /// rest of the message. Never construct it with a known word.
149    Unknown(String),
150}
151
152/// A task row's execution mode. Open: clients MUST ignore unknown modes.
153#[derive(Debug, Clone, PartialEq, Eq)]
154#[non_exhaustive]
155pub enum TaskExecutionMode {
156    /// The task holds the turn (a census counts it; the stop sweep skips it).
157    Foreground,
158    /// The task runs detached (census and sweep both cover it).
159    Background,
160    /// A mode introduced by a newer server. Preserved verbatim so an older
161    /// client keeps the unknown word instead of failing the parse. Not a v1
162    /// server-emission value, so it is excluded from the generated known-value
163    /// schema while the enum remains declared open (the `AdmissionDecision`
164    /// precedent).
165    Unknown(String),
166}
167
168impl TaskExecutionMode {
169    /// The exact wire spelling, including a future value an older
170    /// client does not understand.
171    #[must_use]
172    pub fn as_str(&self) -> &str {
173        match self {
174            Self::Foreground => "foreground",
175            Self::Background => "background",
176            Self::Unknown(value) => value,
177        }
178    }
179}
180
181impl Serialize for TaskExecutionMode {
182    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
183    where
184        S: Serializer,
185    {
186        serializer.serialize_str(self.as_str())
187    }
188}
189
190impl<'de> Deserialize<'de> for TaskExecutionMode {
191    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
192    where
193        D: Deserializer<'de>,
194    {
195        let value = String::deserialize(deserializer)?;
196        Ok(match value.as_str() {
197            "foreground" => Self::Foreground,
198            "background" => Self::Background,
199            _ => Self::Unknown(value),
200        })
201    }
202}