agentmux_srv_core/backend/rpc/
action_access.rs1pub const OPEN: &[&str] = &[
16 "app.update-check",
17 "app.update-status",
18 "eventreadhistory",
19 "eventsub",
20 "eventunsub",
21 "eventunsuball",
22 "getfullconfig",
23 "getwaveairatelimit",
24 "jobs.list",
25 "kanban.list",
26 "notify.ack",
27 "operator.challenge",
28 "presence.status",
29 "routeannounce",
30 "routeunannounce",
31 "setconfig",
32 "waveinfo",
33 "widgets.catalog",
34 "widgets.list",
35];
36
37pub const EVENT_COMMANDS: &[&str] = &[
41 "eventreadhistory",
42 "eventsub",
43];
44
45pub const OPEN_EVENTS: &[&str] = &[
47 "notification",
48 "notification:retract",
49 "notification:state",
50];
51
52pub const OWN_PANE: &[&str] = &[
55 "agentinput",
56 "agentstop",
57 "controllerresync",
58 "createsubblock",
59 "deletesubblock",
60 "setmeta",
61];
62
63pub fn is_open_for(command: &str, data: &serde_json::Value) -> bool {
66 if !OPEN.contains(&command) {
67 return false;
68 }
69 !EVENT_COMMANDS.contains(&command) || data.get("event").and_then(serde_json::Value::as_str).is_some_and(|e| OPEN_EVENTS.contains(&e))
70}
71
72pub fn is_own_pane(command: &str) -> bool {
75 OWN_PANE.contains(&command)
76}
77
78#[cfg(test)]
79mod tests {
80 use super::*;
81 use crate::backend::rpc::action_commands::{ALWAYS, LIVE_INPUT, READ_ONLY, UNLESS_OPERATOR};
82
83 #[test]
84 fn the_lists_name_commands_that_are_decided_and_do_not_overlap() {
85 let decided: std::collections::HashSet<&str> =
86 [ALWAYS, UNLESS_OPERATOR, LIVE_INPUT, READ_ONLY].iter().flat_map(|l| l.iter().copied()).collect();
87 for name in OPEN.iter().chain(OWN_PANE) {
88 assert!(decided.contains(name), "{name} is in no list of action_commands.rs");
90 }
91 for name in OWN_PANE {
92 assert!(!OPEN.contains(name), "{name} is in OPEN and OWN_PANE");
93 }
94 for name in EVENT_COMMANDS {
95 assert!(OPEN.contains(name), "{name} names an event and is open only for OPEN_EVENTS");
96 }
97 }
98
99 #[test]
101 fn each_list_is_in_order() {
102 let lists: [(&str, &[&str]); 4] = [("OPEN", OPEN), ("EVENT_COMMANDS", EVENT_COMMANDS), ("OPEN_EVENTS", OPEN_EVENTS), ("OWN_PANE", OWN_PANE)];
103 for (list, names) in lists {
104 if let Some(pair) = names.windows(2).find(|pair| pair[0] >= pair[1]) {
105 panic!("{list} is not in order: {:?} comes before {:?}", pair[0], pair[1]);
106 }
107 }
108 }
109
110 #[test]
111 fn an_event_is_open_only_when_it_carries_nobody_elses_words() {
112 use serde_json::json;
113 for event in OPEN_EVENTS {
114 assert!(is_open_for("eventsub", &json!({"event": event, "allscopes": true})), "{event}");
115 assert!(is_open_for("eventreadhistory", &json!({"event": event, "scope": "", "maxitems": 5})), "{event}");
116 }
117 for event in ["blockfile", "userinput", "agentturn", "message-flow", "controllerstatus", "a-new-event", ""] {
119 assert!(!is_open_for("eventsub", &json!({"event": event, "allscopes": true})), "{event}");
120 assert!(!is_open_for("eventreadhistory", &json!({"event": event, "scope": ""})), "{event}");
121 }
122 assert!(!is_open_for("eventsub", &json!({})) && !is_open_for("eventsub", &serde_json::Value::Null));
123 assert!(is_open_for("eventunsub", &json!("blockfile")), "taking a subscription away reveals nothing");
124 assert!(!is_open_for("agent.kill-tree", &json!({})));
125 }
126
127 #[test]
128 fn only_the_decided_reads_are_open() {
129 for name in [
132 "agent.output", "agent:session:read", "agent:memory:read_file", "getmemory", "listrecentsessions", "session:export",
133 "agent.input-history", "getagentcontent", "bundle.export", "exportagents", "getmeta", "searchagenthistory",
134 "readeditorfile", "listeditordir", "fs.list", "fs.places", "fileprobe", "filesearchtext", "filesearchbytes",
136 "fileindexlines", "widgets.readfile",
137 ] {
138 assert!(!OPEN.contains(&name), "{name} must be the window's alone");
139 }
140 }
141}