instinct-cli 0.3.6

Local memory for AI coding agents: an MCP server and CLI that gives Claude Code, Codex, Cursor and any MCP client the one lesson that fits. Lessons that keep failing go quiet.
// generated by hxc 1.0.0-acgt-compiler from tests/check_attach_portable.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:2
use std::{
    fs,
    io::Write,
    process::{Command, Output, Stdio},
};
// hlx:3
fn run(root: &std::path::Path, args: &[&str], input: &str) -> Output {
    let mut cmd = Command::new(env!("CARGO_BIN_EXE_instinct"));
    for (k, _) in std::env::vars_os() {
        if k.to_string_lossy().starts_with("INSTINCT_") {
            cmd.env_remove(k);
        }
    }
    let mut child = cmd
        .args(args)
        .current_dir(root)
        .env("HOME", root)
        .env("INSTINCT_STARTER", "0")
        .stdin(Stdio::piped())
        .stdout(Stdio::piped())
        .stderr(Stdio::piped())
        .spawn()
        .unwrap();
    child
        .stdin
        .take()
        .unwrap()
        .write_all(input.as_bytes())
        .unwrap();
    child.wait_with_output().unwrap()
}
// hlx:4
#[test]
// hlx:5
fn attach_validates_policy_without_observation_on_every_platform() {
    let root = std::env::temp_dir().join(format!(
        "icattach-{}-{}",
        std::process::id(),
        std::time::SystemTime::now()
            .duration_since(std::time::UNIX_EPOCH)
            .unwrap()
            .as_nanos()
    ));
    fs::create_dir(&root).unwrap();
    for store in ["bank.jsonl", "bank.hxdb"] {
        let saved = run(
            &root,
            &[
                "bank",
                "--store",
                store,
                "--title",
                "Portable attachment",
                "--when",
                "check staging inventory",
                "--found",
                "Names are bounded",
                "--how",
                "Compare explicit allowlist",
                "--evidence",
                "Synthetic",
            ],
            "",
        );
        assert!(saved.status.success(), "{saved:?}");
        let id = String::from_utf8(saved.stdout)
            .unwrap()
            .split_whitespace()
            .nth(1)
            .unwrap()
            .to_owned();
        let before = fs::read(root.join(store)).unwrap();
        let args = [
            "check", "attach", "--store", store, "--lesson", &id, "--input", "-",
        ];
        let policy = r#"{"schema":"instinct.artifact-policy/v1","allowed":[],"assumptions":{"trusted_quiescent_staging":true}}"#;
        let out = run(&root, &args, policy);
        assert!(out.status.success(), "{out:?}");
        assert_eq!(before, fs::read(root.join(store)).unwrap());
        let side = root.join(format!("{store}.capabilities.hxdb"));
        let attached = fs::read(&side).unwrap();
        let retry = run(&root, &args, policy);
        assert!(retry.status.success());
        assert!(String::from_utf8_lossy(&retry.stdout).contains("already attached"));
        assert_eq!(attached, fs::read(&side).unwrap());
        // hlx:6
        #[cfg(windows)]
        {
            let hit = run(
                &root,
                &[
                    "hit",
                    &id,
                    "--store",
                    store,
                    "--check",
                    "--trusted-staging",
                    "--root",
                    root.to_str().unwrap(),
                    "--outcome-id",
                    "unsupported",
                ],
                "",
            );
            assert!(!hit.status.success());
            assert!(String::from_utf8_lossy(&hit.stderr).contains(
                "check-verified hits are not supported on this platform; nothing recorded"
            ));
            assert_eq!(before, fs::read(root.join(store)).unwrap());
        }
        // hlx:7
    }
    fs::remove_dir_all(root).unwrap();
}
// hlx:8
#[cfg(windows)]
// hlx:9
#[test]
// hlx:10
fn windows_filesystem_roots_validate_but_noncanonical_spellings_do_not() {
    let home = std::env::temp_dir();
    for root in [
        r"C:\",
        r"C:/",
        r"\\?\C:\",
        r"\\server\share\",
        r"\\?\UNC\server\share\",
    ] {
        let out = run(
            &home,
            &["check", "observe", "--root", root, "--input", "-"],
            r#"{"schema":"instinct.artifact-policy/v1","allowed":[]}"#,
        );
        assert!(out.status.success(), "{root}: {out:?}");
        assert!(String::from_utf8_lossy(&out.stdout).contains("assumption_not_asserted"));
    }
    for root in [
        r"C:\folder\",
        r"C:\\",
        r"C:\.\",
        r"C:\..\",
        r"\\?\C:\folder\",
        r"\\?\C:\\",
        r"\\server\share\folder\",
    ] {
        let out = run(
            &home,
            &["check", "observe", "--root", root, "--input", "-"],
            r#"{"schema":"instinct.artifact-policy/v1","allowed":[]}"#,
        );
        assert!(!out.status.success(), "accepted {root}: {out:?}");
    }
}