agentmux_srv_core/backend/
shutdown_events.rs1use serde::Serialize;
9
10pub const EVENT_AGENT_SHUTDOWN: &str = "agent:shutdown";
13
14#[derive(Debug, Clone, serde::Serialize, ts_rs::TS)]
17#[ts(export, export_to = "../../../frontend/types/rpc/")]
18pub struct ShutdownLineEvent {
19 pub block_id: String,
20 #[ts(type = "number")]
21 pub seq: u64,
22 pub step: String,
23 pub text: String,
24 #[serde(flatten)]
25 pub extra: ShutdownExtra,
26}
27
28#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, ts_rs::TS)]
30#[ts(export, export_to = "../../../frontend/types/rpc/")]
31pub struct ShutdownExtra {
32 #[serde(skip_serializing_if = "Option::is_none")]
34 #[ts(optional, type = "number")]
35 pub forced_after_ms: Option<u64>,
36 #[serde(skip_serializing_if = "Option::is_none")]
38 #[ts(optional)]
39 pub error: Option<String>,
40 #[serde(skip_serializing_if = "Option::is_none")]
42 #[ts(optional)]
43 pub container: Option<String>,
44 #[serde(skip_serializing_if = "Option::is_none")]
45 #[ts(optional)]
46 pub outcome: Option<String>,
47 #[serde(skip_serializing_if = "Option::is_none")]
49 #[ts(optional)]
50 pub process: Option<ShutdownProcess>,
51}
52
53#[derive(Debug, Clone, PartialEq, serde::Serialize, ts_rs::TS)]
54#[ts(export, export_to = "../../../frontend/types/rpc/")]
55pub struct ShutdownProcess {
56 pub pid: u32,
57 pub name: String,
58 pub outcome: String,
60}
61
62pub const EVENT_SHUTDOWN_PENDING: &str = "agent:shutdown-pending";
63pub const EVENT_SHUTDOWN_PENDING_CLEARED: &str = "agent:shutdown-pending-cleared";
64
65#[derive(Clone, Debug, Serialize, PartialEq, Eq, ts_rs::TS)]
67#[ts(export, export_to = "../../../frontend/types/rpc/")]
68pub struct PendingView {
69 pub request_id: String,
70 pub block_id: String,
71 pub by: String,
73 pub target: String,
75 pub via: String,
77 pub reason: String,
80 #[ts(type = r#""stop" | "close_tab" | "close_pane""#)]
83 pub effect: &'static str,
84 #[ts(type = "number")]
85 pub deadline_ms: i64,
86 #[ts(type = r#""pending" | "kept_by_user" | "proceeding" | "shut_down" | "failed" | "superseded""#)]
89 pub status: &'static str,
90 #[serde(skip_serializing_if = "Option::is_none")]
91 #[ts(optional)]
92 pub error: Option<String>,
93 #[serde(skip_serializing_if = "Option::is_none")]
95 #[ts(optional)]
96 pub blocks: Option<Vec<BatchBlock>>,
97 #[serde(skip_serializing_if = "Option::is_none")]
100 #[ts(optional)]
101 pub outcomes: Option<Vec<BlockOutcome>>,
102 #[serde(skip)]
105 #[ts(skip)]
106 pub joined: bool,
107}
108
109#[derive(Clone, Debug, Serialize, ts_rs::TS)]
111#[ts(export, export_to = "../../../frontend/types/rpc/")]
112pub struct PendingClearedEvent {
113 pub block_id: String,
114 pub request_id: String,
115 pub outcome: String,
116}
117
118#[derive(Clone, Debug, Serialize, PartialEq, Eq, ts_rs::TS)]
120#[ts(export, export_to = "../../../frontend/types/rpc/")]
121pub struct BatchBlock {
122 pub block_id: String,
123 pub name: String,
125}
126
127#[derive(Clone, Debug, Serialize, PartialEq, Eq, ts_rs::TS)]
129#[ts(export, export_to = "../../../frontend/types/rpc/")]
130pub struct BlockOutcome {
131 pub block_id: String,
132 pub name: String,
133 #[ts(type = r#""kept_by_user" | "shut_down" | "superseded" | "failed""#)]
135 pub outcome: &'static str,
136 #[serde(skip_serializing_if = "Option::is_none")]
137 #[ts(optional)]
138 pub error: Option<String>,
139}
140
141pub const REASON_MAX: usize = 120;
143pub const REASON_HIDDEN: &str = "Reason hidden: it looks sensitive.";
146
147pub fn clean_reason(raw: &str) -> String {
154 if crate::backend::reactive::sanitize::is_sensitive_message(raw) {
155 return REASON_HIDDEN.to_string();
156 }
157 let Some(first) = raw.lines().map(str::trim).find(|l| !l.is_empty()) else {
158 return String::new();
159 };
160 clean_line(first, REASON_MAX)
161}
162
163pub const EVENT_WORKSPACE_STOP: &str = "workspace:stop";
167
168#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, ts_rs::TS)]
170#[ts(export, export_to = "../../../frontend/types/rpc/")]
171pub struct WorkspaceStopView {
172 #[ts(type = r#""pending" | "cleared""#)]
173 pub status: &'static str,
174 #[ts(type = "number")]
176 pub stop_at_ms: i64,
177 pub reason_id: String,
179 pub reason: String,
181}
182
183pub fn clean_line(raw: &str, max: usize) -> String {
186 let cleaned: String = raw
187 .chars()
188 .filter(|c| !crate::backend::notify::router::is_bidi_control(*c))
189 .map(|c| if c.is_control() { ' ' } else { c })
190 .collect();
191 let line = cleaned.split_whitespace().collect::<Vec<_>>().join(" ");
192 let mut out: String = line.chars().take(max).collect();
193 if line.chars().count() > max {
194 out.push('…');
195 }
196 out
197}