a3s_code_core/agent_api/
governance_facade.rs1use super::*;
2
3impl AgentSession {
4 pub fn set_budget_guard(
14 &self,
15 guard: Option<Arc<dyn crate::budget::BudgetGuard>>,
16 ) -> crate::error::Result<()> {
17 self.close_handle.mutate_immediate(|| {
18 let mut slot = self
19 .runtime_budget_guard
20 .lock()
21 .unwrap_or_else(|p| p.into_inner());
22 *slot = guard;
23 drop(slot);
24 self.refresh_task_delegation_tools();
29 self.refresh_skill_tools();
30 })
31 }
32
33 pub fn budget_guard(&self) -> Option<Arc<dyn crate::budget::BudgetGuard>> {
36 self.runtime_budget_guard
37 .lock()
38 .unwrap_or_else(|p| p.into_inner())
39 .clone()
40 }
41
42 pub async fn pending_confirmations(&self) -> Vec<PendingConfirmationInfo> {
44 HitlControl::from_session(self)
45 .pending_confirmations()
46 .await
47 }
48
49 pub async fn confirm_tool_use(
54 &self,
55 tool_id: &str,
56 approved: bool,
57 reason: Option<String>,
58 ) -> Result<bool> {
59 HitlControl::from_session(self)
60 .confirm_tool_use(tool_id, approved, reason)
61 .await
62 }
63
64 pub async fn cancel_confirmations(&self) -> usize {
66 HitlControl::from_session(self).cancel_confirmations().await
67 }
68
69 pub fn verification_reports(&self) -> Vec<crate::verification::VerificationReport> {
71 VerificationRuntime::from_session(self).reports()
72 }
73
74 pub fn verification_summary(&self) -> crate::verification::VerificationSummary {
76 VerificationRuntime::from_session(self).summary()
77 }
78
79 pub fn verification_summary_text(&self) -> String {
81 VerificationRuntime::from_session(self).summary_text()
82 }
83
84 pub fn record_verification_reports(
86 &self,
87 reports: impl IntoIterator<Item = crate::verification::VerificationReport>,
88 ) {
89 VerificationRuntime::from_session(self).record(reports);
90 }
91
92 pub fn register_hook(&self, hook: crate::hooks::Hook) -> crate::error::Result<()> {
94 self.close_handle
95 .mutate_immediate(|| HookControl::from_session(self).register_hook(hook))
96 }
97
98 pub fn unregister_hook(
100 &self,
101 hook_id: &str,
102 ) -> crate::error::Result<Option<crate::hooks::Hook>> {
103 self.close_handle
104 .mutate_immediate(|| HookControl::from_session(self).unregister_hook(hook_id))
105 }
106
107 pub fn register_hook_handler(
109 &self,
110 hook_id: &str,
111 handler: Arc<dyn crate::hooks::HookHandler>,
112 ) -> crate::error::Result<()> {
113 self.close_handle.mutate_immediate(|| {
114 HookControl::from_session(self).register_hook_handler(hook_id, handler)
115 })
116 }
117
118 pub fn unregister_hook_handler(&self, hook_id: &str) -> crate::error::Result<()> {
120 self.close_handle
121 .mutate_immediate(|| HookControl::from_session(self).unregister_hook_handler(hook_id))
122 }
123
124 pub fn hook_count(&self) -> usize {
126 HookControl::from_session(self).hook_count()
127 }
128
129 pub async fn verify_commands(
131 &self,
132 subject: &str,
133 commands: &[crate::verification::VerificationCommand],
134 ) -> Result<crate::verification::VerificationReport> {
135 VerificationRuntime::from_session(self)
136 .verify_commands(subject, commands)
137 .await
138 }
139
140 pub fn verification_presets(&self) -> Vec<crate::verification::VerificationPreset> {
142 VerificationRuntime::from_session(self).presets()
143 }
144}