openmoat 0.24.0

Policy checks for AI coding agents: decides allow, defer, review or deny for each tool call the hook of Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot CLI and seven more agents reports, configures Claude Code's, Codex's and Cursor's own OS sandboxes from the same policy, and keeps a local audit log.
//! Refuse hook input accidentally delivered to the home screen.

use std::io::Read as _;

pub(super) fn detected() -> bool {
    let stdin = std::io::stdin();
    if crate::terminal::interactive() {
        return false;
    }
    let mut input = String::new();
    // Bound the home screen's input just like guard input. A truncated or
    // unreadable stream must not turn an accidental hook into success.
    if stdin
        .take(1024 * 1024 + 1)
        .read_to_string(&mut input)
        .is_err()
        || input.len() > 1024 * 1024
    {
        return true;
    }
    serde_json::from_str::<serde_json::Value>(&input).is_ok_and(|value| {
        value
            .as_object()
            .is_some_and(|v| v.contains_key("hook_event_name"))
    })
}