Persönlichkeits Skill v2

This commit is contained in:
Sithies
2026-03-17 13:13:48 +01:00
parent 750fe1f5f6
commit 0190089c90
8 changed files with 104 additions and 43 deletions
+34
View File
@@ -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(&section_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(())
}
}