Skip to main content

eval_magic/sandbox/
mod.rs

1//! Execution sandbox: shared write-guard machinery and write-boundary policy.
2//!
3//! The hook entry points are hidden subcommands on this binary (see `cli`), so
4//! the installed PreToolUse hook invokes `eval-magic guard <marker>`,
5//! `eval-magic guard-codex <marker>`, or the generic
6//! `eval-magic guard-hook --harness <name> <marker>` — no separate hook script
7//! to ship or locate. Each harness's hook path, matcher, and verdict shape are
8//! descriptor data rendered by the generic engine (`crate::adapters::guard`);
9//! this module holds the shared marker/manifest/teardown machinery and the
10//! boundary policy.
11
12pub mod decide;
13mod git_command;
14pub mod guard;
15pub mod install;
16pub mod policy;
17mod shell_targets;
18
19pub(crate) use decide::marker_is_armed;
20pub use decide::{GuardDecision, GuardMarker, decide};
21pub(crate) use guard::GuardDenialRecord;
22pub(crate) use guard::parse_tool_call;
23pub use guard::read_marker;
24pub(crate) use install::{GUARD_DENIALS_DIR, GUARD_DENIALS_LOG, guard_is_armed};
25pub use install::{GUARD_MANIFEST, GUARD_MARKER, teardown_guard};
26pub use policy::{classify_bash, is_shell_tool, is_under, is_under_any, is_write_tool, path_arg};
27
28use std::time::{SystemTime, UNIX_EPOCH};
29
30/// Current wall clock in epoch milliseconds. chrono ships without its `clock`
31/// feature (it parses timestamps but never reads the clock), so the time comes
32/// from `std::time`. Shared by the guard's expiry check and marker stamping.
33pub(crate) fn now_ms() -> i64 {
34    SystemTime::now()
35        .duration_since(UNIX_EPOCH)
36        .unwrap_or_default()
37        .as_millis() as i64
38}