docs: tambah doc comment, logging, dan inline comments di semua 255 file

Meliputi:
- File-level //! doc comment: tujuan file, alur kerja, komponen utama
- Function-level /// doc comment: apa, parameter, return, flow, edge cases
- Struct/enum/trait /// doc comment: peran, field docs
- Tracing logging (tracing::info!/debug!/trace!/warn!/error!) di setiap fungsi
- Inline comments untuk variable dan branching logic penting
- Seluruh 8 crates di workspace: zesdex-backend, zesdex-cms, zesdex-entities,
  zesdex-iam, zesdex-infra, zesdex-ipc, zesdex-middleware, zesdex-utils
- Build: 0 errors, 242/242 tests passed
This commit is contained in:
asepharyana
2026-07-19 17:05:47 +07:00
parent 6680795ce7
commit 5aaedbf787
255 changed files with 5666 additions and 743 deletions
+73 -25
View File
@@ -1,8 +1,21 @@
//! Repository traits — pure abstraction boundaries for persistence.
//!
//! Each trait defines load / save / query operations that infrastructure
//! adapters implement. The domain and application layers depend only on
//! these traits, never on concrete persistence implementations.
//! adapters implement. The domain and application layers depend **only**
//! on these traits, never on concrete persistence implementations.
//!
//! ## Traits
//! - `SettingsRepository` — load/save `Settings` from/to a base directory
//! - `AppConfigRepository` — load/save `AppConfig` from/to a base directory
//! - `ConversationRepository` — load/save `Conversation` from/to a session directory
//! - `MemoryRepository` — list/load/save/delete `Memory` entries
//! - `RewindBlobRepository` — store/retrieve/list binary blobs per session
//! - `EditLogRepository` — open/append/query edit log entries per session
//!
//! ## Dependency Inversion
//! Application services accept these traits as generic type parameters,
//! allowing the composition root to inject concrete implementations
//! (file-based, SQLite-backed, etc.) without changing business logic.
use std::path::Path;
@@ -14,52 +27,80 @@ use super::edit_log::{EditLog, EditLogEntry};
use super::memory::Memory;
use super::settings::Settings;
/// Persistence contract for `Settings`.
/// Persistence contract for `Settings` (application settings model).
///
/// Implementors provide the actual I/O logic (e.g. file-based JSON storage).
pub trait SettingsRepository {
/// Load settings from a base directory.
/// Load `Settings` from the given base directory.
///
/// Flow: read and deserialize `settings.json` from `base_dir`.
fn load(&self, base_dir: &Path) -> Result<Settings>;
/// Save settings to a base directory.
/// Persist `Settings` to the given base directory.
///
/// Flow: serialize and write `settings.json` to `base_dir`.
fn save(&self, base_dir: &Path, settings: &Settings) -> Result<()>;
}
/// Persistence contract for `AppConfig`.
/// Persistence contract for `AppConfig` (provider and model configuration).
///
/// Implementors provide the actual I/O logic (e.g. file-based JSON storage).
pub trait AppConfigRepository {
/// Load app config from a base directory.
/// Load `AppConfig` from the given base directory.
///
/// Flow: read and deserialize `app_config.json` from `base_dir`.
fn load(&self, base_dir: &Path) -> Result<AppConfig>;
/// Save app config to a base directory.
/// Persist `AppConfig` to the given base directory.
///
/// Flow: serialize and write `app_config.json` to `base_dir`.
fn save(&self, base_dir: &Path, config: &AppConfig) -> Result<()>;
}
/// Persistence contract for `Conversation`.
/// Persistence contract for `Conversation` (session conversation data).
///
/// Implementors provide the actual I/O logic (e.g. file-based JSON storage).
pub trait ConversationRepository {
/// Load a conversation from a session directory.
/// Load a `Conversation` from the given session directory.
///
/// Flow: read and deserialize `conversation.json` from `session_dir`.
fn load(&self, session_dir: &Path) -> Result<Conversation>;
/// Save a conversation to a session directory.
/// Persist a `Conversation` to the given session directory.
///
/// Flow: serialize and write `conversation.json` to `session_dir`.
fn save(&self, session_dir: &Path, conversation: &Conversation) -> Result<()>;
}
/// Persistence contract for `Memory`.
/// Persistence contract for `Memory` (long-term agent memory entries).
///
/// Implementors provide the actual I/O logic (e.g. per-memory markdown files).
pub trait MemoryRepository {
/// List all memory slugs in a memory directory.
/// List all memory slugs (filenames without extension) in the memory directory.
fn list(&self, memory_dir: &Path) -> Result<Vec<String>>;
/// Load a single memory by name.
/// Load a single `Memory` by name from the memory directory.
fn load(&self, memory_dir: &Path, name: &str) -> Result<Memory>;
/// Save (create or update) a memory.
/// Save (create or overwrite) a `Memory` in the memory directory.
fn save(&self, memory_dir: &Path, memory: &Memory) -> Result<()>;
/// Delete a memory by name.
/// Delete a `Memory` by name from the memory directory.
fn delete(&self, memory_dir: &Path, name: &str) -> Result<()>;
}
/// Repository for rewind-snapshot binary blobs, keyed by an arbitrary
/// caller-supplied key (e.g. a tool-call id) within a session.
/// Persistence contract for rewind-snapshot binary blobs.
///
/// Blobs are keyed by an arbitrary caller-supplied key (e.g. a tool-call ID)
/// within a session. They capture file snapshots for the "rewind" feature.
pub trait RewindBlobRepository {
/// Store (or overwrite) a blob under `blob_key` for this session.
/// Store (or overwrite) a binary blob under `blob_key` for this session.
///
/// ## Parameters
/// - `session_dir` — the session directory to store the blob in
/// - `blob_key` — arbitrary caller-supplied key (e.g. tool-call ID)
/// - `data` — raw byte content of the blob
/// - `mime_type` — optional MIME type hint
fn store_blob(
&self,
session_dir: &Path,
@@ -68,21 +109,28 @@ pub trait RewindBlobRepository {
mime_type: Option<&str>,
) -> anyhow::Result<()>;
/// Retrieve a blob's bytes by key, or `None` if not found.
/// Retrieve a blob's raw bytes by key, or `None` if not found.
fn retrieve_blob(&self, session_dir: &Path, blob_key: &str) -> anyhow::Result<Option<Vec<u8>>>;
/// List all blob keys for this session, oldest first.
/// List all blob keys for this session, ordered oldest-first.
fn list_blob_keys(&self, session_dir: &Path) -> anyhow::Result<Vec<String>>;
}
/// Persistence contract for `EditLog`.
/// Persistence contract for `EditLog` (append-only file mutation log).
///
/// Implementors manage an append-only log of `EditLogEntry` items per session,
/// typically persisted to a file for audit and potential undo.
pub trait EditLogRepository {
/// Open (or start tracking) the edit log for a session directory.
/// Open (or initialise) the edit log for a session directory.
///
/// Flow: load existing log file if present, or create an empty log.
fn open(&self, session_dir: &Path) -> Result<EditLog>;
/// Append one entry, persisting it immediately.
/// Append one entry to the log and persist immediately (write-through).
///
/// Flow: push entry to in-memory log → append to disk file.
fn append(&self, session_dir: &Path, log: &mut EditLog, entry: EditLogEntry) -> Result<()>;
/// Return a reference to all in-memory entries.
/// Return a cloned copy of all in-memory entries for inspection.
fn entries(&self, log: &EditLog) -> Vec<EditLogEntry>;
}