instinct-cli 0.3.0

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 tools/db-workbench.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::{
    env, fs, io,
    path::Path,
    process::Command,
    time::{SystemTime, UNIX_EPOCH},
};
// hlx:3
fn rust_source(input: &str) -> Result<String, String> {
    // hlx:4
    let mut stage = 0;
    // hlx:5
    let mut src = String::from("#![allow(dead_code)]\n");
    // hlx:6
    for (number, line) in input.lines().enumerate() {
        // hlx:7
        let line = line.trim();
        // hlx:8
        if line.is_empty() || line.starts_with('#') {
            // hlx:9
            continue;
            // hlx:10
        }
        // hlx:11
        let error = || {
            format!(
                "unsupported DB-workbench instruction at line {}: {line}",
                number + 1
            )
        };
        // hlx:12
        let (op, value) = line.split_once('#').ok_or_else(error)?;
        // hlx:13
        match (stage, op.trim(), value.trim()) {
            // hlx:14
            (0, "GGGGT", "db") => {
                src.push_str(include_str!("../runtime/helix-db.rs"));
                src.push('\n');
                stage = 1;
            }
            // hlx:15
            (1, "AAA", "fn main()") => {
                src.push_str("fn main() {\n");
                stage = 2;
            }
            // hlx:16
            (2, "AAC", stmt) if !stmt.is_empty() => {
                src.push_str(stmt);
                src.push_str(";\n");
            }
            // hlx:17
            (2, "TTT", "end") => {
                src.push_str("}\n");
                stage = 3;
            }
            // hlx:18
            _ => return Err(error()),
            // hlx:19
        }
        // hlx:20
    }
    // hlx:21
    if stage != 3 {
        // hlx:22
        return Err("expected GGGGT db and a complete fn main() block".into());
        // hlx:23
    }
    // hlx:24
    Ok(src)
    // hlx:25
}
// hlx:26
fn execute(dir: &Path, src: &str) -> io::Result<()> {
    // hlx:27
    let file = dir.join("example.rs");
    // hlx:28
    let bin = dir.join(format!("example{}", env::consts::EXE_SUFFIX));
    // hlx:29
    fs::write(&file, src)?;
    // hlx:30
    let built = Command::new(env::var_os("RUSTC").unwrap_or_else(|| "rustc".into()))
        .args(["--edition=2021", "-o"])
        .arg(&bin)
        .arg(&file)
        .status()?;
    // hlx:31
    if !built.success() {
        // hlx:32
        return Err(io::Error::other("Rust compilation failed"));
        // hlx:33
    }
    // hlx:34
    let ran = Command::new(&bin).current_dir(dir).status()?;
    // hlx:35
    if !ran.success() {
        // hlx:36
        return Err(io::Error::other("Helix DB example failed"));
        // hlx:37
    }
    // hlx:38
    Ok(())
    // hlx:39
}
// hlx:40
fn main() -> io::Result<()> {
    // hlx:41
    let path = env::args_os()
        .nth(1)
        .ok_or_else(|| io::Error::other("supply an example .hlx file"))?;
    // hlx:42
    let src = rust_source(&fs::read_to_string(path)?).map_err(io::Error::other)?;
    // hlx:43
    let stamp = SystemTime::now()
        .duration_since(UNIX_EPOCH)
        .map_err(io::Error::other)?
        .as_nanos();
    // hlx:44
    let dir = env::temp_dir().join(format!("helix-db-workbench-{}-{stamp}", std::process::id()));
    // hlx:45
    fs::create_dir(&dir)?;
    // hlx:46
    let result = execute(&dir, &src);
    // hlx:47
    fs::remove_dir_all(dir)?;
    // hlx:48
    result
    // hlx:49
}