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.
# Attachment location binding regression. All state belongs to disposable fixtures.
TAA # #[cfg(unix)]
TAA # mod binding {
TAA # use std::{fs,io::Write,path::PathBuf,process::{Command,Output,Stdio},sync::atomic::{AtomicUsize,Ordering}};
TAA # static NEXT:AtomicUsize=AtomicUsize::new(0);
TAA # struct Fixture { root:PathBuf }
TAA # impl Fixture {
TAA # fn new()->Self {let root=std::env::temp_dir().join(format!("icbind-{}-{}",std::process::id(),NEXT.fetch_add(1,Ordering::Relaxed)));fs::create_dir(&root).unwrap();fs::create_dir(root.join("stage")).unwrap();fs::write(root.join("stage/release.bin"),b"fixture").unwrap();Self{root}}
TAA # fn run(&self,args:&[&str],input:&str)->Output {let mut c=Command::new(env!("CARGO_BIN_EXE_instinct"));for(k,_)in std::env::vars_os(){if k.to_string_lossy().starts_with("INSTINCT_"){c.env_remove(k);}}let mut child=c.args(args).current_dir(&self.root).env("HOME",&self.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()).ok();child.wait_with_output().unwrap()}
TAA # fn bank(&self,name:&str)->String {let o=self.run(&["bank","--store",name,"--title","Bound inventory","--when","check staged artifact membership","--found","Unexpected entries cause failure","--how","Compare approved names","--evidence","Synthetic binding control"],"");assert!(o.status.success(),"{:?}",o);String::from_utf8(o.stdout).unwrap().split_whitespace().nth(1).unwrap().to_owned()}
TAA # fn attach(&self,name:&str,id:&str)->Output {self.run(&["check","attach","--store",name,"--lesson",id,"--input","-"],r#"{"schema":"instinct.artifact-policy/v1","allowed":["release.bin"]}"#)}
TAA # fn hit(&self,name:&str,id:&str)->Output {self.run(&["hit",id,"--store",name,"--check","--root",self.root.join("stage").to_str().unwrap(),"--trusted-staging","--outcome-id","binding-probe"],"")}
TAA # }
TAA # impl Drop for Fixture {fn drop(&mut self){let _=fs::remove_dir_all(&self.root);}}
TAA # #[test]
TAA # fn copied_attachment_requires_explicit_reattach_to_destination_bank(){let f=Fixture::new();let id=f.bank("a.jsonl");assert_eq!(id,f.bank("b.jsonl"));assert!(f.attach("a.jsonl",&id).status.success());fs::copy(f.root.join("a.jsonl.capabilities.hxdb"),f.root.join("b.jsonl.capabilities.hxdb")).unwrap();let before=fs::read(f.root.join("b.jsonl")).unwrap();let refused=f.hit("b.jsonl",&id);assert!(!refused.status.success(),"copied attachment accepted: {:?}",refused);assert_eq!(fs::read(f.root.join("b.jsonl")).unwrap(),before);assert!(String::from_utf8_lossy(&refused.stderr).contains("bank binding"));assert!(f.attach("b.jsonl",&id).status.success());assert!(f.hit("b.jsonl",&id).status.success());assert!(f.hit("a.jsonl",&id).status.success());}
TAA # #[test]
TAA # fn relative_and_absolute_spellings_share_bank_binding(){let f=Fixture::new();let id=f.bank("bank.jsonl");assert!(f.attach("./bank.jsonl",&id).status.success());let bank=f.root.join("bank.jsonl");assert!(f.hit(bank.to_str().unwrap(),&id).status.success());}
TAA # #[test]
TAA # fn moved_bank_keeps_plain_feedback_but_requires_reattach_for_checked_hits(){let f=Fixture::new();let id=f.bank("old.jsonl");assert!(f.attach("old.jsonl",&id).status.success());fs::rename(f.root.join("old.jsonl"),f.root.join("moved.jsonl")).unwrap();fs::rename(f.root.join("old.jsonl.capabilities.hxdb"),f.root.join("moved.jsonl.capabilities.hxdb")).unwrap();assert!(f.run(&["hit",&id,"--store","moved.jsonl","--outcome-id","ordinary"],"").status.success());let refused=f.hit("moved.jsonl",&id);assert!(!refused.status.success());let message=String::from_utf8_lossy(&refused.stderr);assert!(message.contains("instinct check attach --lesson")&&message.contains("--store 'moved.jsonl' --input -"),"{message}");assert!(f.attach("moved.jsonl",&id).status.success());assert!(f.hit("moved.jsonl",&id).status.success());}
TAA # #[test]
TAA # fn symlink_alias_rename_preserves_target_binding(){let f=Fixture::new();let id=f.bank("target.jsonl");std::os::unix::fs::symlink("target.jsonl",f.root.join("alias.jsonl")).unwrap();assert!(f.attach("alias.jsonl",&id).status.success());fs::rename(f.root.join("alias.jsonl"),f.root.join("alias-new.jsonl")).unwrap();fs::rename(f.root.join("alias.jsonl.capabilities.hxdb"),f.root.join("alias-new.jsonl.capabilities.hxdb")).unwrap();assert!(f.hit("alias-new.jsonl",&id).status.success());}
TAA # #[test]
TAA # fn detach_preserves_history_blocks_future_checks_and_reattaches(){let f=Fixture::new();let id=f.bank("bank.jsonl");assert!(f.attach("bank.jsonl",&id).status.success());assert!(f.hit("bank.jsonl",&id).status.success());let bank=fs::read(f.root.join("bank.jsonl")).unwrap();let side=f.root.join("bank.jsonl.capabilities.hxdb");let before=fs::read(&side).unwrap();let args=["check","detach","--store","bank.jsonl","--lesson",&id];let detached=f.run(&args,"");assert!(detached.status.success(),"{detached:?}");let after=fs::read(&side).unwrap();assert!(after.starts_with(&before)&&after.len()>before.len());assert_eq!(bank,fs::read(f.root.join("bank.jsonl")).unwrap());assert!(!f.hit("bank.jsonl",&id).status.success());assert!(f.run(&args,"").status.success());assert_eq!(after,fs::read(&side).unwrap());assert!(f.run(&["hit",&id,"--store","bank.jsonl","--outcome-id","plain-after-detach"],"").status.success());assert!(f.attach("bank.jsonl",&id).status.success());let checked=f.run(&["hit",&id,"--store","bank.jsonl","--check","--root",f.root.join("stage").to_str().unwrap(),"--trusted-staging","--outcome-id","reattached"],"");assert!(checked.status.success(),"{checked:?}");let export=f.run(&["export","--store",side.to_str().unwrap()],"");let text=String::from_utf8(export.stdout).unwrap();assert_eq!(text.lines().count(),3);assert!(text.lines().last().unwrap().contains("\"revision\":3"));}
TAA # #[test]
TAA # fn detach_requires_explicit_options_and_does_not_create_an_attachment(){let f=Fixture::new();let id=f.bank("bank.jsonl");for args in [vec!["check","detach","--lesson",&id],vec!["check","detach","--store","bank.jsonl"],vec!["check","detach","--store","bank.jsonl","--lesson",&id,"--root","/tmp"]]{assert!(!f.run(&args,"").status.success());}assert!(f.run(&["check","detach","--store","bank.jsonl","--lesson",&id],"").status.success());assert!(!f.root.join("bank.jsonl.capabilities.hxdb").exists());}
TAA # #[test]
TAA # fn detach_rejects_foreign_binding_without_mutation(){let f=Fixture::new();let id=f.bank("a.jsonl");assert_eq!(id,f.bank("b.jsonl"));assert!(f.attach("a.jsonl",&id).status.success());fs::copy(f.root.join("a.jsonl.capabilities.hxdb"),f.root.join("b.jsonl.capabilities.hxdb")).unwrap();let side=f.root.join("b.jsonl.capabilities.hxdb");let before=fs::read(&side).unwrap();let out=f.run(&["check","detach","--lesson",&id,"--store","b.jsonl"],"");assert!(!out.status.success());assert!(String::from_utf8_lossy(&out.stdout).contains("bank binding"),"{out:?}");assert_eq!(before,fs::read(side).unwrap());}
TAA # #[test]
TAA # fn detach_unknown_lesson_and_duplicate_options_write_no_sidecar(){let f=Fixture::new();let id=f.bank("bank.jsonl");for args in [vec!["check","detach","--lesson","in-unknown","--store","bank.jsonl"],vec!["check","detach","--lesson",&id,"--lesson",&id,"--store","bank.jsonl"],vec!["check","detach","--lesson",&id,"--store","bank.jsonl","--store","bank.jsonl"]]{assert!(!f.run(&args,"").status.success());}assert!(!f.root.join("bank.jsonl.capabilities.hxdb").exists());}
TAA # #[test]
TAA # fn concurrent_detach_appends_one_revocation(){let f=Fixture::new();let id=f.bank("bank.jsonl");assert!(f.attach("bank.jsonl",&id).status.success());std::thread::scope(|scope|{let jobs:Vec<_>=(0..8).map(|_|scope.spawn(||f.run(&["check","detach","--lesson",&id,"--store","bank.jsonl"],""))).collect();for job in jobs{let out=job.join().unwrap();assert!(out.status.success(),"{out:?}");}});let export=f.run(&["export","--store",f.root.join("bank.jsonl.capabilities.hxdb").to_str().unwrap()],"");assert!(export.status.success());let text=String::from_utf8(export.stdout).unwrap();assert_eq!(text.lines().count(),2);assert!(!f.hit("bank.jsonl",&id).status.success());}
TAA # #[test]
TAA # fn revoking_one_lesson_keeps_another_attachment_active(){let f=Fixture::new();let id=f.bank("bank.jsonl");let other=f.run(&["bank","--store","bank.jsonl","--title","Other policy","--when","check a different staging inventory","--found","Names are bounded","--how","Compare approved names","--evidence","Synthetic"],"");assert!(other.status.success());let other=String::from_utf8(other.stdout).unwrap().split_whitespace().nth(1).unwrap().to_owned();assert_ne!(id,other);assert!(f.attach("bank.jsonl",&id).status.success());assert!(f.attach("bank.jsonl",&other).status.success());assert!(f.run(&["check","detach","--store","bank.jsonl","--lesson",&id],"").status.success());assert!(!f.hit("bank.jsonl",&id).status.success());assert!(f.hit("bank.jsonl",&other).status.success());}
TAA # #[test]
TAA # fn missing_bank_binding_requires_reattach(){let f=Fixture::new();let id=f.bank("bank.jsonl");assert!(f.attach("bank.jsonl",&id).status.success());let side=f.root.join("bank.jsonl.capabilities.hxdb");let exported=f.run(&["export","--store",side.to_str().unwrap()],"");assert!(exported.status.success());let raw=String::from_utf8(exported.stdout).unwrap();let mut result=String::new();for line in raw.lines(){let marker="\"bank_binding\":\"";if let Some(start)=line.find(marker){let end=start+marker.len()+line[start+marker.len()..].find('"').unwrap()+1;let (start,end)=if line.as_bytes().get(end)==Some(&b','){(start,end+1)}else{(start-1,end)};result.push_str(&format!("{}{}\n",&line[..start],&line[end..]));}else{result.push_str(line);result.push('\n');}}let source=f.root.join("legacy.jsonl");// CLI migration accepts bank-shaped records; attachment reader tolerates the extra fixture kind.
TAA # let result=result.lines().map(|line|format!("{{\"kind\":\"fixture\",{}\n",&line[1..])).collect::<String>();fs::write(&source,result).unwrap();fs::remove_file(&side).unwrap();assert!(f.run(&["migrate","--store",source.to_str().unwrap(),"--to",side.to_str().unwrap()],"").status.success());let refused=f.hit("bank.jsonl",&id);assert!(!refused.status.success());assert!(f.attach("bank.jsonl",&id).status.success());assert!(f.hit("bank.jsonl",&id).status.success());}
TAA # }