1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use super::*;
impl AgentSession {
/// Install or replace a runtime budget guard. Takes effect on the
/// next `send` / `stream` call (the guard is consulted at agent-
/// loop build time, not on the live execution). Setting `None`
/// clears the override so `config.budget_guard` takes over again.
///
/// This is the entry point SDKs use to wire a host-supplied guard
/// after the session has already been constructed — useful when
/// the guard's transport (e.g. a JS callable) cannot live inside
/// the value-typed `SessionOptions`.
pub fn set_budget_guard(
&self,
guard: Option<Arc<dyn crate::budget::BudgetGuard>>,
) -> crate::error::Result<()> {
self.close_handle.mutate_immediate(|| {
let mut slot = self
.runtime_budget_guard
.lock()
.unwrap_or_else(|p| p.into_inner());
*slot = guard;
drop(slot);
// Delegated children own a pre-built TaskExecutor. Refresh its parent
// context so the next run cannot bypass a runtime-installed ledger.
// SkillTool likewise owns a child AgentConfig captured at registration
// time, so it must be refreshed from the same runtime source of truth.
self.refresh_task_delegation_tools();
self.refresh_skill_tools();
})
}
/// Return the currently-installed runtime budget guard, if any.
/// `None` means the loop falls back to `config.budget_guard`.
pub fn budget_guard(&self) -> Option<Arc<dyn crate::budget::BudgetGuard>> {
self.runtime_budget_guard
.lock()
.unwrap_or_else(|p| p.into_inner())
.clone()
}
/// Return pending HITL tool confirmations for this session.
pub async fn pending_confirmations(&self) -> Vec<PendingConfirmationInfo> {
HitlControl::from_session(self)
.pending_confirmations()
.await
}
/// Resolve a pending HITL tool confirmation.
///
/// Returns `Ok(true)` when a pending confirmation was found and completed,
/// `Ok(false)` when the tool ID is not pending or HITL is not configured.
pub async fn confirm_tool_use(
&self,
tool_id: &str,
approved: bool,
reason: Option<String>,
) -> Result<bool> {
HitlControl::from_session(self)
.confirm_tool_use(tool_id, approved, reason)
.await
}
/// Cancel all pending HITL confirmations for this session.
pub async fn cancel_confirmations(&self) -> usize {
HitlControl::from_session(self).cancel_confirmations().await
}
/// Return structured verification reports recorded for this session.
pub fn verification_reports(&self) -> Vec<crate::verification::VerificationReport> {
VerificationRuntime::from_session(self).reports()
}
/// Return a structured summary of all verification reports recorded for this session.
pub fn verification_summary(&self) -> crate::verification::VerificationSummary {
VerificationRuntime::from_session(self).summary()
}
/// Return a concise human-readable verification summary for this session.
pub fn verification_summary_text(&self) -> String {
VerificationRuntime::from_session(self).summary_text()
}
/// Add externally produced verification reports to this session's completion evidence.
pub fn record_verification_reports(
&self,
reports: impl IntoIterator<Item = crate::verification::VerificationReport>,
) {
VerificationRuntime::from_session(self).record(reports);
}
/// Register a hook for lifecycle event interception.
pub fn register_hook(&self, hook: crate::hooks::Hook) -> crate::error::Result<()> {
self.close_handle
.mutate_immediate(|| HookControl::from_session(self).register_hook(hook))
}
/// Unregister a hook by ID.
pub fn unregister_hook(
&self,
hook_id: &str,
) -> crate::error::Result<Option<crate::hooks::Hook>> {
self.close_handle
.mutate_immediate(|| HookControl::from_session(self).unregister_hook(hook_id))
}
/// Register a handler for a specific hook.
pub fn register_hook_handler(
&self,
hook_id: &str,
handler: Arc<dyn crate::hooks::HookHandler>,
) -> crate::error::Result<()> {
self.close_handle.mutate_immediate(|| {
HookControl::from_session(self).register_hook_handler(hook_id, handler)
})
}
/// Unregister a hook handler by hook ID.
pub fn unregister_hook_handler(&self, hook_id: &str) -> crate::error::Result<()> {
self.close_handle
.mutate_immediate(|| HookControl::from_session(self).unregister_hook_handler(hook_id))
}
/// Get the number of registered hooks.
pub fn hook_count(&self) -> usize {
HookControl::from_session(self).hook_count()
}
/// Run verification commands through the session's tool execution path.
pub async fn verify_commands(
&self,
subject: &str,
commands: &[crate::verification::VerificationCommand],
) -> Result<crate::verification::VerificationReport> {
VerificationRuntime::from_session(self)
.verify_commands(subject, commands)
.await
}
/// Return project-aware verification command presets for this workspace.
pub fn verification_presets(&self) -> Vec<crate::verification::VerificationPreset> {
VerificationRuntime::from_session(self).presets()
}
}