openmoat 0.12.1

Policy checks for AI coding agents: decides allow, defer, ask or deny for every tool call from Claude Code, Codex, Cursor, OpenClaw, GitHub Copilot CLI, pi and Gemini CLI, 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"))
    })
}