instinct-cli 0.3.9

Shared local memory for coding agents. Save a fix once and find it again in a new session or another connected tool.
# Scoped standing instructions and counterfactual recall [GAMMA-Codon/S]
AAC # use super::{append, decision_packet, eligibility, journal, json_out, load, now_secs, Args, Json}
AAC # use std::path::PathBuf

TAG # #[derive(Clone, Debug, PartialEq)]
GCA # pub(super) struct StandingInstruction
GCC # pub(super) text: String
GCC # pub(super) reference: String
TTT # end

AAA # pub(super) fn set_default(path: &PathBuf, args: &Args, scope: &eligibility::Scope) -> Result<String, String>
AAC # let id = args.pos.first().ok_or("default requires a lesson ID")?
AAC # let project = args.opt("project").filter(|p| !p.trim().is_empty()).ok_or("default requires an explicit --project")?
CAA # if args.pos.len() != 1 || args.opt("clear").is_some_and(|s| !s.is_empty())
AAC # return Err("supply one lesson ID and use --clear without a value".into())
TTT # end
AAC # let clear = args.flag("clear")
TAC # let instruction = match (clear, args.opt("instruction"), args.opt("source-ref")) {
TAC # (true, None, None) => None,
TAC # (false, Some(text), Some(reference)) if !text.trim().is_empty() && !reference.trim().is_empty() =>
TAC # Some(StandingInstruction { text: text.trim().into(), reference: reference.trim().into() }),
TAC # _ => return Err("supply --instruction TEXT --source-ref REF together, or --clear".into()),
TAC # };
AAC # let _lock = journal::identity_lock(path)?
TAC # let lesson = load(path)?.into_iter().find(|d| d.id == *id && d.meta.project == project && d.meta.source == "banked"
TAC # && eligibility::scope_check(&d.meta, scope, now_secs()).is_ok())
TAC # .ok_or("no eligible directly banked lesson in this project and scope")?;
CAA # if lesson.standing == instruction
AAC # return Ok(format!("standing instruction already matches for {id}"))
TTT # end
TAC # let mut fields = vec![
TAC # ("kind".into(), Json::Str("standing_instruction".into())),
TAC # ("id".into(), Json::Str(id.clone())), ("ts".into(), Json::Num(now_secs() as f64)),
TAC # ("scope_project".into(), Json::Str(lesson.meta.project)), ("scope_persona".into(), Json::Str(lesson.meta.persona)),
TAC # ("action".into(), Json::Str(if clear { "clear" } else { "set" }.into())),
TAC # ];
CAA # if let Some(v) = instruction
AAC # fields.push(("instruction".into(), Json::Str(v.text)))
AAC # fields.push(("source_ref".into(), Json::Str(v.reference)))
TTT # end
AAC # append(path, &json_out(&Json::Obj(fields)))?
TAC # Ok(format!("standing instruction {} for {id}", if clear { "cleared" } else { "recorded" }))
TTT # end

# Rehearse against one scoped journal snapshot. The host interprets the changed brief.
AAA # pub(super) fn dream(path: &PathBuf, usual: &str, changed: &str, scope: &eligibility::Scope) -> Result<String, String>
CAA # if usual.trim().is_empty() || changed.trim().is_empty() || usual.trim() == changed.trim()
AAC # return Err("dream requires two different situations via --q and --changed".into())
TTT # end
AAC # let all = super::load_scoped(path, scope, now_secs())?
AAC # let docs: Vec<_> = all.iter().map(super::Discovery::lex_text).collect()
AAC # let mut cases = Vec::new()
AGA # for (name, q) in [("usual", usual), ("changed", changed)]
AAC # let methods = super::rank_methods(path, q, 2, scope, &all, |action| super::bm25(action, &docs))?
TAC # cases.push(Json::Obj(vec![
TAC # ("case".into(), Json::Str(name.into())), ("situation".into(), Json::Str(q.into())),
TAC # ("context".into(), decision_packet(&methods)),
TAC # ]));
TTT # end
TAC # Ok(json_out(&Json::Obj(vec![
TAC # ("schema".into(), Json::Str("instinct-rehearsal/1".into())), ("hypothetical".into(), Json::Bool(true)),
TAC # ("cases".into(), Json::Arr(cases)),
TAC # ])))
TTT # end