Refactor IPC and DTO structures; remove unused code and streamline message handling
- Removed unused structs and methods from `response.rs`, `usage.rs`, and `client.rs`. - Simplified `Connection` handling in `conn.rs` to only support Unix sockets. - Updated `IpcServer` to exclusively use Unix sockets and removed TCP handling. - Cleaned up `editlog.rs` by removing loading and recent entry methods. - Refactored `memory.rs` to eliminate unused functions related to lesson promotion and retrospective creation. - Enhanced `search.rs` to support multiple search providers and improved error handling. - Updated chat view logic to simplify message display and improve user experience. - Removed deprecated modules and constants from various files to streamline the codebase.
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::session::Session;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Memory {
|
||||
pub name: String,
|
||||
@@ -129,16 +127,6 @@ impl Memory {
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn load_index(memory_dir: &Path) -> Vec<String> {
|
||||
let index_path = memory_dir.join("MEMORY.md");
|
||||
let content = std::fs::read_to_string(index_path).unwrap_or_default();
|
||||
content.lines().filter_map(|l| {
|
||||
let l = l.trim();
|
||||
if l.is_empty() || l.starts_with('#') { return None; }
|
||||
l.split(']').next().and_then(|s| s.split('[').nth(1)).map(|s| s.to_string())
|
||||
}).collect()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn slug_path(memory_dir: &Path, raw: &str) -> PathBuf {
|
||||
@@ -159,26 +147,6 @@ pub fn export_lessons(memory_dir: &Path, output: &Path) -> std::io::Result<()> {
|
||||
std::fs::write(output, data)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn promote_with_consensus(global_dir: &Path, lesson: &Memory) -> std::io::Result<bool> {
|
||||
let global_path = global_dir.join("memory");
|
||||
std::fs::create_dir_all(&global_path)?;
|
||||
let existing = Memory::list(&global_path);
|
||||
let slug = Memory::slugify(&lesson.name).unwrap_or_default();
|
||||
if existing.contains(&slug) {
|
||||
return Ok(true);
|
||||
}
|
||||
let consensus = lesson.outcome.as_deref() == Some("verified");
|
||||
|
||||
if consensus {
|
||||
let mut promoted = lesson.clone();
|
||||
promoted.scope = Some("global".to_string());
|
||||
promoted.write(&global_path)?;
|
||||
Ok(true)
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn import_lessons(memory_dir: &Path, input: &Path) -> std::io::Result<usize> {
|
||||
let data = std::fs::read_to_string(input)?;
|
||||
let lessons: Vec<Memory> = serde_json::from_str(&data)
|
||||
@@ -194,30 +162,6 @@ pub fn import_lessons(memory_dir: &Path, input: &Path) -> std::io::Result<usize>
|
||||
}
|
||||
Ok(imported)
|
||||
}
|
||||
pub fn auto_create_retrospective(session_dir: &Path, session: &Session) -> std::io::Result<Option<Memory>> {
|
||||
let now = chrono::Utc::now().timestamp_millis();
|
||||
let session_age_ms = now.saturating_sub(session.created_at);
|
||||
if session_age_ms < 60_000 {
|
||||
return Ok(None);
|
||||
}
|
||||
let retro_name = format!("retrospective-{}", session.id);
|
||||
let retro_path = Memory::path(session_dir, &retro_name);
|
||||
if retro_path.exists() {
|
||||
return Ok(None);
|
||||
}
|
||||
let lessons: Vec<Memory> = Memory::list(session_dir)
|
||||
.iter()
|
||||
.filter_map(|n| Memory::read(session_dir, n).ok())
|
||||
.filter(|m| m.kind == "lesson")
|
||||
.collect();
|
||||
|
||||
if lessons.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let retrospective = create_retrospective(session_dir, session, &lessons)?;
|
||||
Ok(Some(retrospective))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
@@ -386,31 +330,3 @@ mod tests {
|
||||
let _ = std::fs::remove_file(&export_path);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_retrospective(session_dir: &Path, session: &Session, lessons: &[Memory]) -> std::io::Result<Memory> {
|
||||
let now = chrono::Utc::now().timestamp_millis();
|
||||
let lessons_content: String = lessons.iter()
|
||||
.map(|l| format!("- {}: {}", l.name, l.description))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
let content = format!(
|
||||
"# Session Retrospective\n\nSession: {}\nCreated: {}\nLessons learned:\n{}\n",
|
||||
session.title, now, lessons_content,
|
||||
);
|
||||
let memory = Memory {
|
||||
name: format!("retrospective-{}", session.id),
|
||||
description: format!("End-of-session retrospective for {}", session.title),
|
||||
content,
|
||||
kind: "retrospective".to_string(),
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
outcome: None,
|
||||
lifecycle: "new".to_string(),
|
||||
scope: Some("project".to_string()),
|
||||
before_snippet: None,
|
||||
after_snippet: None,
|
||||
provenances: vec![],
|
||||
};
|
||||
memory.write(session_dir)?;
|
||||
Ok(memory)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user