openlatch-client 0.6.1

OpenLatch runtime enforcement node — the capture-and-enforce adapter that evaluates every covered action against a coding agent's Autonomy Zone before it runs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! Pure readers of a Linux `/proc/<pid>/stat` line, shared by OpenLatch's own daemon lifecycle
//! (`cli::commands::lifecycle`) and the third-party process table (`hooks::cline_app::process`).
//! A leaf: it reads no file and knows no caller.

/// Does a `/proc/<pid>/stat` line describe a process that has exited?
///
/// The state is the field after the command name. That name is parenthesised
/// and is whatever the process called itself — spaces and `)` included — so
/// the state is read after the **last** `)`, never by splitting on spaces.
/// `Z` is a zombie; `X` (and `x` on 2.6.33–3.13 kernels) is dead. Pure, so it
/// is tested on every host.
#[cfg_attr(not(target_os = "linux"), allow(dead_code))]
pub(crate) fn proc_stat_says_exited(stat: &str) -> bool {
    stat.rsplit_once(')')
        .and_then(|(_, rest)| rest.trim_start().chars().next())
        .is_some_and(|state| matches!(state, 'Z' | 'X' | 'x'))
}