instinct-cli 0.3.7

Shared local memory for coding agents. Save a fix once and find it again in a new session or another connected tool.
# Instinct trust rules: what counts as helped or misled, and when a lesson is quarantined. Read this one file; nothing else decides.
# Each verdict is (label, case). outcomes.rs words the evidence for a case; eval.rs lists what these rules flag. Nothing here writes.

# A lesson was acted on when it added words (novel) and the window shows at least two of them, or all of them when it added one.
AAA # pub fn acted(found: usize, novel: usize) -> bool
TAC # novel > 0 && found >= novel.min(2)
TTT # end

# Tripwire delivery: judged from the next calls after the warned one. Checked in this order, first match wins.
AAA # pub fn guard_verdict(complete: bool, repeat_failed: bool, warned_failed: Option<bool>, errors: u32, calls: u32) -> (&'static str, &'static str)
CAA # if !complete
TAC # return ("unclear", "open")
TTT # end
CAA # if repeat_failed
TAC # return ("misled", "repeat_failed")
TTT # end
CAA # if warned_failed == Some(true) && errors == 0 && calls > 0
TAC # return ("helped", "failed_once")
TTT # end
CAA # if warned_failed == Some(false) && errors == 0
TAC # return ("unused", "clean")
TTT # end
CAA # if warned_failed.is_none()
TAC # return ("unclear", "no_result")
TTT # end
TAC # ("unclear", "mixed")
TTT # end

# Prompt delivery: judged from the next user turns. Acting on a lesson and then being corrected is misled.
AAA # pub fn prompt_verdict(complete: bool, corrected: bool, acted: bool) -> (&'static str, &'static str)
CAA # if !complete
TAC # return ("unclear", "open")
TTT # end
CAA # if corrected && acted
TAC # return ("misled", "acted_then_corrected")
TTT # end
CAA # if acted
TAC # return ("helped", "acted")
TTT # end
CAA # if corrected
TAC # return ("unused", "corrected_anyway")
TTT # end
TAC # ("unused", "not_acted")
TTT # end

# Quarantine: two misses and no hit in the window, or strength that fell below 0.5 and by more than 0.15 with a miss in the window.
AAA # pub fn quarantine_reason(already: bool, hits_w: u32, misses_w: u32, hits_all: u32, misses_all: u32) -> Option<String>
CAA # if already
TAC # return None
TTT # end
CAA # if misses_w >= 2 && hits_w == 0
TAC # return Some(format!("{misses_w} misses and no hits in the window"))
TTT # end
AAC # let now = super::eligibility::strength(hits_all, misses_all)
AAC # let (h, m) = (hits_all.saturating_sub(hits_w), misses_all.saturating_sub(misses_w))
CAA # if h + m > 0 && misses_w > 0 && now < 0.5
AAC # let before = super::eligibility::strength(h, m)
CAA # if now < before - 0.15
TAC # return Some(format!("strength fell from {before:.2} to {now:.2}"))
TTT # end
TTT # end
TAC # None
TTT # end

# Near-duplicates: at least 3 shared anchor words, and 70% or more of the shorter lesson's anchors.
AAA # pub fn near_duplicate(shared: usize, shorter: usize) -> bool
TAC # shared >= 3 && shared as f64 / shorter.max(1) as f64 >= 0.7
TTT # end

# Of a duplicate pair, keep the lesson with more hits, then more deliveries, else the first listed. Returns (keep the second, why).
AAA # pub fn duplicate_keep(hits_a: u32, hits_b: u32, deliveries_a: u32, deliveries_b: u32) -> (bool, &'static str)
CAA # if hits_a != hits_b
TAC # return (hits_b > hits_a, "more hits")
TTT # end
CAA # if deliveries_a != deliveries_b
TAC # return (deliveries_b > deliveries_a, "delivered more")
TTT # end
TAC # (false, "listed first")
TTT # end