openlatch-client 0.6.13

OpenLatch runtime enforcement node — the capture-and-enforce adapter that evaluates every covered action against a coding agent's Autonomy Zone before it runs
//! Process-spawn semantics that differ between POSIX and Windows.
//!
//! The daemon runs without a console (`CREATE_NO_WINDOW`), so on Windows every
//! console program it spawns — certutil, powershell, netstat, git — gets a
//! console of its own, which flashes on the developer's desktop. Every
//! daemon-reachable spawn goes through [`no_console_window`]; a CLI-only spawn
//! inherits the terminal's console and needs nothing.

use std::process::Command;

/// `CREATE_NO_WINDOW` from the Win32 process-creation flags.
#[cfg(windows)]
const CREATE_NO_WINDOW: u32 = 0x0800_0000;

/// Start `cmd` without a console window on Windows; a no-op elsewhere. A tokio
/// `Command` passes `cmd.as_std_mut()`.
pub fn no_console_window(cmd: &mut Command) -> &mut Command {
    #[cfg(windows)]
    {
        use std::os::windows::process::CommandExt;
        cmd.creation_flags(CREATE_NO_WINDOW);
    }
    cmd
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn keeps_the_command_it_was_given() {
        let mut cmd = Command::new("certutil");
        cmd.arg("-user");
        let got = no_console_window(&mut cmd);
        assert_eq!(got.get_program(), "certutil");
        assert_eq!(got.get_args().collect::<Vec<_>>(), ["-user"]);
    }
}