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), `alreadyTerminal`
100 /// (recovery found it already decided) or `resolving` (a
101 /// `computerUseTakeover` approval was marked resolving and waits for the
102 /// lock broker; a decide now answers -32059). The set is open, so newer
103 /// hosts may add kinds.
104 pub kind: String,
105 /// The stage requirement that was satisfied. Present only when `kind` is
106 /// `stageResolved`.
107 #[serde(skip_serializing_if = "Option::is_none")]
108 pub requirement_id: Option<ApprovalRequirementRef>,
109 /// The `choiceId` that satisfied the stage. Present only when `kind` is
110 /// `stageResolved`.
111 #[serde(skip_serializing_if = "Option::is_none")]
112 pub choice_id: Option<String>,
113 /// The decision the chosen option applied to the stage. Present only when
114 /// `kind` is `stageResolved`.
115 #[serde(skip_serializing_if = "Option::is_none")]
116 pub decision: Option<ApprovalDecision>,
117 /// Whether saving the policy rule succeeded or failed; present only when
118 /// `kind` is `policyPersistence`. A failure does not undo the decision;
119 /// only the saved rule is missing.
120 #[serde(skip_serializing_if = "Option::is_none")]
121 pub status: Option<ApprovalPersistenceStatus>,
122 /// Why saving the policy rule failed, as human-readable text. Present only
123 /// when `kind` is `policyPersistence` and `status` is `failed`.
124 #[serde(skip_serializing_if = "Option::is_none")]
125 pub reason: Option<String>,
126 /// A recovery detail: whether the command was re-parsed during recovery.
127 /// Present only when `kind` is `restartRecovered`.
128 #[serde(skip_serializing_if = "Option::is_none")]
129 pub reparsed: Option<bool>,
130 /// A recovery detail: whether the action could run without a new decision.
131 /// Present only when `kind` is `restartRecovered`.
132 #[serde(skip_serializing_if = "Option::is_none")]
133 pub executable: Option<bool>,
134}
135
136/// The result of saving a granted rule to the local policy store. The set is
137/// open, so newer hosts may send other values.
138#[derive(Debug, Clone, PartialEq, Eq)]
139#[non_exhaustive]
140pub enum ApprovalPersistenceStatus {
141 /// `succeeded`: the rule was saved.
142 Succeeded,
143 /// `failed`: the rule could not be saved, though the decision still stands.
144 /// See `reason`.
145 Failed,
146 /// A value from a newer host, kept verbatim so an older client decodes the
147 /// rest of the message. Excluded from the generated schema while the enum
148 /// stays declared open; never construct it with a known word.
149 Unknown(String),
150}
151
152/// Whether an approval's final decision lets the action run. The set is open,
153/// so newer hosts may send other values.
154#[derive(Debug, Clone, PartialEq, Eq)]
155#[non_exhaustive]
156pub enum ApprovalPolicyResult {
157 /// `allow`: the action may run.
158 Allow,
159 /// `deny`: the action is blocked.
160 Deny,
161 /// A value from a newer host, kept verbatim so an older client decodes the
162 /// rest of the message. Excluded from the generated schema while the enum
163 /// stays declared open; never construct it with a known word.
164 Unknown(String),
165}
166
167/// The policy rule a decision created, in display form; the full rule is not
168/// included.
169#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
170#[serde(rename_all = "camelCase")]
171#[non_exhaustive]
172pub struct ApprovalAmendment {
173 /// How long the rule lasts: `session` or `localPersistent`.
174 pub durability: ApprovalAmendmentDurability,
175 /// A human-readable preview of the rule, for display.
176 pub rule_preview: String,
177}
178
179/// How long a rule created by an approval decision lasts. The set is open, so
180/// newer hosts may send other values.
181#[derive(Debug, Clone, PartialEq, Eq)]
182#[non_exhaustive]
183pub enum ApprovalAmendmentDurability {
184 /// `session`: the rule applies for the rest of this session.
185 Session,
186 /// `localPersistent`: the rule is saved in the local policy store and lasts
187 /// beyond this session.
188 LocalPersistent,
189 /// A value from a newer host, kept verbatim so an older client decodes the
190 /// rest of the message. Excluded from the generated schema while the enum
191 /// stays declared open; never construct it with a known word.
192 Unknown(String),
193}
194
195/// Who or what made an approval's final decision. The set is open, so newer
196/// hosts may send other values.
197#[derive(Debug, Clone, PartialEq, Eq)]
198#[non_exhaustive]
199pub enum ApprovalResolvedBy {
200 /// `user`: decided neither by policy nor by the LLM judge: a person's
201 /// `approval/decide` or turn interrupt, or cleanup after a host restart.
202 User,
203 /// `policy`: policy decided automatically, for example by denying the
204 /// action when no one can be asked.
205 Policy,
206 /// `llmJudge`: the automated LLM judge decided.
207 LlmJudge,
208 /// A value from a newer host, kept verbatim so an older client decodes the
209 /// rest of the message. Excluded from the generated schema while the enum
210 /// stays declared open; never construct it with a known word.
211 Unknown(String),
212}
213
214/// How one stage of a `shell` approval was resolved when the decision became
215/// final.
216#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
217#[serde(rename_all = "camelCase")]
218#[non_exhaustive]
219pub struct ApprovalStageEvidence {
220 /// The stage's requirement id.
221 pub requirement_id: ApprovalRequirementRef,
222 /// The stage's 1-based position in the command.
223 pub position: usize,
224 /// The total number of stages in the command.
225 pub total_stages: usize,
226 /// The stage's command words as parsed.
227 pub argv: Vec<String>,
228 /// How the stage was resolved at the final decision.
229 pub resolution: ApprovalStageResolution,
230}