Skip to main content

ProjectKnowledge

Struct ProjectKnowledge 

Source
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,
    pub withheld: Vec<WithheldKnowledge>,
}

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: KnowledgeIndex

Ephemeral recall index. It is rebuilt after JSON load and never persisted, preserving the on-disk knowledge format for existing projects.

§withheld: Vec<WithheldKnowledge>

Records excluded from this read view. Never serialized or exposed by a formatter; the checked persistence path retains them without modification.

Implementations§

Source§

impl ProjectKnowledge

Source

pub fn run_memory_lifecycle( &mut self, policy: &MemoryPolicy, ) -> Result<LifecycleReport, String>

The quality lifecycle (decay, merge of near-duplicates, archival of low-confidence and stale facts). There is no count cap: knowledge grows without limit (owner decision 24.10.). Writes never run it — a pass over the whole store per write does not scale — the background cognition loop does, and reports its failures.

Source

pub fn new(project_root: &str) -> Self

Source

pub fn rebuild_index(&mut self)

Rebuilds the transient lookup tables after loading or changing facts. The maps are intentionally excluded from JSON serialization.

Source

pub fn check_contradiction( &self, category: &str, key: &str, new_value: &str, policy: &MemoryPolicy, ) -> Option<Contradiction>

Source

pub fn remember( &mut self, category: &str, key: &str, value: &str, session_id: &str, confidence: f32, policy: &MemoryPolicy, ) -> Option<Contradiction>

Source

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.

Source

pub fn add_pattern( &mut self, pattern_type: &str, description: &str, examples: Vec<String>, session_id: &str, policy: &MemoryPolicy, )

Source

pub fn remove_fact(&mut self, category: &str, key: &str) -> bool

Source§

impl ProjectKnowledge

Source

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).

Source

pub fn delivery_filter(&self) -> impl Fn(&KnowledgeFact) -> bool + '_

The delivery rule of every renderer in this file: whether a fact of this store may enter model-visible output now. It is the one function fact_served — a fact bound to sources at its write is re-authorized and left out when a source no longer admits; a fact without a binding is delivered as before and marks the call’s capture incomplete. Without protection nothing is asked (one policy read per rendering, not one per fact).

A fact is bound under the project root its writer’s request named. That is this store’s root; a request that names the project by another spelling is asked as well, so a binding is never missed by its key.

Source

pub fn format_summary(&self) -> String

Source

pub fn format_aaak(&self) -> String

Source

pub fn format_aaak_delta(&self, last_hash: Option<&str>) -> AaakDelta

Source§

impl ProjectKnowledge

Source

pub fn format_aaak_budgeted(&self, token_budget: usize) -> String

Source

pub fn format_wakeup(&self) -> String

Source

pub fn format_wakeup_top(&self, max_facts: usize) -> String

The wake-up facts block with at most max_facts facts, most salient first; empty for 0.

Source§

impl ProjectKnowledge

Source

pub fn import_facts( &mut self, incoming: Vec<KnowledgeFact>, merge: ImportMerge, session_id: &str, ) -> ImportResult

Import facts from an external source with a configurable merge strategy. Returns (added, skipped, replaced) counts.

Source

pub fn export_simple(&self) -> Vec<SimpleFactEntry>

Export current facts as a simple JSON array (community-compatible schema).

Source§

impl ProjectKnowledge

Source

pub fn add_fact(&mut self, fact: KnowledgeFact) -> bool

Return the most recent active decision-like facts for session handoff. Adds a pre-built fact, coalescing repeated observations into confirmations.

Source

pub fn recent_decisions(&self, limit: usize) -> Vec<KnowledgeFact>

Source

pub fn search_semantic(&self, query: &str, limit: usize) -> Vec<KnowledgeFact>

Keyword-based knowledge search across all facts. Serves as the API surface for semantic retrieval; currently falls back to substring matching. When the embedding model is loaded, this will use HNSW vector search instead.

Source

pub fn list_project_roots() -> Result<Vec<String>, String>

Source

pub fn load_for_admission( project_root: &str, admission: &KnowledgeAdmission, ) -> Result<Option<Self>, String>

Load one admitted, non-migrating read view for an export operation. Hidden rows are omitted from the view and never rewrite the durable store.

Source

pub fn load_for_checked_capture(project_root: &str) -> Result<Self, String>

Optional capture must not trigger legacy migration writes during a read, or replace an unreadable existing store with a newly created empty one.

Source

pub fn save(&self) -> Result<(), String>

Source

pub fn with_project_lock<T>(project_root: &str, f: impl FnOnce() -> T) -> T

Runs f while holding this project’s locks — the in-process per-hash mutex and the cross-process advisory file lock — without loading or saving the knowledge JSON itself. mutate_locked is built on this, and side-car stores that must stay consistent with the facts (today: the embedding index) call it directly so their read-modify-write is serialized against parallel remember/remove/reindex. That side-car write used to run lock-free, so concurrent callers clobbered each other’s embeddings and pruned just-stored vectors, degrading semantic recall (issue #412, a #326 follow-up).

Source

pub fn mutate_locked<T>( project_root: &str, f: impl FnOnce(&mut Self) -> T, ) -> Result<(Self, T), String>

Source

pub fn mutate_locked_with_admission<T>( project_root: &str, admission: &KnowledgeAdmission, f: impl FnOnce(&mut Self) -> T, ) -> Result<(Self, T), String>

Source

pub fn load(project_root: &str) -> Option<Self>

Source

pub fn load_or_create(project_root: &str) -> Self

Source

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

Source

pub fn recall(&self, query: &str) -> Vec<&KnowledgeFact>

Source

pub fn recall_for_task(&self, task: &str) -> Vec<&KnowledgeFact>

Recall for a free-text task description (overview, sub-agent briefing).

Unlike Self::recall, which serves an explicit knowledge query, a task sentence is mostly framing: “Inspect alpha parser header validation.” shares only “inspect” with an unrelated fact about deployments, and that single word used to be enough to present the fact as relevant (#1832). Only the task’s content words are matched, tokenized the way the index is, so a task made of nothing but generic words recalls nothing.

Source

pub fn recall_by_category(&self, category: &str) -> Vec<&KnowledgeFact>

Source

pub fn recall_at_time( &self, query: &str, at: DateTime<Utc>, ) -> Vec<&KnowledgeFact>

Source

pub fn timeline(&self, category: &str) -> Vec<&KnowledgeFact>

Source

pub fn list_rooms(&self) -> Vec<(String, usize)>

Source

pub fn recall_for_output( &mut self, query: &str, limit: usize, ) -> (Vec<KnowledgeFact>, usize)

Source

pub fn recall_by_category_for_output( &mut self, category: &str, limit: usize, ) -> (Vec<KnowledgeFact>, usize)

Source§

impl ProjectKnowledge

Source

pub fn admit_sources(self) -> Self

Trait Implementations§

Source§

impl Clone for ProjectKnowledge

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProjectKnowledge

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ProjectKnowledge

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ProjectKnowledge

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more