Skip to main content

agentmux_srv_core/backend/rpc/
action_commands.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Which websocket RPC commands are recorded ([`super::action_record`]), decided one
5//! by one. Every command a connection can call is in exactly one of the lists below
6//! (a test checks it against the commands a real connection registers), so a new
7//! command cannot be added without someone deciding whether it changes anything.
8
9/// Whether a call of a command is recorded.
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum Policy {
12    /// Every call, whoever makes it.
13    Always,
14    /// Calls by an agent or an unproven connection. The window's own view state
15    /// (layout, tabs, drafts, notifications) is not worth a line each time the
16    /// operator moves something; a call to it from anywhere else is.
17    UnlessOperator,
18    /// Never: it reads, or it is live input or a subscription.
19    Never,
20}
21
22/// Changes state, runs or stops a process, writes files, sends to an agent or
23/// changes who may do what. Recorded whoever calls.
24pub const ALWAYS: &[&str] = &[
25    "account.key.verify",
26    "account.oauth.cancel",
27    "account.oauth.client.clear",
28    "account.oauth.start",
29    "agent.account.switch",
30    "agent.bring-back",
31    "agent.define",
32    "agent.kill-process",
33    "agent.kill-tree",
34    "agent.model.switch",
35    "agent.move-here",
36    "agent.move-to-computer",
37    "agent.notice.decide",
38    "agent.notice.setgrant",
39    "agent.open",
40    "agent.pane.unregister",
41    "agent.prep.now",
42    "agent.send",
43    "agent.setSeat",
44    "agent.spend",
45    "agent.start",
46    "agent.stop",
47    "agent.takeover",
48    "agent:memory:adopt",
49    "agent:memory:dream_apply",
50    "agent:memory:dream_now",
51    "agent:memory:dream_reject",
52    "agent:memory:dream_revert",
53    "agent:memory:release",
54    "agent:memory:revert",
55    "agent:memory:write_file",
56    "agent:session:append_output",
57    "agent:session:archive",
58    "agent:session:write_state",
59    "agentanswer",
60    "agentcancel",
61    "agentdefcreatefromtemplate",
62    "agentdefhide",
63    "agentdefunhide",
64    "agentinput",
65    "agentlastruntime",
66    "agents.migrateForkSlugs",
67    "agentshutdownkeep",
68    "agentshutdownnow",
69    "agentstop",
70    "answerdroneapproval",
71    "app.desktop",
72    "app.upgrade-requests",
73    "app_skills.catalog.install",
74    "appendagenthistory",
75    "asksidequestion",
76    "attachments.copy-to-workdir",
77    "attachments.ingest",
78    "auth.cancel",
79    "auth.start",
80    "auth.submitcallback",
81    "browser.signin_fill",
82    "browser.signin_offer_answer",
83    "browser.signin_stop",
84    "browser.signup_password",
85    "browser_profiles.create",
86    "browser_profiles.delete",
87    "browser_profiles.update",
88    "browser_start_page.set",
89    "browsergrants.pauseall",
90    "browsergrants.permissionrevoke",
91    "browsergrants.permissionset",
92    "browsergrants.powers",
93    "browsergrants.preset",
94    "browsergrants.revoke",
95    "browsergrants.set",
96    "bundle.delete",
97    "bundle.import",
98    "bundle.import.commit",
99    "bundle.import_for_agent",
100    "bundle.upsert",
101    "clearcontainercaches",
102    "client.agreetos",
103    "connconnect",
104    "conndisconnect",
105    "connensure",
106    "connsessionend",
107    "copyforkhistory",
108    "createagent",
109    "createagentinstance",
110    "createagentskill",
111    "createeditordir",
112    "createeditorfile",
113    "createscratchfile",
114    "deleteagent",
115    "deleteagentinstance",
116    "deleteagentskill",
117    "deletedrone",
118    "deleteeditorfile",
119    "deleteidentityaccount",
120    "deletememory",
121    "deletesystemmemory",
122    "fleet.broadcast",
123    "fleet.bulk-stop",
124    "fleet.check-limits",
125    "fleet.group.create",
126    "fleet.group.delete",
127    "fleet.group.update",
128    "forkagentdefinition",
129    "fs.create",
130    "fs.delete",
131    "fs.op.cancel",
132    "fs.op.resolve",
133    "fs.op.start",
134    "fs.open",
135    "fs.rename",
136    "fs.restore",
137    "fs.trash",
138    "github.connection",
139    "github.installations",
140    "globalmemory:import",
141    "globalmemory:revert",
142    "globalmemory:set_reach",
143    "hidenamedagent",
144    "history.reclaim",
145    "identity.account.move_agents",
146    "identity.account.set_failover",
147    "identity.account.signed_in",
148    "identity.account.upsert",
149    "identity.account.validate",
150    "identity.ensureaccountdir",
151    "identity.self.unlink",
152    "importagentfromclaw",
153    "importagents",
154    "install.cancel",
155    "install.start",
156    "install.uninstall",
157    "installtool",
158    "jobs.act",
159    "jobs.reporters.add",
160    "jobs.reporters.forget",
161    "jobs.save",
162    "jobs.templates.approve",
163    "jobs.templates.catalog.install",
164    "jobs.templates.install",
165    "jobs.templates.make_drone",
166    "jobs.templates.uninstall",
167    "kanban.act",
168    "lan:firewall:setup",
169    "linkagentidentity",
170    "lspstart",
171    "lspstop",
172    "mcp.bind",
173    "mcp.catalog.bind",
174    "mcp.catalog.delete",
175    "mcp.catalog.probe",
176    "mcp.catalog.set_reach",
177    "mcp.catalog.unbind",
178    "mcp.catalog.upsert",
179    "mcp.delete",
180    "mcp.probe",
181    "mcp.unbind",
182    "mcp.upsert",
183    "memory.write",
184    "movescratchfile",
185    "muxbus.cloudconfig",
186    "muxbus.disconnect",
187    "muxbus.login",
188    "muxbus.login.cancel",
189    "openinshell",
190    "pins.adopt",
191    "pins.ask.answer",
192    "pins.forget",
193    "provider.ensureauthdir",
194    "remoteadd",
195    "remoteagentrevoke",
196    "remoteforget",
197    "remotehelperremove",
198    "remotepane.forget",
199    "remotepane.pair",
200    "remotepane.send",
201    "remotesetconfig",
202    "remotetest",
203    "renameagentdefinitiontitle",
204    "reorderglobalbrain",
205    "replaydronerun",
206    "reseedagents",
207    "resolvedronerun",
208    "resumedronewait",
209    "routeannounce",
210    "routeunannounce",
211    "runclilogin",
212    "rundrone",
213    "sensitive.decide",
214    "session:archive",
215    "session:restore",
216    "setagentbundles",
217    "setagentcontent",
218    "setconfig",
219    "setcontainerlimits",
220    "setdroneagents",
221    "shellexec",
222    "shellstop",
223    "skill.bind",
224    "skill.catalog.app_script",
225    "skill.catalog.bind",
226    "skill.catalog.bind_all",
227    "skill.catalog.bind_to_bundle",
228    "skill.catalog.delete",
229    "skill.catalog.export",
230    "skill.catalog.import_commit",
231    "skill.catalog.import_preview",
232    "skill.catalog.set_opt_out",
233    "skill.catalog.set_reach",
234    "skill.catalog.unbind",
235    "skill.catalog.unbind_from_bundle",
236    "skill.catalog.upsert",
237    "skill.catalog.upsert_for_bundle",
238    "skill.delete",
239    "skill.unbind",
240    "skill.upsert",
241    "subprocessspawn",
242    "supervisor.set-mode",
243    "toolchain.install_system_tool",
244    "toolchain.prune",
245    "tooldecision",
246    "tower.forget",
247    "tower.pair",
248    "undoagentendpoint",
249    "unlinkagentidentity",
250    "updateagent",
251    "updateagentinstance",
252    "updateagentskill",
253    "updatecontainer",
254    "upsertdrone",
255    "upsertidentityaccount",
256    "upsertmemory",
257    "upsertsystemmemory",
258    "viewer.can-send",
259    "viewer.pair-start",
260    "viewer.revoke",
261    "viewer.stop-watching",
262    "widget.api",
263    "widgets.call",
264    "widgets.catalog.install",
265    "widgets.install",
266    "widgets.rescan",
267    "widgets.session",
268    "widgets.setenabled",
269    "widgets.uninstall",
270    "workspace.importuserworkspace",
271    "writeagentconfig",
272    "writeeditorfile",
273];
274
275/// The window's own view and bookkeeping state.
276pub const UNLESS_OPERATOR: &[&str] = &[
277    "agent.input-draft",
278    "agent.input-history-append",
279    "agent.input-history-clear",
280    "agent.input-history-delete",
281    "agent.input-history-restore",
282    "agent.input-history-trash",
283    "agentquit",
284    "agentshutdown",
285    "ambientnarrate",
286    "attachments.cancel",
287    "backgroundtaskcompletion",
288    "backgroundtaskpid",
289    "block.reveal",
290    "block.revealed",
291    "blockfile:write_state",
292    "bookmarks.set",
293    "browser.session.show",
294    "browser.signin_list_close",
295    "capture.mask.report",
296    "controllerresync",
297    "createsubblock",
298    "deeplink.open.done",
299    "deletesubblock",
300    "docknodestatus",
301    "folderoverlapaccept",
302    "folderoverlapdecline",
303    "fs.reveal",
304    "fs.unwatch",
305    "fs.watch",
306    "layout.applyIntent",
307    "layout.open",
308    "layout.restoreOtherBuild",
309    "layout.save",
310    "memorydelivery:claim_fallback",
311    "notify.ack",
312    "notify.attention",
313    "notify.emit",
314    "notify.focus",
315    "notify.takeactivation",
316    "notify.test",
317    "operator.challenge",
318    "pane.activateTab",
319    "pane.confirm.decide",
320    "pane.floatplaced",
321    "pane.moveTab",
322    "pane.moveTabs",
323    "pane.open",
324    "pane.removeTab",
325    "presence.publish-now",
326    "record.page",
327    "remotepane.close",
328    "remotepane.open",
329    "setmeta",
330    "unwatcheditorfile",
331    "unwatchmediadir",
332    "viewer.agent-hidden",
333    "watcheditorfile",
334    "watchmediadir",
335    "widgets.endsession",
336];
337
338/// Terminal and language-server input and event subscriptions: live traffic, not actions.
339pub const LIVE_INPUT: &[&str] = &[
340    "agent:open_tail",
341    "controllerinput",
342    "eventsub",
343    "eventunsub",
344    "eventunsuball",
345    "lspsend",
346];
347
348/// Returns data and changes nothing.
349pub const READ_ONLY: &[&str] = &[
350    "account.oauth.client.get",
351    "account.oauth.poll",
352    "agent.input-history",
353    "agent.input-history-search",
354    "agent.list",
355    "agent.model.panel",
356    "agent.move-status",
357    "agent.notice.grants",
358    "agent.open-panes",
359    "agent.output",
360    "agent.peer-labels",
361    "agent.process-list",
362    "agent.project_instructions",
363    "agent.status",
364    "agent.tracked-blocks",
365    "agent:memory:adoption_list",
366    "agent:memory:claims",
367    "agent:memory:diff",
368    "agent:memory:dream_get",
369    "agent:memory:dreams_list",
370    "agent:memory:history",
371    "agent:memory:list",
372    "agent:memory:read_file",
373    "agent:session:list_archives",
374    "agent:session:read",
375    "agentapiretry",
376    "agentdeflisthiddentemplates",
377    "agentruntime.list",
378    "ambient.outcomes",
379    "app.update-check",
380    "app.update-status",
381    "app_skills.catalog",
382    "app_skills.here",
383    "attachments.info",
384    "audit.query",
385    "auth.poll",
386    "blockfile:line_count",
387    "blockfile:read_range",
388    "blockfile:read_state",
389    "blockstats.detail",
390    "bookmarks.list",
391    "browser_profiles.list",
392    "browsergrants.list",
393    "bundle.export",
394    "bundle.export_for_agent",
395    "bundle.export_for_agent_with_history",
396    "bundle.get",
397    "bundle.import.preview",
398    "bundle.list",
399    "bundle.self.get",
400    "bundle.validate",
401    "checkcliauth",
402    "connectivity.status",
403    "connlist",
404    "connlistaws",
405    "connsessions",
406    "containerimagecheck",
407    "containerruntimeavailable",
408    "eventreadhistory",
409    "exportagents",
410    "fileindexlines",
411    "fileprobe",
412    "filesearchbytes",
413    "filesearchtext",
414    "fleet.group.list",
415    "folderoverlapasks",
416    "folderoverlapcheck",
417    "forkagentdefinitionsuggest",
418    "fs.agent_folder",
419    "fs.git_status",
420    "fs.link_file_check",
421    "fs.list",
422    "fs.places",
423    "getagentbundles",
424    "getagentcontent",
425    "getagentinstance",
426    "getallagentcontent",
427    "getbuildslot",
428    "getclaudeglobalconfig",
429    "getcontainercaches",
430    "getcontainerlimits",
431    "getdrone",
432    "getdroneaccess",
433    "getdronepayloadschema",
434    "geteditorhome",
435    "geteditorroots",
436    "getfullconfig",
437    "getidentityaccount",
438    "getmemory",
439    "getmeta",
440    "gettoolstatus",
441    "getwaveairatelimit",
442    "globalmemory:diff",
443    "globalmemory:history",
444    "globalmemory:import_sources",
445    "globalmemory:reach_list",
446    "globalmemory:removed",
447    "globalmemory:sections",
448    "gpu.sample",
449    "history.agent_sessions",
450    "history.agents",
451    "history.locate",
452    "history.usage",
453    "identity.account.availability",
454    "identity.account.usage",
455    "identity.self.accounts",
456    "install.check",
457    "jekt.held.summary",
458    "jobs.dryrun",
459    "jobs.get",
460    "jobs.list",
461    "jobs.reporters.list",
462    "jobs.runs",
463    "jobs.templates.catalog",
464    "jobs.templates.get",
465    "jobs.templates.list",
466    "jobs.templates.update_diff",
467    "kanban.list",
468    "kanban.task",
469    "kanban.tokens",
470    "layout.otherBuilds",
471    "layout.preview",
472    "listagenthistory",
473    "listagentidentities",
474    "listagentinstances",
475    "listagents",
476    "listagentskills",
477    "listallagentidentities",
478    "listbackgroundtasks",
479    "listdroneapprovals",
480    "listdroneruns",
481    "listdrones",
482    "listeditordir",
483    "listidentityaccounts",
484    "listmemories",
485    "listnamedagents",
486    "listrecentsessions",
487    "mcp.catalog.list",
488    "mcp.catalog.list_for_agent",
489    "mcp.get",
490    "mcp.list",
491    "mcp.observed.list",
492    "memory.list",
493    "memory.read",
494    "memory:launchcost",
495    "memorydelivery:compose",
496    "muxbus.status",
497    "pins.asks",
498    "pins.list",
499    "presence.status",
500    "providers.models",
501    "reactive.registration_flags",
502    "reactive.registrations",
503    "readeditorfile",
504    "remotepane.computers",
505    "remotepane.older",
506    "remotepane.range",
507    "remoteslist",
508    "remotesshlocate",
509    "resolve.prereqs",
510    "resolvecli",
511    "searchagenthistory",
512    "session:activity_summary",
513    "session:export",
514    "session:next_prompt_suggestion",
515    "session:resume_preflight",
516    "shell.list",
517    "shellstatus",
518    "skill.catalog.app_file",
519    "skill.catalog.list",
520    "skill.catalog.list_for_agent",
521    "skill.catalog.list_for_bundle",
522    "skill.get",
523    "skill.list",
524    "swarm.other-instances",
525    "toolchain.env",
526    "toolchain.resolve_install_command",
527    "toolchain.versions",
528    "tower.peers",
529    "tower.sample",
530    "viewer.devices",
531    "viewer.watching",
532    "voice.checkPath",
533    "waveinfo",
534    "widget.health",
535    "widgets.catalog",
536    "widgets.list",
537    "widgets.readfile",
538    "widgets.requests",
539    "widgets.sectionentry",
540    "wsllist",
541];
542
543/// How `command` is recorded; `None` for a command in no list.
544pub fn policy(command: &str) -> Option<Policy> {
545    if ALWAYS.contains(&command) {
546        Some(Policy::Always)
547    } else if UNLESS_OPERATOR.contains(&command) {
548        Some(Policy::UnlessOperator)
549    } else if LIVE_INPUT.contains(&command) || READ_ONLY.contains(&command) {
550        Some(Policy::Never)
551    } else {
552        None
553    }
554}
555
556/// Commands that only read unless the request carries the named field.
557const WRITES_ONLY_WITH: &[(&str, &str)] = &[("agentlastruntime", "runtime")];
558
559/// Whether this request, of a command that can write, only reads.
560pub fn is_a_read(command: &str, data: &serde_json::Value) -> bool {
561    WRITES_ONLY_WITH
562        .iter()
563        .any(|(c, field)| *c == command && data.get(*field).map_or(true, serde_json::Value::is_null))
564}
565
566/// A command that is in no list is recorded: forgetting to decide never hides a call.
567pub fn is_recorded(command: &str, operator: bool) -> bool {
568    match policy(command) {
569        Some(Policy::Never) => false,
570        Some(Policy::UnlessOperator) => !operator,
571        Some(Policy::Always) | None => true,
572    }
573}
574
575#[cfg(test)]
576mod tests {
577    use super::*;
578
579    #[test]
580    fn a_command_is_in_one_list_only() {
581        let lists: [(&str, &[&str]); 4] =
582            [("ALWAYS", ALWAYS), ("UNLESS_OPERATOR", UNLESS_OPERATOR), ("LIVE_INPUT", LIVE_INPUT), ("READ_ONLY", READ_ONLY)];
583        let mut seen = std::collections::HashMap::new();
584        for (list, names) in lists {
585            for name in names {
586                if let Some(other) = seen.insert(*name, list) {
587                    panic!("{name} is in {other} and {list}");
588                }
589            }
590        }
591    }
592
593    /// One entry per line, in byte order: two changes to a list meet only when they add the same command.
594    #[test]
595    fn each_list_is_in_order() {
596        let lists: [(&str, &[&str]); 4] = [("ALWAYS", ALWAYS), ("UNLESS_OPERATOR", UNLESS_OPERATOR), ("LIVE_INPUT", LIVE_INPUT), ("READ_ONLY", READ_ONLY)];
597        for (list, names) in lists {
598            if let Some(pair) = names.windows(2).find(|pair| pair[0] >= pair[1]) {
599                panic!("{list} is not in order: {:?} comes before {:?}", pair[0], pair[1]);
600            }
601        }
602    }
603
604    #[test]
605    fn the_policies() {
606        assert!(is_recorded("agent.kill-tree", false) && is_recorded("agent.kill-tree", true));
607        assert!(is_recorded("setmeta", false) && !is_recorded("setmeta", true));
608        assert!(!is_recorded("listagents", false) && !is_recorded("controllerinput", false));
609        assert!(is_recorded("a-command-nobody-decided", true), "an undecided command is recorded");
610        let read = serde_json::json!({"id": "a"});
611        let write = serde_json::json!({"id": "a", "runtime": ""});
612        assert!(is_a_read("agentlastruntime", &read) && !is_a_read("agentlastruntime", &write));
613        assert!(!is_a_read("agent.send", &read));
614    }
615}