#[cfg(target_os = "linux")]
use super::{output, rules, syscall_linux};
#[cfg(target_os = "linux")]
use crate::cli::commands::monitor::MonitorArgs;
#[cfg(target_os = "linux")]
async fn maybe_enforce_violation(
event: &assay_common::MonitorEvent,
rule: &rules::ActiveRule,
kill: &rules::KillPlan,
quiet: bool,
) {
let what = if rule.event_type == assay_common::EVENT_EXEC {
"exec"
} else {
"file access"
};
output::log_violation(event.pid, &rule.id, what, quiet);
if rule.action != assay_core::mcp::runtime_features::MonitorAction::TriggerKill {
return;
}
if kill.enabled {
let mode = kill.mode_for(&rule.id);
output::log_kill(event.pid, &mode, kill.grace_period_ms, quiet);
syscall_linux::kill_pid(event.pid, mode, kill.grace_period_ms).await;
}
}
#[cfg(target_os = "linux")]
pub(crate) async fn handle_event(
event: &assay_common::MonitorEvent,
args: &MonitorArgs,
ruleset: &[rules::ActiveRule],
kill: &rules::KillPlan,
) {
if let Some(rule) = rules::find_violation_rule(event, ruleset) {
maybe_enforce_violation(event, rule, kill, args.quiet).await;
}
output::log_monitor_event(event, args);
}
pub(crate) fn observed_peer(event: &assay_common::MonitorEvent) -> Option<String> {
match event.event_type {
assay_common::EVENT_CONNECT_OBSERVED | assay_common::EVENT_CONNECT_BLOCKED => {
assay_monitor::events::decode_blocked_socket_payload(&event.data).map(|s| s.endpoint())
}
_ => None,
}
}