refactor(backend): alihkan Memory ke zesdex-cms MarkdownMemoryRepository
Ganti semua pemanggilan Memory::read/write/remove/list di zesdex-backend dengan MarkdownMemoryRepository dari zesdex-cms. Hapus re-export model::memory yang sudah tidak dipakai. Method mapping: read -> load, write -> save, remove -> delete, list -> list. Import trait MemoryRepository untuk method resolution. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
dc9fd4dbd1
commit
0ad3b0e539
@@ -29,6 +29,8 @@ use crate::app::state::rest::{AppStateRest, ChatMessageDisplay};
|
||||
use crate::app::state::runtime::TurnEvent;
|
||||
use crate::app::state::types::{Origin, Overlay, Toast, ToastKind};
|
||||
use crate::dto::chat::message::{ChatMessage, Role};
|
||||
use zesdex_cms::domain::repository::MemoryRepository;
|
||||
use zesdex_cms::infrastructure::persistence::memory_repo::MarkdownMemoryRepository;
|
||||
|
||||
/// A single, well-typed event in the app — produced by key input, the
|
||||
/// streaming pipeline, or subagent threads — that mutates `AppStateRest`
|
||||
@@ -589,7 +591,7 @@ pub fn apply_action(state: &mut AppStateRest, action: Action) {
|
||||
state.dirty = true;
|
||||
}
|
||||
Action::LessonDelete { name } => {
|
||||
let _ = crate::model::memory::Memory::remove(&state.memory_dir, &name);
|
||||
let _ = MarkdownMemoryRepository::new().delete(&state.memory_dir, &name);
|
||||
if let Some(ref mut rt) = state.session_runtime {
|
||||
refresh_lesson_counters(&state.memory_dir, rt);
|
||||
}
|
||||
@@ -795,7 +797,7 @@ fn generate_workspace_tree(roots: &[std::path::PathBuf]) -> String {
|
||||
///
|
||||
/// Return: a formatted string (may be empty if no memory entries exist).
|
||||
fn build_memory_section(memory_dir: &std::path::Path) -> String {
|
||||
let names = crate::model::memory::Memory::list(memory_dir);
|
||||
let names = MarkdownMemoryRepository::new().list(memory_dir).unwrap_or_default();
|
||||
if names.is_empty() {
|
||||
return String::new();
|
||||
}
|
||||
@@ -808,7 +810,7 @@ fn build_memory_section(memory_dir: &std::path::Path) -> String {
|
||||
section.push_str("... (more entries omitted, use recall() to see all)\n");
|
||||
break;
|
||||
}
|
||||
if let Ok(mem) = crate::model::memory::Memory::read(memory_dir, name) {
|
||||
if let Ok(mem) = MarkdownMemoryRepository::new().load(memory_dir, name) {
|
||||
if mem.lifecycle == "stale" {
|
||||
continue;
|
||||
}
|
||||
@@ -831,7 +833,7 @@ fn build_memory_section(memory_dir: &std::path::Path) -> String {
|
||||
/// breakdown counters. This runs on every user submit so the dashboard
|
||||
/// reflects actual memory state.
|
||||
fn refresh_lesson_counters(memory_dir: &std::path::Path, rt: &mut crate::app::state::runtime::SessionRuntime) {
|
||||
let names = crate::model::memory::Memory::list(memory_dir);
|
||||
let names = MarkdownMemoryRepository::new().list(memory_dir).unwrap_or_default();
|
||||
rt.lesson_count = 0;
|
||||
rt.lessons_user = 0;
|
||||
rt.lessons_feedback = 0;
|
||||
@@ -841,7 +843,7 @@ fn refresh_lesson_counters(memory_dir: &std::path::Path, rt: &mut crate::app::st
|
||||
rt.lessons_stale = 0;
|
||||
rt.lessons_contradicted = 0;
|
||||
for name in &names {
|
||||
if let Ok(mem) = crate::model::memory::Memory::read(memory_dir, name) {
|
||||
if let Ok(mem) = MarkdownMemoryRepository::new().load(memory_dir, name) {
|
||||
rt.lesson_count += 1;
|
||||
match mem.kind.as_str() {
|
||||
"user" => rt.lessons_user += 1,
|
||||
|
||||
Reference in New Issue
Block a user