instinct-cli 0.3.8

Shared local memory for coding agents. Save a fix once and find it again in a new session or another connected tool.
// generated by hxc 1.0.0-acgt-compiler from src/trust.hlx -- do not edit by hand

#[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
}

// hlx:5
pub fn acted(found: usize, novel: usize) -> bool {
    // hlx:6
    novel > 0 && found >= novel.min(2)
    // hlx:7
}
// hlx:10
pub fn guard_verdict(
    complete: bool,
    repeat_failed: bool,
    warned_failed: Option<bool>,
    errors: u32,
    calls: u32,
) -> (&'static str, &'static str) {
    // hlx:11
    if !complete {
        // hlx:12
        return ("unclear", "open");
        // hlx:13
    }
    // hlx:14
    if repeat_failed {
        // hlx:15
        return ("misled", "repeat_failed");
        // hlx:16
    }
    // hlx:17
    if warned_failed == Some(true) && errors == 0 && calls > 0 {
        // hlx:18
        return ("helped", "failed_once");
        // hlx:19
    }
    // hlx:20
    if warned_failed == Some(false) && errors == 0 {
        // hlx:21
        return ("unused", "clean");
        // hlx:22
    }
    // hlx:23
    if warned_failed.is_none() {
        // hlx:24
        return ("unclear", "no_result");
        // hlx:25
    }
    // hlx:26
    ("unclear", "mixed")
    // hlx:27
}
// hlx:30
pub fn prompt_verdict(
    complete: bool,
    corrected: bool,
    acted: bool,
) -> (&'static str, &'static str) {
    // hlx:31
    if !complete {
        // hlx:32
        return ("unclear", "open");
        // hlx:33
    }
    // hlx:34
    if corrected && acted {
        // hlx:35
        return ("misled", "acted_then_corrected");
        // hlx:36
    }
    // hlx:37
    if acted {
        // hlx:38
        return ("helped", "acted");
        // hlx:39
    }
    // hlx:40
    if corrected {
        // hlx:41
        return ("unused", "corrected_anyway");
        // hlx:42
    }
    // hlx:43
    ("unused", "not_acted")
    // hlx:44
}
// hlx:47
pub fn quarantine_reason(
    already: bool,
    hits_w: u32,
    misses_w: u32,
    hits_all: u32,
    misses_all: u32,
) -> Option<String> {
    // hlx:48
    if already {
        // hlx:49
        return None;
        // hlx:50
    }
    // hlx:51
    if misses_w >= 2 && hits_w == 0 {
        // hlx:52
        return Some(format!("{misses_w} misses and no hits in the window"));
        // hlx:53
    }
    // hlx:54
    let now = super::eligibility::strength(hits_all, misses_all);
    // hlx:55
    let (h, m) = (
        hits_all.saturating_sub(hits_w),
        misses_all.saturating_sub(misses_w),
    );
    // hlx:56
    if h + m > 0 && misses_w > 0 && now < 0.5 {
        // hlx:57
        let before = super::eligibility::strength(h, m);
        // hlx:58
        if now < before - 0.15 {
            // hlx:59
            return Some(format!("strength fell from {before:.2} to {now:.2}"));
            // hlx:60
        }
        // hlx:61
    }
    // hlx:62
    None
    // hlx:63
}
// hlx:66
pub fn near_duplicate(shared: usize, shorter: usize) -> bool {
    // hlx:67
    shared >= 3 && shared as f64 / shorter.max(1) as f64 >= 0.7
    // hlx:68
}
// hlx:71
pub fn duplicate_keep(
    hits_a: u32,
    hits_b: u32,
    deliveries_a: u32,
    deliveries_b: u32,
) -> (bool, &'static str) {
    // hlx:72
    if hits_a != hits_b {
        // hlx:73
        return (hits_b > hits_a, "more hits");
        // hlx:74
    }
    // hlx:75
    if deliveries_a != deliveries_b {
        // hlx:76
        return (deliveries_b > deliveries_a, "delivered more");
        // hlx:77
    }
    // hlx:78
    (false, "listed first")
    // hlx:79
}