Skip to main content

muse_code_sdk/msp/view/approval/
decision.rs

1// @generated from the MSP stable schema and protocol sources; do not edit by hand.
2
3use super::ApprovalStageResolution;
4use crate::msp::error::ApprovalRequirementRef;
5use serde::Deserialize;
6use serde::Serialize;
7
8/// One option the server offers for deciding an approval. Clients pick one and
9/// send its `choiceId` in `approval/decide`; they never build their own.
10#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11#[serde(rename_all = "camelCase")]
12#[non_exhaustive]
13pub struct ApprovalChoice {
14    /// The id to send as `choiceId` in `approval/decide`. The set of ids is
15    /// open, so show `label` and do not base behavior on specific ids.
16    pub choice_id: String,
17    /// The human-readable label to show for this choice.
18    pub label: String,
19    /// The decision this choice applies, so a client can act on approve or
20    /// reject without knowing choice ids.
21    pub decision: ApprovalDecision,
22    /// The grant duration this choice declares: `once` (this request only),
23    /// `session` (the rest of the session) or `localPersistent` (saved in the
24    /// local policy store).
25    pub scope: ApprovalChoiceScope,
26    /// A human-readable preview of what this choice grants, such as the policy
27    /// rule it would create; show it exactly as given.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub rule_preview: Option<String>,
30    /// `true` when this choice takes optional `feedback` text in
31    /// `approval/decide`, which reaches the model as guidance. Omitted when
32    /// `false`.
33    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
34    pub accepts_feedback: bool,
35}
36
37/// The kind of decision a choice applies or an approval received. The set is
38/// open, so newer hosts may send values this version does not list.
39#[derive(Debug, Clone, PartialEq, Eq)]
40#[non_exhaustive]
41pub enum ApprovalDecision {
42    /// `approved`: the action may run this once; nothing is remembered.
43    Approved,
44    /// `approvedForSession`: the action is approved, and matching requests are
45    /// approved automatically for the rest of the session.
46    ApprovedForSession,
47    /// `approvedPolicyAmendment`: the action is approved and an allow rule is
48    /// added to policy; the choice's `scope`, or the resolution's `amendment`,
49    /// says how long the rule lasts.
50    ApprovedPolicyAmendment,
51    /// `denied`: the action is denied and does not run; no rule is saved.
52    Denied,
53    /// `deniedPolicyAmendment`: the action is denied and a deny rule is added
54    /// to policy.
55    DeniedPolicyAmendment,
56    /// `timedOut`: no decision arrived in time, and the action does not run.
57    TimedOut,
58    /// `abort`: the action was rejected and does not run. It is the decision
59    /// behind the reject choice, a turn interrupt, and cleanup after a host
60    /// restart.
61    Abort,
62    /// A value from a newer host, kept verbatim so an older client decodes the
63    /// rest of the message. Excluded from the generated schema while the enum
64    /// stays declared open; never construct it with a known word.
65    Unknown(String),
66}
67
68/// How long a grant made by a choice lasts. The set is open, so newer hosts may
69/// send other values.
70#[derive(Debug, Clone, PartialEq, Eq)]
71#[non_exhaustive]
72pub enum ApprovalChoiceScope {
73    /// `once`: the choice applies to this request only.
74    Once,
75    /// `session`: the choice creates a rule that applies for the rest of the
76    /// session.
77    Session,
78    /// `localPersistent`: the choice creates a rule saved in the local policy
79    /// store, which lasts beyond this session.
80    LocalPersistent,
81    /// A value from a newer host, kept verbatim so an older client decodes the
82    /// rest of the message. Excluded from the generated schema while the enum
83    /// stays declared open; never construct it with a known word.
84    Unknown(String),
85}
86
87/// The change an `approval/updated` event reports. `kind` says what happened,
88/// and only the fields for that kind are present.
89#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
90#[serde(rename_all = "camelCase")]
91#[non_exhaustive]
92pub struct ApprovalChange {
93    /// What happened: for example `stageResolved` (a shell stage was
94    /// satisfied), `policyPersistence` (saving a rule succeeded or failed),
95    /// `reviewStarted` or `reviewCompleted` (the automated LLM judge started or
96    /// finished reviewing), `restartRecovered` (a host restart recovered this
97    /// approval: either the host first resolves it `abort` and a re-ask comes
98    /// as a new approval with a new `approvalId`, or it stays pending under
99    /// the same `approvalId` with refreshed choices) or `alreadyTerminal`
100    /// (recovery found it already decided). The set is open, so newer hosts
101    /// may add kinds.
102    pub kind: String,
103    /// The stage requirement that was satisfied. Present only when `kind` is
104    /// `stageResolved`.
105    #[serde(skip_serializing_if = "Option::is_none")]
106    pub requirement_id: Option<ApprovalRequirementRef>,
107    /// The `choiceId` that satisfied the stage. Present only when `kind` is
108    /// `stageResolved`.
109    #[serde(skip_serializing_if = "Option::is_none")]
110    pub choice_id: Option<String>,
111    /// The decision the chosen option applied to the stage. Present only when
112    /// `kind` is `stageResolved`.
113    #[serde(skip_serializing_if = "Option::is_none")]
114    pub decision: Option<ApprovalDecision>,
115    /// Whether saving the policy rule succeeded or failed; present only when
116    /// `kind` is `policyPersistence`. A failure does not undo the decision;
117    /// only the saved rule is missing.
118    #[serde(skip_serializing_if = "Option::is_none")]
119    pub status: Option<ApprovalPersistenceStatus>,
120    /// Why saving the policy rule failed, as human-readable text. Present only
121    /// when `kind` is `policyPersistence` and `status` is `failed`.
122    #[serde(skip_serializing_if = "Option::is_none")]
123    pub reason: Option<String>,
124    /// A recovery detail: whether the command was re-parsed during recovery.
125    /// Present only when `kind` is `restartRecovered`.
126    #[serde(skip_serializing_if = "Option::is_none")]
127    pub reparsed: Option<bool>,
128    /// A recovery detail: whether the action could run without a new decision.
129    /// Present only when `kind` is `restartRecovered`.
130    #[serde(skip_serializing_if = "Option::is_none")]
131    pub executable: Option<bool>,
132}
133
134/// The result of saving a granted rule to the local policy store. The set is
135/// open, so newer hosts may send other values.
136#[derive(Debug, Clone, PartialEq, Eq)]
137#[non_exhaustive]
138pub enum ApprovalPersistenceStatus {
139    /// `succeeded`: the rule was saved.
140    Succeeded,
141    /// `failed`: the rule could not be saved, though the decision still stands.
142    /// See `reason`.
143    Failed,
144    /// A value from a newer host, kept verbatim so an older client decodes the
145    /// rest of the message. Excluded from the generated schema while the enum
146    /// stays declared open; never construct it with a known word.
147    Unknown(String),
148}
149
150/// Whether an approval's final decision lets the action run. The set is open,
151/// so newer hosts may send other values.
152#[derive(Debug, Clone, PartialEq, Eq)]
153#[non_exhaustive]
154pub enum ApprovalPolicyResult {
155    /// `allow`: the action may run.
156    Allow,
157    /// `deny`: the action is blocked.
158    Deny,
159    /// A value from a newer host, kept verbatim so an older client decodes the
160    /// rest of the message. Excluded from the generated schema while the enum
161    /// stays declared open; never construct it with a known word.
162    Unknown(String),
163}
164
165/// The policy rule a decision created, in display form; the full rule is not
166/// included.
167#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
168#[serde(rename_all = "camelCase")]
169#[non_exhaustive]
170pub struct ApprovalAmendment {
171    /// How long the rule lasts: `session` or `localPersistent`.
172    pub durability: ApprovalAmendmentDurability,
173    /// A human-readable preview of the rule, for display.
174    pub rule_preview: String,
175}
176
177/// How long a rule created by an approval decision lasts. The set is open, so
178/// newer hosts may send other values.
179#[derive(Debug, Clone, PartialEq, Eq)]
180#[non_exhaustive]
181pub enum ApprovalAmendmentDurability {
182    /// `session`: the rule applies for the rest of this session.
183    Session,
184    /// `localPersistent`: the rule is saved in the local policy store and lasts
185    /// beyond this session.
186    LocalPersistent,
187    /// A value from a newer host, kept verbatim so an older client decodes the
188    /// rest of the message. Excluded from the generated schema while the enum
189    /// stays declared open; never construct it with a known word.
190    Unknown(String),
191}
192
193/// Who or what made an approval's final decision. The set is open, so newer
194/// hosts may send other values.
195#[derive(Debug, Clone, PartialEq, Eq)]
196#[non_exhaustive]
197pub enum ApprovalResolvedBy {
198    /// `user`: decided neither by policy nor by the LLM judge: a person's
199    /// `approval/decide` or turn interrupt, or cleanup after a host restart.
200    User,
201    /// `policy`: policy decided automatically, for example by denying the
202    /// action when no one can be asked.
203    Policy,
204    /// `llmJudge`: the automated LLM judge decided.
205    LlmJudge,
206    /// A value from a newer host, kept verbatim so an older client decodes the
207    /// rest of the message. Excluded from the generated schema while the enum
208    /// stays declared open; never construct it with a known word.
209    Unknown(String),
210}
211
212/// How one stage of a `shell` approval was resolved when the decision became
213/// final.
214#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
215#[serde(rename_all = "camelCase")]
216#[non_exhaustive]
217pub struct ApprovalStageEvidence {
218    /// The stage's requirement id.
219    pub requirement_id: ApprovalRequirementRef,
220    /// The stage's 1-based position in the command.
221    pub position: usize,
222    /// The total number of stages in the command.
223    pub total_stages: usize,
224    /// The stage's command words as parsed.
225    pub argv: Vec<String>,
226    /// How the stage was resolved at the final decision.
227    pub resolution: ApprovalStageResolution,
228}