provenance: env var based tagging via POC_PROVENANCE
upsert() now checks POC_PROVENANCE env var for provenance label, falling back to Manual. This lets external callers (Claude sessions, scripts) tag writes without needing to use the internal upsert_provenance() API. Add from_env() and from_label() to Provenance for parsing.
This commit is contained in:
parent
d3075dc235
commit
5e78e5be3f
2 changed files with 30 additions and 1 deletions
|
|
@ -29,8 +29,12 @@ impl Store {
|
|||
|
||||
/// Upsert a node: update if exists (and content changed), create if not.
|
||||
/// Returns: "created", "updated", or "unchanged".
|
||||
///
|
||||
/// Provenance is determined by the POC_PROVENANCE env var if set,
|
||||
/// otherwise defaults to Manual.
|
||||
pub fn upsert(&mut self, key: &str, content: &str) -> Result<&'static str, String> {
|
||||
self.upsert_provenance(key, content, Provenance::Manual)
|
||||
let prov = Provenance::from_env().unwrap_or(Provenance::Manual);
|
||||
self.upsert_provenance(key, content, prov)
|
||||
}
|
||||
|
||||
/// Upsert with explicit provenance (for agent-created nodes).
|
||||
|
|
|
|||
|
|
@ -248,6 +248,31 @@ pub enum Provenance {
|
|||
}
|
||||
|
||||
impl Provenance {
|
||||
/// Parse from POC_PROVENANCE env var. Returns None if unset.
|
||||
pub fn from_env() -> Option<Self> {
|
||||
std::env::var("POC_PROVENANCE").ok().and_then(|s| Self::from_label(&s))
|
||||
}
|
||||
|
||||
pub fn from_label(s: &str) -> Option<Self> {
|
||||
Some(match s {
|
||||
"manual" => Self::Manual,
|
||||
"journal" => Self::Journal,
|
||||
"agent" => Self::Agent,
|
||||
"dream" => Self::Dream,
|
||||
"derived" => Self::Derived,
|
||||
"agent:experience-mine" => Self::AgentExperienceMine,
|
||||
"agent:knowledge-observation"=> Self::AgentKnowledgeObservation,
|
||||
"agent:knowledge-pattern" => Self::AgentKnowledgePattern,
|
||||
"agent:knowledge-connector" => Self::AgentKnowledgeConnector,
|
||||
"agent:knowledge-challenger" => Self::AgentKnowledgeChallenger,
|
||||
"agent:consolidate" => Self::AgentConsolidate,
|
||||
"agent:digest" => Self::AgentDigest,
|
||||
"agent:fact-mine" => Self::AgentFactMine,
|
||||
"agent:decay" => Self::AgentDecay,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn label(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Manual => "manual",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue