Persönlichkeits Skill v2
This commit is contained in:
@@ -56,4 +56,38 @@ impl PersonalityWriter for PersonalitySkill {
|
||||
info!(path = %self.path, field = %field, "Persönlichkeit aktualisiert");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Entfernt einen Abschnitt aus soul_personality.md.
|
||||
/// Macht nichts wenn der Abschnitt nicht existiert.
|
||||
fn remove(&self, field: &str) -> anyhow::Result<()> {
|
||||
let content = std::fs::read_to_string(&self.path)?;
|
||||
let section_header = format!("## {}", field);
|
||||
|
||||
// Abschnitt nicht vorhanden — nichts zu tun
|
||||
if !content.contains(§ion_header) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut result = String::new();
|
||||
let mut in_section = false;
|
||||
|
||||
for line in content.lines() {
|
||||
if line.trim_start().starts_with("## ") && line.contains(field) {
|
||||
// Abschnitt gefunden — überspringen
|
||||
in_section = true;
|
||||
} else if line.trim_start().starts_with("## ") && in_section {
|
||||
// Nächster Abschnitt — Section-Modus beenden
|
||||
in_section = false;
|
||||
result.push_str(line);
|
||||
result.push('\n');
|
||||
} else if !in_section {
|
||||
result.push_str(line);
|
||||
result.push('\n');
|
||||
}
|
||||
}
|
||||
|
||||
std::fs::write(&self.path, result.trim_end())?;
|
||||
info!(path = %self.path, field = %field, "Persönlichkeits-Abschnitt entfernt");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user