MingaAgent.EventLog.Store (Minga v0.1.0)

Copy Markdown View Source

SQLite storage backend for durable agent session events.

Summary

Functions

Closes the database connection.

Returns the total number of agent events.

Deletes events older than the given wall-clock time.

Returns all events for a session with id greater than the cursor, ordered by id.

Returns every persisted file-edit event in durable order.

Returns :file_edit_proposed events whose payload path exactly matches, most recent first.

Inserts an append-only event record.

Runs a SQLite integrity check.

Returns the latest event id for a session, or 0 when it has no events.

Opens or creates the agent event database.

Opens an in-memory database for tests.

Opens the writer connection, recreating a database that fails an integrity check.

Types

db()

@type db() :: Exqlite.Sqlite3.db()

Functions

close(db)

@spec close(db()) :: :ok | {:error, term()}

Closes the database connection.

count(db)

@spec count(db()) :: {:ok, non_neg_integer()} | {:error, term()}

Returns the total number of agent events.

delete_before(db, cutoff)

@spec delete_before(db(), DateTime.t()) :: {:ok, non_neg_integer()} | {:error, term()}

Deletes events older than the given wall-clock time.

events_after(db, session_id, last_id, limit \\ 1000)

@spec events_after(db(), String.t(), non_neg_integer(), pos_integer()) ::
  {:ok, [MingaAgent.EventLog.EventRecord.t()]} | {:error, term()}

Returns all events for a session with id greater than the cursor, ordered by id.

file_edit_events(db)

@spec file_edit_events(db()) ::
  {:ok, [MingaAgent.EventLog.EventRecord.t()]} | {:error, term()}

Returns every persisted file-edit event in durable order.

file_edits_for_path(db, path, limit \\ 200)

@spec file_edits_for_path(db(), String.t(), pos_integer()) ::
  {:ok, [MingaAgent.EventLog.EventRecord.t()]} | {:error, term()}

Returns :file_edit_proposed events whose payload path exactly matches, most recent first.

Used by code-provenance reads to find every agent edit that touched a file, across all sessions. Bounded by limit (newest events win).

insert(db, record)

@spec insert(db(), MingaAgent.EventLog.EventRecord.t()) ::
  {:ok, pos_integer()} | {:error, term()}

Inserts an append-only event record.

integrity_check(db, mode \\ :quick)

@spec integrity_check(db(), :full | :quick) ::
  {:ok, :healthy} | {:error, [String.t()]}

Runs a SQLite integrity check.

latest_id(db, session_id)

@spec latest_id(db(), String.t()) :: {:ok, non_neg_integer()} | {:error, term()}

Returns the latest event id for a session, or 0 when it has no events.

open(db_path)

@spec open(String.t()) :: {:ok, db()} | {:error, term()}

Opens or creates the agent event database.

open_memory()

@spec open_memory() :: {:ok, db()} | {:error, term()}

Opens an in-memory database for tests.

open_writer(db_path, opts)

@spec open_writer(
  String.t(),
  keyword()
) :: {:ok, db()} | {:error, term()}

Opens the writer connection, recreating a database that fails an integrity check.