#[cfg(windows)]
#[allow(dead_code)]
const SYS_CURL: &str = "C:\\Windows\\System32\\curl.exe";
#[cfg(not(windows))]
#[allow(dead_code)]
const SYS_CURL: &str = "curl";
#[allow(dead_code)]
fn _helix_allowed(var: &str, what: &str) -> bool {
let ok = std::env::var(var).map(|v| v == "1").unwrap_or(false);
if !ok {
eprintln!("helix: BLOCKED {} -- permission denied (set {}=1 to allow; `hxc run` allows by default, a `hxc build`/`export-rust` binary does not)", what, var);
}
ok
}
#[cfg(windows)]
#[allow(dead_code)]
fn _nw_exec(mut c: std::process::Command) -> std::process::Command {
if !_helix_allowed("HELIX_ALLOW_RUN", "process execution") {
std::process::exit(13);
}
use std::os::windows::process::CommandExt;
c.creation_flags(0x08000000);
c
}
#[cfg(not(windows))]
#[allow(dead_code)]
fn _nw_exec(c: std::process::Command) -> std::process::Command {
if !_helix_allowed("HELIX_ALLOW_RUN", "process execution") {
std::process::exit(13);
}
c
}
#[cfg(windows)]
#[allow(dead_code)]
fn _nw_net(mut c: std::process::Command) -> std::process::Command {
if !_helix_allowed("HELIX_ALLOW_NET", "network access") {
std::process::exit(13);
}
use std::os::windows::process::CommandExt;
c.creation_flags(0x08000000);
c
}
#[cfg(not(windows))]
#[allow(dead_code)]
fn _nw_net(c: std::process::Command) -> std::process::Command {
if !_helix_allowed("HELIX_ALLOW_NET", "network access") {
std::process::exit(13);
}
c
}
pub fn acted(found: usize, novel: usize) -> bool {
novel > 0 && found >= novel.min(2)
}
pub fn guard_verdict(
complete: bool,
repeat_failed: bool,
warned_failed: Option<bool>,
errors: u32,
calls: u32,
) -> (&'static str, &'static str) {
if !complete {
return ("unclear", "open");
}
if repeat_failed {
return ("misled", "repeat_failed");
}
if warned_failed == Some(true) && errors == 0 && calls > 0 {
return ("helped", "failed_once");
}
if warned_failed == Some(false) && errors == 0 {
return ("unused", "clean");
}
if warned_failed.is_none() {
return ("unclear", "no_result");
}
("unclear", "mixed")
}
pub fn prompt_verdict(
complete: bool,
corrected: bool,
acted: bool,
) -> (&'static str, &'static str) {
if !complete {
return ("unclear", "open");
}
if corrected && acted {
return ("misled", "acted_then_corrected");
}
if acted {
return ("helped", "acted");
}
if corrected {
return ("unused", "corrected_anyway");
}
("unused", "not_acted")
}
pub fn quarantine_reason(
already: bool,
hits_w: u32,
misses_w: u32,
hits_all: u32,
misses_all: u32,
) -> Option<String> {
if already {
return None;
}
if misses_w >= 2 && hits_w == 0 {
return Some(format!("{misses_w} misses and no hits in the window"));
}
let now = super::eligibility::strength(hits_all, misses_all);
let (h, m) = (
hits_all.saturating_sub(hits_w),
misses_all.saturating_sub(misses_w),
);
if h + m > 0 && misses_w > 0 && now < 0.5 {
let before = super::eligibility::strength(h, m);
if now < before - 0.15 {
return Some(format!("strength fell from {before:.2} to {now:.2}"));
}
}
None
}
pub fn near_duplicate(shared: usize, shorter: usize) -> bool {
shared >= 3 && shared as f64 / shorter.max(1) as f64 >= 0.7
}
pub fn duplicate_keep(
hits_a: u32,
hits_b: u32,
deliveries_a: u32,
deliveries_b: u32,
) -> (bool, &'static str) {
if hits_a != hits_b {
return (hits_b > hits_a, "more hits");
}
if deliveries_a != deliveries_b {
return (deliveries_b > deliveries_a, "delivered more");
}
(false, "listed first")
}