instinct-cli 0.3.10

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 bench/transfer.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::process::Command;
// hlx:3
use std::path::{Path,PathBuf};
// hlx:4
use std::time::Instant;
// hlx:5
fn run(cmd:&mut Command)->String {
    // hlx:6
    let out=cmd.output().expect("start command");
    // hlx:7
    assert!(out.status.success(),"command failed: {}",String::from_utf8_lossy(&out.stderr));
    // hlx:8
    String::from_utf8(out.stdout).expect("UTF-8 output").trim().to_owned()
    // hlx:9
}
// hlx:10
fn field(path:&Path,filter:&str)->String {
    // hlx:11
    run(Command::new("jq").args(["-er",filter]).arg(path))
    // hlx:12
}
// hlx:13
fn ask(route:&str,model:&str,work:&Path,prompt:&str)->String {
    // hlx:14
    let mut cmd=Command::new("timeout");
    // hlx:15
    cmd.arg("90").arg(route).current_dir(&work);
    // hlx:16
    if route=="claude" {cmd.args(["-p","--model",model,"--tools","","--settings","{\"disableAllHooks\":true}","--setting-sources","","--strict-mcp-config","--no-session-persistence"]);}else{cmd.args(["exec","--ephemeral","--ignore-user-config","--skip-git-repo-check","-s","read-only" ,"-m",model,"-c","features.shell_tool=false","-o","answer.txt"]);};
    // hlx:17
    let output=cmd.arg(prompt).output().expect("run harness");
    // hlx:18
    let answer=if !output.status.success(){{eprintln!("{}",String::from_utf8_lossy(&output.stderr)); format!("ERROR exit {}",output.status)}}else if route=="codex"{std::fs::read_to_string(work.join("answer.txt")).unwrap()}else{String::from_utf8_lossy(&output.stdout).to_string()};
    // hlx:19
    let answer=answer.trim().replace(['\n','\t']," ");
    // hlx:20
    answer
    // hlx:21
}
// hlx:22
fn main() {
    // hlx:23
    let root=PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    // hlx:24
    let engine=std::env::current_exe().unwrap().parent().unwrap().parent().unwrap().join("instinct");
    // hlx:25
    let route=std::env::args().nth(1).unwrap_or_else(||"claude".into());
    // hlx:26
    assert!(matches!(route.as_str(),"claude"|"codex"));
    // hlx:27
    let model=std::env::args().nth(2).unwrap_or_else(||if route=="claude"{"haiku".into()}else{"gpt-6.2-sol".into()});
    // hlx:28
    let work=PathBuf::from(run(Command::new("mktemp").arg("-d")));
    // hlx:29
    let mode=std::env::args().nth(3).unwrap_or_else(||"framed".into());
    // hlx:30
    assert!(matches!(mode.as_str(),"raw"|"framed"|"prepared"));
    // hlx:31
    let cases=root.join(if mode=="prepared"{"bench/fresh-cases.json"}else{"bench/cases.json"});
    // hlx:32
    let discovery=root.join("bench/discovery.json");
    // hlx:33
    let bank=|args:&[String]|run(Command::new(&engine).env_clear().env("INSTINCT_STORE",work.join("bank.jsonl")).args(args));
    // hlx:34
    let mut args=vec!["bank".to_string()];
    // hlx:35
    for key in ["title","when","found","how","evidence"] {args.extend([format!("--{key}"),field(&discovery,&format!(".{key}"))]);};
    // hlx:36
    if mode=="prepared" {args.extend(["--tags".to_string(),std::fs::read_to_string(root.join("bench/transfer-cues.txt")).unwrap()]);};
    // hlx:37
    bank(&args);
    // hlx:38
    let static_method=field(&discovery,".how");
    // hlx:39
    println!("route\tmodel\tcase\tarm\trecall_ms\tcontext_bytes\tdecision_ms\tfirst_correct\texact_pass\tanswer");
    // hlx:40
    for (index,arm) in [(0,"base"),(1,"static"),(0,"live"),(1,"base"),(0,"static"),(1,"live")] {
    // hlx:41
    let question=field(&cases,&format!(".[{index}].question"));
    // hlx:42
    let expected=field(&cases,&format!(".[{index}].key"));
    // hlx:43
    let name=field(&cases,&format!(".[{index}].name"));
    // hlx:44
    let start=Instant::now();
    // hlx:45
    let cue=if arm=="live" && mode=="framed"{ask(&route,&model,&work,&format!("Describe the underlying decision situation in one sentence and six reusable search terms from other domains. Include any condition that changes the appropriate method. Do not solve the case. Case: {question}"))}else{String::new()};
    // hlx:46
    assert!(!cue.starts_with("ERROR"),"situation extraction failed");
    // hlx:47
    let lookup=Instant::now();
    // hlx:48
    let context=match arm {"live"=>bank(&["recall".into(),"--q".into(),format!("{cue} {question}"),"--k".into(),"1".into()]),"static"=>static_method.clone(),_=>String::new()};
    // hlx:49
    let retrieval=lookup.elapsed().as_millis();
    // hlx:50
    let prompt=format!("Use only the supplied case. Optional previous experience: {context}\nCase: {question}\nReturn only the extract letter and the integer, separated by one space.");
    // hlx:51
    let answer=ask(&route,&model,&work,&prompt);
    // hlx:52
    println!("{route}\t{model}\t{name}\t{arm}\t{retrieval}\t{}\t{}\t{}\t{}\t{}",context.len(),start.elapsed().as_millis(),answer.split_whitespace().next()==expected.split_whitespace().next(),answer==expected,answer);
    // hlx:53
    };
    // hlx:54
    std::fs::remove_dir_all(work).unwrap();
    // hlx:55
}