From 5e78e5be3f22b72ff37fe05ab788ba6aad92d295 Mon Sep 17 00:00:00 2001 From: ProofOfConcept Date: Fri, 6 Mar 2026 21:42:39 -0500 Subject: [PATCH] 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. --- src/store/ops.rs | 6 +++++- src/store/types.rs | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/store/ops.rs b/src/store/ops.rs index 987bec5..28459c5 100644 --- a/src/store/ops.rs +++ b/src/store/ops.rs @@ -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). diff --git a/src/store/types.rs b/src/store/types.rs index c87b03b..5a73ac6 100644 --- a/src/store/types.rs +++ b/src/store/types.rs @@ -248,6 +248,31 @@ pub enum Provenance { } impl Provenance { + /// Parse from POC_PROVENANCE env var. Returns None if unset. + pub fn from_env() -> Option { + std::env::var("POC_PROVENANCE").ok().and_then(|s| Self::from_label(&s)) + } + + pub fn from_label(s: &str) -> Option { + 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",