pub struct ProjectKnowledge {
pub project_root: String,
pub project_hash: String,
pub facts: Vec<KnowledgeFact>,
pub patterns: Vec<ProjectPattern>,
pub history: Vec<ConsolidatedInsight>,
pub updated_at: DateTime<Utc>,
pub judged_pairs: Vec<JudgedPair>,
pub index: KnowledgeIndex,
}Fields§
§project_root: String§project_hash: String§facts: Vec<KnowledgeFact>§patterns: Vec<ProjectPattern>§history: Vec<ConsolidatedInsight>§updated_at: DateTime<Utc>§judged_pairs: Vec<JudgedPair>§index: KnowledgeIndexEphemeral recall index. It is rebuilt after JSON load and never persisted, preserving the on-disk knowledge format for existing projects.
Implementations§
Source§impl ProjectKnowledge
impl ProjectKnowledge
pub fn run_memory_lifecycle( &mut self, policy: &MemoryPolicy, ) -> Result<LifecycleReport, String>
Sourcepub fn compact_low_value_clusters(&mut self, policy: &MemoryPolicy) -> u32
pub fn compact_low_value_clusters(&mut self, policy: &MemoryPolicy) -> u32
Cluster compaction (#971): collapse piles of low-value, mutually-similar
facts into recoverable digests, returning the number of clusters
collapsed. Heavier than Self::run_memory_lifecycle, so it runs only
from the background cognition loop (hourly), never on every write. The
originals are archived and rehydrate on recall — nothing is lost.
pub fn new(project_root: &str) -> Self
Sourcepub fn rebuild_index(&mut self)
pub fn rebuild_index(&mut self)
Rebuilds the transient lookup tables after loading or changing facts. The maps are intentionally excluded from JSON serialization.
pub fn check_contradiction( &self, category: &str, key: &str, new_value: &str, policy: &MemoryPolicy, ) -> Option<Contradiction>
pub fn remember( &mut self, category: &str, key: &str, value: &str, session_id: &str, confidence: f32, policy: &MemoryPolicy, ) -> Option<Contradiction>
Sourcepub fn remember_admitted(
&mut self,
category: &str,
key: &str,
value: &str,
session_id: &str,
confidence: f32,
policy: &MemoryPolicy,
) -> AdmissionResult
pub fn remember_admitted( &mut self, category: &str, key: &str, value: &str, session_id: &str, confidence: f32, policy: &MemoryPolicy, ) -> AdmissionResult
Write-time admission gate for the agent-facing ctx_knowledge remember
path (#970). Unlike Self::remember (which every internal restorer also
calls), this enforces the crate::core::memory_policy::AdmissionPolicy:
near-duplicates are merged instead of inserted, and low-salience noise is
kept out of the capped store — so eviction never has to drop a good fact to
make room for a paraphrase. Internal callers (archive rehydrate, cognition
auto-promotion) keep using Self::remember and are never gated.
pub fn add_pattern( &mut self, pattern_type: &str, description: &str, examples: Vec<String>, session_id: &str, policy: &MemoryPolicy, )
pub fn remove_fact(&mut self, category: &str, key: &str) -> bool
Source§impl ProjectKnowledge
impl ProjectKnowledge
Sourcepub fn consolidate(
&mut self,
summary: &str,
session_ids: Vec<String>,
policy: &MemoryPolicy,
) -> Result<usize, String>
pub fn consolidate( &mut self, summary: &str, session_ids: Vec<String>, policy: &MemoryPolicy, ) -> Result<usize, String>
Record one consolidated insight, then losslessly reclaim history to its capacity headroom. Returns the number of older insights archived (0 when under cap).
pub fn format_summary(&self) -> String
pub fn format_aaak(&self) -> String
pub fn format_aaak_delta(&self, last_hash: Option<&str>) -> AaakDelta
pub fn format_aaak_budgeted(&self, token_budget: usize) -> String
pub fn format_wakeup(&self) -> String
Source§impl ProjectKnowledge
impl ProjectKnowledge
Sourcepub fn import_facts(
&mut self,
incoming: Vec<KnowledgeFact>,
merge: ImportMerge,
session_id: &str,
policy: &MemoryPolicy,
) -> ImportResult
pub fn import_facts( &mut self, incoming: Vec<KnowledgeFact>, merge: ImportMerge, session_id: &str, policy: &MemoryPolicy, ) -> ImportResult
Import facts from an external source with a configurable merge strategy. Returns (added, skipped, replaced) counts.
Sourcepub fn export_simple(&self) -> Vec<SimpleFactEntry>
pub fn export_simple(&self) -> Vec<SimpleFactEntry>
Export current facts as a simple JSON array (community-compatible schema).
Source§impl ProjectKnowledge
impl ProjectKnowledge
pub fn list_project_roots() -> Result<Vec<String>, String>
pub fn save(&self) -> Result<(), String>
Sourcepub fn mutate_locked<T>(
project_root: &str,
f: impl FnOnce(&mut Self) -> T,
) -> Result<(Self, T), String>
pub fn mutate_locked<T>( project_root: &str, f: impl FnOnce(&mut Self) -> T, ) -> Result<(Self, T), String>
Runs a read-modify-write cycle under with_project_lock, then saves
atomically. The knowledge is (re)loaded inside the lock so
the closure always operates on the latest on-disk state; this is what
prevents lost updates when several remember calls run in parallel —
whether as threads in one process (parallel MCP calls) or as separate
processes (parallel CLI invocations, CLI + daemon + MCP server) — see
issue #326. Returns the persisted knowledge plus the closure’s return
value so the caller can build a response from the committed state.
pub fn load(project_root: &str) -> Option<Self>
pub fn load_or_create(project_root: &str) -> Self
Sourcepub fn migrate_legacy_empty_root(
target_root: &str,
policy: &MemoryPolicy,
) -> Result<bool, String>
pub fn migrate_legacy_empty_root( target_root: &str, policy: &MemoryPolicy, ) -> Result<bool, String>
Migrates legacy knowledge that was accidentally stored under an empty project_root (“”)
into the given target_root. Keeps a timestamped backup of the legacy file.
Source§impl ProjectKnowledge
impl ProjectKnowledge
pub fn recall(&self, query: &str) -> Vec<&KnowledgeFact>
pub fn recall_by_category(&self, category: &str) -> Vec<&KnowledgeFact>
pub fn recall_at_time( &self, query: &str, at: DateTime<Utc>, ) -> Vec<&KnowledgeFact>
pub fn timeline(&self, category: &str) -> Vec<&KnowledgeFact>
pub fn list_rooms(&self) -> Vec<(String, usize)>
pub fn recall_for_output( &mut self, query: &str, limit: usize, ) -> (Vec<KnowledgeFact>, usize)
pub fn recall_by_category_for_output( &mut self, category: &str, limit: usize, ) -> (Vec<KnowledgeFact>, usize)
Trait Implementations§
Source§impl Clone for ProjectKnowledge
impl Clone for ProjectKnowledge
Source§fn clone(&self) -> ProjectKnowledge
fn clone(&self) -> ProjectKnowledge
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ProjectKnowledge
impl Debug for ProjectKnowledge
Source§impl<'de> Deserialize<'de> for ProjectKnowledge
impl<'de> Deserialize<'de> for ProjectKnowledge
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ProjectKnowledge
impl RefUnwindSafe for ProjectKnowledge
impl Send for ProjectKnowledge
impl Sync for ProjectKnowledge
impl Unpin for ProjectKnowledge
impl UnsafeUnpin for ProjectKnowledge
impl UnwindSafe for ProjectKnowledge
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more