1pub mod dispatch;
8pub mod footer;
9pub mod parser;
10pub mod rules;
11
12use crate::context::AppContext;
13use crate::protocol::Response;
14use crate::sandbox_spawn::{native_sandbox_enforced, AuthenticatedPrincipal};
15
16pub trait RewriteRule: Send + Sync {
19 fn name(&self) -> &'static str;
20 fn matches(&self, command: &str) -> bool;
21 fn rewrite(
22 &self,
23 command: &str,
24 session_id: Option<&str>,
25 ctx: &AppContext,
26 ) -> Result<Response, String>;
27}
28
29pub fn try_rewrite(
33 command: &str,
34 session_id: Option<&str>,
35 ctx: &AppContext,
36 principal: &AuthenticatedPrincipal,
37) -> Option<Response> {
38 if native_sandbox_enforced(ctx, principal) {
39 return None;
40 }
41 dispatch::dispatch(command, session_id, ctx)
42}