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
@@ -9,6 +9,9 @@ use crate::app::subagent::context::build_subagent_context;
|
||||
use crate::app::subagent::engine::run_subagent;
|
||||
use crate::app::subagent::spawn::AgentDefinition;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zesdex_cms::domain::memory::Memory;
|
||||
use zesdex_cms::domain::repository::MemoryRepository;
|
||||
use zesdex_cms::infrastructure::persistence::memory_repo::MarkdownMemoryRepository;
|
||||
|
||||
/// How much trust a lesson's origin/verification warrants.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
@@ -484,14 +487,15 @@ const STALE_AFTER_DAYS: i64 = 60;
|
||||
/// `mem.write`.
|
||||
pub fn run_staleness_sweep(memory_dir: &std::path::Path) -> std::io::Result<Vec<String>> {
|
||||
let mut flagged = Vec::new();
|
||||
let names = crate::model::memory::Memory::list(memory_dir);
|
||||
let names = MarkdownMemoryRepository::new().list(memory_dir).unwrap_or_default();
|
||||
let now = chrono::Utc::now().timestamp_millis();
|
||||
let cutoff = now - STALE_AFTER_DAYS * 24 * 3600 * 1000;
|
||||
for name in names {
|
||||
if let Ok(mut mem) = crate::model::memory::Memory::read(memory_dir, &name) {
|
||||
if let Ok(mut mem) = MarkdownMemoryRepository::new().load(memory_dir, &name) {
|
||||
if mem.updated_at < cutoff && mem.lifecycle != "stale" {
|
||||
mem.lifecycle = "stale".to_string();
|
||||
mem.write(memory_dir)?;
|
||||
MarkdownMemoryRepository::new().save(memory_dir, &mem)
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
|
||||
flagged.push(name);
|
||||
}
|
||||
}
|
||||
@@ -581,7 +585,7 @@ pub fn process_pending_lessons(session_dir: &std::path::Path, memory_dir: &std::
|
||||
}
|
||||
}
|
||||
for lesson in &to_keep {
|
||||
let mem = crate::model::memory::Memory {
|
||||
let mem = Memory {
|
||||
name: lesson.name.clone(),
|
||||
description: lesson.content.chars().take(80).collect(),
|
||||
content: lesson.content.clone(),
|
||||
@@ -595,7 +599,8 @@ pub fn process_pending_lessons(session_dir: &std::path::Path, memory_dir: &std::
|
||||
after_snippet: None,
|
||||
provenances: vec![],
|
||||
};
|
||||
mem.write(memory_dir)?;
|
||||
MarkdownMemoryRepository::new().save(memory_dir, &mem)
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
|
||||
}
|
||||
|
||||
save_pending_lessons(session_dir, &remaining)?;
|
||||
@@ -625,7 +630,7 @@ pub fn resolve_pending_lesson(
|
||||
for p in pending {
|
||||
if p.lesson.name == lesson_name {
|
||||
if keep {
|
||||
let mem = crate::model::memory::Memory {
|
||||
let mem = Memory {
|
||||
name: p.lesson.name.clone(),
|
||||
description: p.lesson.content.chars().take(80).collect(),
|
||||
content: p.lesson.content.clone(),
|
||||
@@ -639,7 +644,8 @@ pub fn resolve_pending_lesson(
|
||||
after_snippet: None,
|
||||
provenances: vec![],
|
||||
};
|
||||
mem.write(memory_dir)?;
|
||||
MarkdownMemoryRepository::new().save(memory_dir, &mem)
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
|
||||
}
|
||||
} else {
|
||||
remaining.push(p);
|
||||
|
||||
Reference in New Issue
Block a user