Skip to main content

soma_application/
context.rs

1use soma_domain::{AuthorizationMode, Confirmation, Principal, RequestId, Surface, TraceContext};
2
3/// Per-request execution context threaded through the application layer,
4/// carrying caller identity, authorization mode, surface, and limits.
5#[derive(Debug, Clone)]
6pub struct ExecutionContext {
7    /// Authenticated caller, or `None` when no principal is attached.
8    pub principal: Option<Principal>,
9    /// How authorization is enforced for this request.
10    pub authorization_mode: AuthorizationMode,
11    /// Surface (MCP, REST, CLI, ...) the request arrived on.
12    pub surface: Surface,
13    /// Inbound distributed-trace context, when propagated.
14    pub trace: Option<TraceContext>,
15    /// Whether the caller supplied confirmation for destructive actions.
16    pub destructive_confirmation: Confirmation,
17    /// Optional cap on the response payload size.
18    pub response_limit: Option<usize>,
19    /// Unique identifier for this request.
20    pub request_id: RequestId,
21}
22
23impl ExecutionContext {
24    /// Builds a loopback-dev context with no principal and no limits, for
25    /// trusted local calls where auth is bypassed.
26    pub fn loopback(surface: Surface, request_id: RequestId) -> Self {
27        Self {
28            principal: None,
29            authorization_mode: AuthorizationMode::LoopbackDev,
30            surface,
31            trace: None,
32            destructive_confirmation: Confirmation::Missing,
33            response_limit: None,
34            request_id,
35        }
36    }
37}