Skip to main content

Ledger

Struct Ledger 

Source
pub struct Ledger {
    pub paths: EddaPaths,
    /* private fields */
}
Expand description

The append-only event ledger (SQLite backend).

Fields§

§paths: EddaPaths

Implementations§

Source§

impl Ledger

Source

pub fn open(repo_root: impl Into<PathBuf>) -> Result<Self>

Open an existing workspace. Fails if .edda/ does not exist.

Source

pub fn open_or_init(repo_root: impl Into<PathBuf>) -> Result<Self>

Open a workspace, auto-initializing .edda/ if missing.

Use this for read-path consumers (e.g. edda watch) that should work without requiring the user to run edda init first.

This is a lightweight init — it only creates the ledger directory layout and SQLite DB. Config files (policy.yaml, actors.yaml) and bridge hooks are NOT created; those require edda init.

Source

pub fn ensure_initialized(repo_root: impl Into<PathBuf>) -> Result<()>

Ensure .edda/ and ledger exist, without returning a Ledger handle.

Use this when you only need the side effect (workspace creation) and will open the ledger separately later.

Source

pub fn open_path(repo_root: &Path) -> Result<Self>

Convenience: open from a Path ref (avoids Into ambiguity).

Source

pub fn head_branch(&self) -> Result<String>

Read the current HEAD branch name.

Source

pub fn set_head_branch(&self, name: &str) -> Result<()>

Write the HEAD branch name.

Source

pub fn append_event(&self, event: &Event) -> Result<()>

Append an event to the ledger. Append-only (CONTRACT LEDGER-02).

Source

pub fn append_event_idempotent(&self, event: &Event) -> Result<bool>

Append an event idempotently. Returns true if inserted, false if duplicate.

Source

pub fn last_event_hash(&self) -> Result<Option<String>>

Get the hash of the last event, or None if the ledger is empty.

Source

pub fn iter_events(&self) -> Result<Vec<Event>>

Read all events in the ledger.

Source

pub fn get_event(&self, event_id: &str) -> Result<Option<Event>>

Get a single event by event_id.

Source

pub fn iter_events_by_type(&self, event_type: &str) -> Result<Vec<Event>>

Get all events of a given type, filtered at the SQL level.

Source

pub fn iter_branch_events(&self, branch: &str) -> Result<Vec<Event>>

Get all events for a specific branch, filtered at the SQL level.

Source

pub fn iter_events_filtered( &self, branch: &str, event_type: Option<&str>, keyword: Option<&str>, after: Option<&str>, before: Option<&str>, limit: usize, ) -> Result<Vec<Event>>

Get events filtered by branch with optional type/keyword/date/limit, all pushed down to SQL. Returns newest-first, capped at limit.

Find commit events related to a query by evidence chain or keyword match.

Find note events matching a keyword, excluding decisions and session digests.

Source

pub fn events_after_rowid(&self, after_rowid: i64) -> Result<Vec<(i64, Event)>>

Get all events with rowid strictly greater than after_rowid.

Returns (rowid, Event) pairs ordered by rowid, useful for cursor-based polling (e.g. SSE streaming).

Source

pub fn rowid_for_event_id(&self, event_id: &str) -> Result<Option<i64>>

Look up the rowid for a given event_id.

Source

pub fn branches_json(&self) -> Result<Value>

Read branches.json content.

Source

pub fn set_branches_json(&self, value: &Value) -> Result<()>

Write branches.json content.

Source

pub fn active_decisions( &self, domain: Option<&str>, key_pattern: Option<&str>, after: Option<&str>, before: Option<&str>, ) -> Result<Vec<DecisionView>>

Query active decisions, optionally filtered by domain or key pattern. after/before are optional ISO 8601 bounds for temporal filtering.

Source

pub fn active_decisions_limited( &self, domain: Option<&str>, key_pattern: Option<&str>, after: Option<&str>, before: Option<&str>, limit: usize, ) -> Result<Vec<DecisionView>>

Query active decisions with limit for hot path optimization.

Source

pub fn decision_timeline( &self, key: &str, after: Option<&str>, before: Option<&str>, ) -> Result<Vec<DecisionView>>

All decisions for a key (active + superseded), ordered by time. after/before are optional ISO 8601 bounds for temporal filtering.

Source

pub fn domain_timeline( &self, domain: &str, after: Option<&str>, before: Option<&str>, ) -> Result<Vec<DecisionView>>

All decisions for a domain (active + superseded), ordered by time. after/before are optional ISO 8601 bounds for temporal filtering.

Source

pub fn list_domains(&self) -> Result<Vec<String>>

Distinct domain values from active decisions.

Source

pub fn village_stats( &self, village_id: &str, after: Option<&str>, before: Option<&str>, ) -> Result<VillageStats>

Compute aggregate statistics for a village’s decisions.

Source

pub fn detect_village_patterns( &self, village_id: &str, after: &str, min_occurrences: usize, ) -> Result<Vec<DetectedPattern>>

Detect recurring patterns in a village’s decision history.

Source

pub fn find_active_decision( &self, branch: &str, key: &str, ) -> Result<Option<DecisionView>>

Find the active decision for a specific key on a branch.

Source

pub fn query_active_with_paths( &self, branch: Option<&str>, limit: Option<usize>, ) -> Result<Vec<DecisionView>>

Return active decisions that have non-empty affected_paths. Used by Injection to get the candidate set for glob matching.

Source

