refactor(backend): alihkan EditLog ke zesdex-cms JsonlEditLogRepository
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
0ad3b0e539
commit
9618ef413b
@@ -8,6 +8,7 @@
|
|||||||
//! session's `SQLite` blob store.
|
//! session's `SQLite` blob store.
|
||||||
use crate::app::state::rest::AppStateRest;
|
use crate::app::state::rest::AppStateRest;
|
||||||
use sha2::Digest;
|
use sha2::Digest;
|
||||||
|
use zesdex_cms::domain::repository::EditLogRepository;
|
||||||
|
|
||||||
/// Returns the number of stored pre-edit blobs (snapshots) for this session.
|
/// Returns the number of stored pre-edit blobs (snapshots) for this session.
|
||||||
pub fn rewind_count(state: &AppStateRest) -> usize {
|
pub fn rewind_count(state: &AppStateRest) -> usize {
|
||||||
@@ -100,18 +101,20 @@ pub fn rewind_to(state: &mut AppStateRest, index: usize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Log the rewind itself as an edit entry
|
// Log the rewind itself as an edit entry
|
||||||
let mut el = crate::model::editlog::EditLog::new(&state.session_dir);
|
let repo = zesdex_cms::infrastructure::persistence::edit_log_repo::JsonlEditLogRepository::new();
|
||||||
let entry = crate::model::editlog::EditLogEntry {
|
if let Ok(mut el) = repo.open(&state.session_dir) {
|
||||||
ts: chrono::Utc::now().timestamp_millis(),
|
let entry = zesdex_cms::domain::edit_log::EditLogEntry {
|
||||||
tool: "rewind".to_string(),
|
ts: chrono::Utc::now().timestamp_millis(),
|
||||||
path: restore_path.to_string_lossy().to_string(),
|
tool: "rewind".to_string(),
|
||||||
reason: format!("rewind_to({index})"),
|
path: restore_path.to_string_lossy().to_string(),
|
||||||
content_sha256: hex::encode(sha2::Sha256::digest(&bytes)),
|
reason: format!("rewind_to({index})"),
|
||||||
bytes_delta: bytes.len() as i64,
|
content_sha256: hex::encode(sha2::Sha256::digest(&bytes)),
|
||||||
origin: crate::app::state::types::Origin::Main.tag(),
|
bytes_delta: bytes.len() as i64,
|
||||||
session_id: state.session_id.clone(),
|
origin: crate::app::state::types::Origin::Main.tag(),
|
||||||
};
|
session_id: state.session_id.clone(),
|
||||||
let _ = el.append(entry);
|
};
|
||||||
|
let _ = repo.append(&state.session_dir, &mut el, entry);
|
||||||
|
}
|
||||||
|
|
||||||
// Clear the transcript to force a refresh
|
// Clear the transcript to force a refresh
|
||||||
state.transcript_cache.dirty = true;
|
state.transcript_cache.dirty = true;
|
||||||
@@ -125,7 +128,9 @@ fn open_session_db(session_dir: &std::path::Path) -> anyhow::Result<rusqlite::Co
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn find_edit_path(state: &AppStateRest, _blob_key: &str) -> Option<std::path::PathBuf> {
|
fn find_edit_path(state: &AppStateRest, _blob_key: &str) -> Option<std::path::PathBuf> {
|
||||||
let el = crate::model::editlog::EditLog::new(&state.session_dir);
|
let el = zesdex_cms::infrastructure::persistence::edit_log_repo::JsonlEditLogRepository::new()
|
||||||
|
.open(&state.session_dir)
|
||||||
|
.unwrap_or_else(|_| zesdex_cms::domain::edit_log::EditLog::new());
|
||||||
let entry = el
|
let entry = el
|
||||||
.entries
|
.entries
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ use std::fmt::Write;
|
|||||||
|
|
||||||
use crate::app::harness::Verdict;
|
use crate::app::harness::Verdict;
|
||||||
use sha2::Digest;
|
use sha2::Digest;
|
||||||
|
use zesdex_cms::domain::repository::EditLogRepository;
|
||||||
use crate::app::review::{should_trigger_review, trigger_review};
|
use crate::app::review::{should_trigger_review, trigger_review};
|
||||||
use zesdex_iam::domain::repository::SessionRepository;
|
use zesdex_iam::domain::repository::SessionRepository;
|
||||||
use crate::app::state::rest::{AppStateRest, ChatMessageDisplay};
|
use crate::app::state::rest::{AppStateRest, ChatMessageDisplay};
|
||||||
@@ -921,7 +922,10 @@ fn run_agent_turn(
|
|||||||
const MAX_TODO_RETRIES: usize = 5;
|
const MAX_TODO_RETRIES: usize = 5;
|
||||||
let mut msgs = messages.to_vec();
|
let mut msgs = messages.to_vec();
|
||||||
let mut edited_paths: Vec<String> = Vec::new();
|
let mut edited_paths: Vec<String> = Vec::new();
|
||||||
let initial_edits = crate::model::editlog::EditLog::new(&tc.edit_log_session_dir).len();
|
let initial_edits = zesdex_cms::infrastructure::persistence::edit_log_repo::JsonlEditLogRepository::new()
|
||||||
|
.open(&tc.edit_log_session_dir)
|
||||||
|
.map(|el| el.len())
|
||||||
|
.unwrap_or(0);
|
||||||
let mut inline_reviews_count: usize = 0;
|
let mut inline_reviews_count: usize = 0;
|
||||||
let mut prev_shaped = false;
|
let mut prev_shaped = false;
|
||||||
|
|
||||||
@@ -1473,7 +1477,9 @@ fn run_agent_turn(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let el = crate::model::editlog::EditLog::new(&tc.edit_log_session_dir);
|
let el = zesdex_cms::infrastructure::persistence::edit_log_repo::JsonlEditLogRepository::new()
|
||||||
|
.open(&tc.edit_log_session_dir)
|
||||||
|
.unwrap_or_else(|_| zesdex_cms::domain::edit_log::EditLog::new());
|
||||||
let final_edits = el.len();
|
let final_edits = el.len();
|
||||||
let total_edits_this_turn = final_edits.saturating_sub(initial_edits);
|
let total_edits_this_turn = final_edits.saturating_sub(initial_edits);
|
||||||
|
|
||||||
@@ -1586,7 +1592,7 @@ fn execute_one_tool(
|
|||||||
let new = args.get("new").and_then(|v| v.as_str()).unwrap_or("");
|
let new = args.get("new").and_then(|v| v.as_str()).unwrap_or("");
|
||||||
(new.len() as i64 - old.len() as i64).abs()
|
(new.len() as i64 - old.len() as i64).abs()
|
||||||
};
|
};
|
||||||
let entry = crate::model::editlog::EditLogEntry {
|
let entry = zesdex_cms::domain::edit_log::EditLogEntry {
|
||||||
ts: chrono::Utc::now().timestamp_millis(),
|
ts: chrono::Utc::now().timestamp_millis(),
|
||||||
tool: name.to_string(),
|
tool: name.to_string(),
|
||||||
path: path.to_string(),
|
path: path.to_string(),
|
||||||
@@ -1596,8 +1602,10 @@ fn execute_one_tool(
|
|||||||
origin: ctx.origin.tag(),
|
origin: ctx.origin.tag(),
|
||||||
session_id: session_id.to_string(),
|
session_id: session_id.to_string(),
|
||||||
};
|
};
|
||||||
let mut el = crate::model::editlog::EditLog::new(session_dir);
|
let repo = zesdex_cms::infrastructure::persistence::edit_log_repo::JsonlEditLogRepository::new();
|
||||||
el.append(entry).ok();
|
if let Ok(mut el) = repo.open(session_dir) {
|
||||||
|
let _ = repo.append(session_dir, &mut el, entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,10 @@ use super::types::{Origin, Toast, TranscriptCache};
|
|||||||
use crate::app::lsp::LspManager;
|
use crate::app::lsp::LspManager;
|
||||||
use crate::app::mcp::manager::McpManager;
|
use crate::app::mcp::manager::McpManager;
|
||||||
use crate::app::workflow::engine::WorkflowEngine;
|
use crate::app::workflow::engine::WorkflowEngine;
|
||||||
use crate::model::editlog::EditLog;
|
|
||||||
use zesdex_cms::domain::app_config::AppConfig;
|
use zesdex_cms::domain::app_config::AppConfig;
|
||||||
|
use zesdex_cms::domain::edit_log::EditLog;
|
||||||
|
use zesdex_cms::domain::repository::EditLogRepository;
|
||||||
|
use zesdex_cms::infrastructure::persistence::edit_log_repo::JsonlEditLogRepository;
|
||||||
use zesdex_cms::domain::repository::AppConfigRepository;
|
use zesdex_cms::domain::repository::AppConfigRepository;
|
||||||
use zesdex_cms::domain::repository::SettingsRepository;
|
use zesdex_cms::domain::repository::SettingsRepository;
|
||||||
use zesdex_cms::domain::settings::Settings;
|
use zesdex_cms::domain::settings::Settings;
|
||||||
@@ -121,7 +123,10 @@ impl AppStateRest {
|
|||||||
abort_flag: Arc::new(std::sync::atomic::AtomicBool::new(false)),
|
abort_flag: Arc::new(std::sync::atomic::AtomicBool::new(false)),
|
||||||
dir_cache: Arc::new(RwLock::new(dir_cache)),
|
dir_cache: Arc::new(RwLock::new(dir_cache)),
|
||||||
mention_index: MentionIndex::new(),
|
mention_index: MentionIndex::new(),
|
||||||
edit_log: EditLog::new(session_dir),
|
edit_log: JsonlEditLogRepository::new().open(session_dir).unwrap_or_else(|e| {
|
||||||
|
tracing::warn!("[state] failed to open edit log at '{}': {e}", session_dir.display());
|
||||||
|
EditLog::new()
|
||||||
|
}),
|
||||||
session_runtime: Some(SessionRuntime::new(session_dir.to_path_buf())),
|
session_runtime: Some(SessionRuntime::new(session_dir.to_path_buf())),
|
||||||
workflow_engine: WorkflowEngine::new(),
|
workflow_engine: WorkflowEngine::new(),
|
||||||
mcp_manager: McpManager::new(),
|
mcp_manager: McpManager::new(),
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ use crate::tool::{all_tools, tool_defs, tool_is_risky};
|
|||||||
use super::context::SubagentContext;
|
use super::context::SubagentContext;
|
||||||
use super::event::SubagentEvent;
|
use super::event::SubagentEvent;
|
||||||
use zesdex_cms::domain::repository::AppConfigRepository;
|
use zesdex_cms::domain::repository::AppConfigRepository;
|
||||||
|
use zesdex_cms::domain::repository::EditLogRepository;
|
||||||
use zesdex_cms::domain::repository::SettingsRepository;
|
use zesdex_cms::domain::repository::SettingsRepository;
|
||||||
|
|
||||||
/// Maps a subagent's allowed tool names to concrete Tool trait objects and
|
/// Maps a subagent's allowed tool names to concrete Tool trait objects and
|
||||||
@@ -575,7 +576,7 @@ pub fn run_subagent(ctx: &SubagentContext, tx: &mpsc::Sender<SubagentEvent>) ->
|
|||||||
.and_then(|n| n.to_str())
|
.and_then(|n| n.to_str())
|
||||||
.unwrap_or("unknown")
|
.unwrap_or("unknown")
|
||||||
.to_string();
|
.to_string();
|
||||||
let entry = crate::model::editlog::EditLogEntry {
|
let entry = zesdex_cms::domain::edit_log::EditLogEntry {
|
||||||
ts: chrono::Utc::now().timestamp_millis(),
|
ts: chrono::Utc::now().timestamp_millis(),
|
||||||
tool: tool_name.clone(),
|
tool: tool_name.clone(),
|
||||||
path: path.to_string(),
|
path: path.to_string(),
|
||||||
@@ -585,8 +586,10 @@ pub fn run_subagent(ctx: &SubagentContext, tx: &mpsc::Sender<SubagentEvent>) ->
|
|||||||
origin: tool_ctx_ref.origin.tag(),
|
origin: tool_ctx_ref.origin.tag(),
|
||||||
session_id,
|
session_id,
|
||||||
};
|
};
|
||||||
let mut el = crate::model::editlog::EditLog::new(&ctx.session_dir);
|
let repo = zesdex_cms::infrastructure::persistence::edit_log_repo::JsonlEditLogRepository::new();
|
||||||
el.append(entry).ok();
|
if let Ok(mut el) = repo.open(&ctx.session_dir) {
|
||||||
|
let _ = repo.append(&ctx.session_dir, &mut el, entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
run_res
|
run_res
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,6 @@
|
|||||||
pub mod store {
|
pub mod store {
|
||||||
pub use zesdex_entities::seaorm::common::store::*;
|
pub use zesdex_entities::seaorm::common::store::*;
|
||||||
}
|
}
|
||||||
pub mod editlog {
|
|
||||||
pub use zesdex_entities::seaorm::common::edit_log::*;
|
|
||||||
}
|
|
||||||
/// Local modules not extracted to workspace crates
|
/// Local modules not extracted to workspace crates
|
||||||
pub mod msglog;
|
pub mod msglog;
|
||||||
pub mod agent_def;
|
pub mod agent_def;
|
||||||
|
|||||||
Reference in New Issue
Block a user