pub fn query_by_paths( &self, paths: &[&str], branch: Option<&str>, limit: Option<usize>, ) -> Result<Vec<DecisionView>>

Given a list of file paths, return decisions whose affected_paths globs match any of them. Uses globset for pattern matching.

This is the primary query for PreToolUse hook (Track E): “which active decisions govern the file I’m about to edit?”

§Arguments
  • paths: concrete file paths to check (e.g., ["crates/edda-ledger/src/lib.rs"])
  • branch: optional branch filter
  • limit: max decisions to return
Source

pub fn shared_decisions(&self) -> Result<Vec<DecisionView>>

Query active decisions with shared or global scope.

Source

pub fn is_already_imported( &self, source_project_id: &str, source_event_id: &str, ) -> Result<bool>

Check if a decision has already been imported from a source project.

Source

pub fn insert_imported_decision(&self, params: ImportParams<'_>) -> Result<()>

Insert an imported decision from another project.

Source

pub fn insert_dep( &self, source_key: &str, target_key: &str, dep_type: &str, created_event: Option<&str>, ) -> Result<()>

Insert a dependency edge between two decision keys.

Source

pub fn deps_of(&self, key: &str) -> Result<Vec<DependencyEdge>>

What does key depend on?

Source

pub fn dependents_of(&self, key: &str) -> Result<Vec<DependencyEdge>>

Who depends on key?

Source

pub fn active_dependents_of( &self, key: &str, ) -> Result<Vec<(DependencyEdge, DecisionView)>>

Who depends on key, joined with active decisions only.

Source

pub fn decision_outcomes( &self, decision_event_id: &str, ) -> Result<Option<OutcomeMetrics>>

Get aggregated outcome metrics for a decision.

Source

pub fn executions_for_decision( &self, decision_event_id: &str, ) -> Result<Vec<ExecutionLinked>>

Get all execution events linked to a decision via based_on provenance.

Source

pub fn transitive_dependents_of( &self, key: &str, max_depth: usize, ) -> Result<Vec<(DependencyEdge, DecisionView, usize)>>

Transitive dependents of key via BFS, up to max_depth hops. Returns (DependencyEdge, DecisionView, depth) — only active decisions, deduplicated.

Source

pub fn get_decision_by_event_id( &self, event_id: &str, ) -> Result<Option<DecisionView>>

Look up a single decision by event_id.

Source

pub fn causal_chain( &self, event_id: &str, max_depth: usize, ) -> Result<Option<(DecisionView, Vec<ChainEntryView>)>>

Traverse the causal chain from a root decision via unified BFS.

Source

pub fn get_task_brief(&self, task_id: &str) -> Result<Option<TaskBriefRow>>

Get a task brief by task_id.

Source

pub fn list_task_briefs( &self, status: Option<&str>, intent: Option<&str>, ) -> Result<Vec<TaskBriefRow>>

List task briefs, optionally filtered by status and/or intent.

Source

pub fn get_bundle(&self, bundle_id: &str) -> Result<Option<BundleRow>>

Get a review bundle by bundle_id.

Source

pub fn list_bundles(&self, status: Option<&str>) -> Result<Vec<BundleRow>>

List review bundles, optionally filtered by status.

Source

pub fn insert_device_token(&self, row: &DeviceTokenRow) -> Result<()>

Insert a new device token row.

Source

pub fn validate_device_token( &self, token_hash: &str, ) -> Result<Option<DeviceTokenRow>>

Validate a device token by its SHA-256 hash. Returns the row if active.

Source

pub fn list_device_tokens(&self) -> Result<Vec<DeviceTokenRow>>

List all device tokens (active and revoked).

Source

pub fn revoke_device_token( &self, device_name: &str, revoke_event_id: &str, ) -> Result<bool>

Revoke a device token by device name. Returns true if revoked.

Source

pub fn revoke_all_device_tokens(&self, revoke_event_id: &str) -> Result<u64>

Revoke all active device tokens. Returns count of revoked tokens.

Source

pub fn insert_snapshot(&self, row: &DecideSnapshotRow) -> Result<()>

Insert a row into the decide_snapshots materialized view.

Source

pub fn query_snapshots( &self, village_id: Option<&str>, engine_version: Option<&str>, limit: usize, ) -> Result<Vec<DecideSnapshotRow>>

Query snapshots with optional filtering by village_id and engine_version.

Source

pub fn snapshots_by_context_hash( &self, context_hash: &str, ) -> Result<Vec<DecideSnapshotRow>>

Find all snapshots for a given context_hash.

Source

pub fn insert_suggestion(&self, row: &SuggestionRow) -> Result<()>

Insert a new suggestion row.

Source

pub fn list_suggestions_by_status( &self, status: &str, ) -> Result<Vec<SuggestionRow>>

List suggestions filtered by status.

Source

pub fn get_suggestion(&self, id: &str) -> Result<Option<SuggestionRow>>

Get a single suggestion by id.

Source

pub fn update_suggestion_status( &self, id: &str, status: &str, reviewed_at: &str, ) -> Result<bool>

Update a suggestion’s status and reviewed_at timestamp. Returns true if a row was updated.

Auto Trait Implementations§

§

impl !Freeze for Ledger

§

impl !RefUnwindSafe for Ledger

§

impl !Sync for Ledger

§

impl !UnwindSafe for Ledger

§

impl Send for Ledger

§

impl Unpin for Ledger

§

impl UnsafeUnpin for Ledger

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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