Entwickler-Reiter „Roadmap“ (#1035): ROADMAP.md lesen, Kennzahlen, Filter, Sprung per ID

Nur in Debug-Builds erreichbar (--tab roadmap). Parser mit Tests, auch gegen die echte ROADMAP.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-02 09:28:06 +01:00
parent e03cd0bd4b
commit 3c9ff67b0c
4 changed files with 664 additions and 0 deletions

View File

@ -6,6 +6,7 @@ mod guitar;
mod import;
mod pitch;
mod review;
mod roadmap;
mod score;
mod session;
mod ui;

359
src/roadmap.rs Normal file
View File

@ -0,0 +1,359 @@
//! Liest `ROADMAP.md` für den Entwickler-Reiter „Roadmap“.
//!
//! Gleiche Regeln wie `tools/check-roadmap.py`: Eine ID `#NNNN` steht am Zeilenanfang, als Tabellenzeile
//! (`| #1001 | Titel | ✓ … | Notiz |`) oder als Aufzählung (`- [#1031] **Titel.** Text`).
/// Abschnitt, zu dem ein Eintrag gehört.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Section {
Stand,
Todo,
Erledigt,
Entscheidung,
Risiko,
Auftrag,
}
impl Section {
pub const ALL: [Section; 6] = [
Section::Stand,
Section::Todo,
Section::Erledigt,
Section::Entscheidung,
Section::Risiko,
Section::Auftrag,
];
pub fn label(self) -> &'static str {
match self {
Section::Stand => "Stand",
Section::Todo => "Todo",
Section::Erledigt => "Erledigt",
Section::Entscheidung => "Entscheidungen",
Section::Risiko => "Risiken",
Section::Auftrag => "Aufträge",
}
}
}
#[derive(Clone, Debug)]
pub struct Item {
pub id: u32,
pub section: Section,
/// Gruppe im Abschnitt, z. B. „P1 – Release v0.1.0“ (leer, wenn der Abschnitt keine hat).
pub group: String,
pub title: String,
/// Status einer Stand-Zeile: `✓`, `◐`, `✗` oder `?`.
pub status: Option<char>,
pub detail: String,
/// Andere IDs, die Titel oder Text nennen (ohne die eigene).
pub refs: Vec<u32>,
}
#[derive(Clone, Debug, Default)]
pub struct Roadmap {
/// Kopfzeile „Stand: …“ ohne das Wort „Stand:“.
pub stand: String,
pub next_id: Option<u32>,
pub items: Vec<Item>,
}
impl Roadmap {
pub fn parse(text: &str) -> Roadmap {
let mut out = Roadmap::default();
let mut section: Option<Section> = None;
let mut group = String::new();
for line in text.lines() {
if let Some(rest) = line.strip_prefix("Stand:") {
out.stand = rest.trim().to_string();
out.next_id = parse_next_id(rest);
continue;
}
if let Some(h) = line.strip_prefix("## ") {
section = section_of(h);
group.clear();
continue;
}
let Some(sec) = section else { continue };
if let Some(g) = bold_line(line) {
// „**Erledigt (einzeln)**“ eröffnet den Block erledigter Einträge im Todo-Abschnitt;
// „**Erledigt am …:**“ ist eine Fließtext-Zeile ohne ID.
if sec == Section::Todo && g.starts_with("Erledigt (einzeln)") {
section = Some(Section::Erledigt);
group = "Erledigt".to_string();
} else {
group = g.to_string();
}
continue;
}
if let Some(item) = parse_item(line, sec, &group) {
out.items.push(item);
}
}
out
}
pub fn count(&self, s: Section) -> usize {
self.items.iter().filter(|i| i.section == s).count()
}
/// Anzahl der Stand-Zeilen mit dem gegebenen Status.
pub fn count_status(&self, status: char) -> usize {
self.items
.iter()
.filter(|i| i.status == Some(status))
.count()
}
pub fn find(&self, id: u32) -> Option<&Item> {
self.items.iter().find(|i| i.id == id)
}
}
fn parse_next_id(s: &str) -> Option<u32> {
let rest = s.split("Nächste freie ID:").nth(1)?.trim_start();
digits_after_hash(rest)
}
fn digits_after_hash(s: &str) -> Option<u32> {
let d: String = s
.strip_prefix('#')?
.chars()
.take_while(char::is_ascii_digit)
.collect();
d.parse().ok()
}
fn section_of(heading: &str) -> Option<Section> {
if heading.contains("Stand") {
Some(Section::Stand)
} else if heading.contains("Todo") {
Some(Section::Todo)
} else if heading.contains("Entscheidungen") {
Some(Section::Entscheidung)
} else if heading.contains("Risiken") {
Some(Section::Risiko)
} else if heading.contains("Aufträge") {
Some(Section::Auftrag)
} else {
None
}
}
/// Zeile der Form `**Text**` (nur fett, sonst nichts).
fn bold_line(line: &str) -> Option<&str> {
let t = line.trim();
let inner = t.strip_prefix("**")?.strip_suffix("**")?;
(!inner.contains("**")).then_some(inner)
}
fn parse_item(line: &str, section: Section, group: &str) -> Option<Item> {
if let Some(rest) = line.strip_prefix("| #") {
let cells: Vec<&str> = line
.trim()
.trim_matches('|')
.split('|')
.map(str::trim)
.collect();
let id = digits_after_hash(&format!("#{rest}"))?;
let title = cells.get(1).copied().unwrap_or_default().to_string();
let status = cells.get(2).and_then(|c| c.chars().next());
let detail = cells
.iter()
.skip(3)
.copied()
.collect::<Vec<_>>()
.join(" | ");
return Some(make_item(id, section, group, title, status, detail));
}
let rest = line.strip_prefix("- [#")?;
let id: u32 = rest.split(']').next()?.parse().ok()?;
let body = rest.split_once(']')?.1.trim();
let (title, detail) = split_title(body);
Some(make_item(id, section, group, title, None, detail))
}
/// Titel einer Aufzählung: der fette Anfang `**Titel.**`, sonst der erste Satz.
fn split_title(body: &str) -> (String, String) {
if let Some(r) = body.strip_prefix("**")
&& let Some((t, rest)) = r.split_once("**")
{
return (
t.trim().trim_end_matches('.').to_string(),
rest.trim().to_string(),
);
}
match body.split_once(". ") {
Some((t, rest)) => (t.to_string(), rest.to_string()),
None => (body.trim_end_matches('.').to_string(), String::new()),
}
}
fn make_item(
id: u32,
section: Section,
group: &str,
title: String,
status: Option<char>,
detail: String,
) -> Item {
let mut refs = Vec::new();
for text in [&title, &detail] {
let mut rest = text.as_str();
while let Some(p) = rest.find('#') {
let after = &rest[p..];
let d: String = after[1..]
.chars()
.take_while(char::is_ascii_digit)
.collect();
if d.len() == 4
&& let Ok(n) = d.parse::<u32>()
&& n != id
&& !refs.contains(&n)
{
refs.push(n);
}
rest = &rest[p + 1..];
}
}
Item {
id,
section,
group: group.to_string(),
title,
status,
detail,
refs,
}
}
#[cfg(test)]
mod tests {
use super::*;
const SAMPLE: &str = "\
# Roadmap
Stand: 2026-11-02, `main` @ abc. Nächste freie ID: #1010
## 1. Leitplanken
Text ohne ID, #1001 hier zählt nicht.
## 2. Stand
| ID | Was | Status | Notiz |
|---|---|---|---|
| #1001 | Audio | ✓ geprüft | Test grün → #1002 |
| #1002 | Anzeige | ◐ gebaut | Nur Simulation |
## 3. Todo
**P1 – Release**
- [#1003] **Paket installieren.** Nutzer: pacman. → #1001
- [#1004] **Kurz.**
**Erledigt (einzeln)**
- [#1005] **Probe-Tag (2026-11-01).** Lauf grün.
**Erledigt am 2026-11-01:** Fließtext ohne ID.
## 4. Offene Entscheidungen
- [#1006] Lizenz des Codes: MIT, entschieden. Offen ist nichts.
## 5. Risiken
- [#1007] Kein echtes Mikrofon.
## 7. Aufträge an den Analyse-Agenten
- [#1008] **Format stabil halten.** Siehe #1003.
";
#[test]
fn reads_head() {
let r = Roadmap::parse(SAMPLE);
assert_eq!(r.next_id, Some(1010));
assert!(r.stand.starts_with("2026-11-02"));
}
#[test]
fn reads_table_rows_with_status() {
let r = Roadmap::parse(SAMPLE);
let a = r.find(1001).unwrap();
assert_eq!(a.section, Section::Stand);
assert_eq!(a.title, "Audio");
assert_eq!(a.status, Some('✓'));
assert_eq!(a.detail, "Test grün → #1002");
assert_eq!(a.refs, vec![1002]);
assert_eq!(r.find(1002).unwrap().status, Some('◐'));
}
#[test]
fn reads_todo_with_group_and_bold_title() {
let r = Roadmap::parse(SAMPLE);
let t = r.find(1003).unwrap();
assert_eq!(
(t.section, t.group.as_str()),
(Section::Todo, "P1 – Release")
);
assert_eq!(t.title, "Paket installieren");
assert_eq!(t.refs, vec![1001]);
assert_eq!(r.find(1004).unwrap().title, "Kurz");
}
#[test]
fn done_block_and_prose_lines() {
let r = Roadmap::parse(SAMPLE);
assert_eq!(r.find(1005).unwrap().section, Section::Erledigt);
assert_eq!(r.count(Section::Erledigt), 1);
}
#[test]
fn decisions_risks_orders_and_sentence_title() {
let r = Roadmap::parse(SAMPLE);
let d = r.find(1006).unwrap();
assert_eq!(
(d.section, d.title.as_str()),
(Section::Entscheidung, "Lizenz des Codes: MIT, entschieden")
);
assert_eq!(r.find(1007).unwrap().section, Section::Risiko);
assert_eq!(r.find(1008).unwrap().section, Section::Auftrag);
assert_eq!(r.find(1008).unwrap().refs, vec![1003]);
}
#[test]
fn ignores_ids_outside_definitions() {
let r = Roadmap::parse(SAMPLE);
assert!(r.find(1010).is_none());
assert_eq!(r.items.len(), 8);
}
/// Die echte `ROADMAP.md` muss vollständig lesbar sein: so viele Einträge, wie `check-roadmap.py` Definitionen zählt.
#[test]
fn real_roadmap_matches_definition_count() {
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("ROADMAP.md");
let text = std::fs::read_to_string(path).unwrap();
let defs = text
.lines()
.filter(|l| {
let digits = |s: &str| s.chars().take_while(char::is_ascii_digit).count() > 0;
l.strip_prefix("| #").is_some_and(digits)
|| l.strip_prefix("- [#").is_some_and(digits)
})
.count();
let r = Roadmap::parse(&text);
assert_eq!(r.items.len(), defs);
assert!(r.next_id.is_some_and(|n| r.items.iter().all(|i| i.id < n)));
let mut ids: Vec<u32> = r.items.iter().map(|i| i.id).collect();
ids.sort_unstable();
ids.dedup();
assert_eq!(ids.len(), r.items.len(), "doppelte ID");
assert!(
r.items
.iter()
.filter(|i| i.section == Section::Stand)
.all(|i| i.status.is_some())
);
}
}

View File

@ -7,6 +7,7 @@ mod grip_view;
mod home_view;
mod metro_view;
mod review_view;
mod roadmap_view;
mod roll;
mod voice_view;
@ -71,6 +72,8 @@ enum Mode {
Review,
Voice,
Calib,
/// Nur in Debug-Builds erreichbar (Entscheidung #1048).
Roadmap,
}
pub struct App {
@ -112,6 +115,7 @@ pub struct App {
/// Probe-Modus im Chart-Tab: Wiedergabe ohne Wertung und Aufnahme, mit Spulen.
practice: Option<chart_view::Practice>,
metro: metro_view::MetroState,
roadmap: roadmap_view::RoadmapState,
/// Gefundene Songs für die Auswahl.
charts: Vec<chart_view::ChartEntry>,
/// Gewählte Passage (Index in `chart.sections`); `None` = ganzes Lied.
@ -208,6 +212,7 @@ impl App {
calib: CalibState::new(),
practice: None,
metro: metro_view::MetroState::new(),
roadmap: roadmap_view::RoadmapState::new(),
charts: Vec::new(),
section: None,
practice_loop: true,
@ -289,6 +294,7 @@ impl App {
"verlauf" => Mode::History,
"stimmfinder" | "voice" => Mode::Voice,
"kalibrierung" | "abgleich" => Mode::Calib,
"roadmap" if cfg!(debug_assertions) => Mode::Roadmap,
_ => Mode::Tuner,
};
self.last_mode = self.mode;
@ -606,6 +612,9 @@ impl eframe::App for App {
if self.review.is_some() {
ui.selectable_value(&mut self.mode, Mode::Review, "Auswertung");
}
if cfg!(debug_assertions) {
ui.selectable_value(&mut self.mode, Mode::Roadmap, "Roadmap");
}
});
// Hinweise und Fehlermeldungen gut sichtbar oben.
if !self.messages.is_empty() {
@ -641,6 +650,7 @@ impl eframe::App for App {
Mode::Review => self.review_ui(ui),
Mode::Voice => self.voice_ui(ui),
Mode::Calib => self.calib_ui(ui),
Mode::Roadmap => self.roadmap_ui(ui),
}
});
});

294
src/ui/roadmap_view.rs Normal file
View File

@ -0,0 +1,294 @@
//! Entwickler-Reiter „Roadmap“: zeigt `ROADMAP.md` mit Kennzahlen, Filter und Sprung per ID.
//! Nur in Debug-Builds erreichbar (Entscheidung #1048); das Paket enthält ihn nicht.
use super::App;
use super::gear::{AMBER, ENGRAVING, LED_GREEN, LED_RED, LED_YELLOW, PLATE_BG, PLATE_EDGE, panel};
use crate::roadmap::{Item, Roadmap, Section};
use eframe::egui::{self, Color32, RichText, Stroke};
use std::path::PathBuf;
pub(super) struct RoadmapState {
path: PathBuf,
roadmap: Option<Roadmap>,
error: Option<String>,
filter: String,
section: Option<Section>,
/// Eingabefeld „Gehe zu #“.
goto_text: String,
/// Eintrag, zu dem gesprungen wurde (hervorgehoben, einmal ins Bild gerollt).
goto: Option<u32>,
scroll_pending: bool,
}
impl RoadmapState {
pub fn new() -> Self {
Self {
path: PathBuf::from("ROADMAP.md"),
roadmap: None,
error: None,
filter: String::new(),
section: None,
goto_text: String::new(),
goto: None,
scroll_pending: false,
}
}
fn load(&mut self) {
match std::fs::read_to_string(&self.path) {
Ok(text) => {
self.roadmap = Some(Roadmap::parse(&text));
self.error = None;
}
Err(e) => {
self.roadmap = None;
self.error = Some(format!(
"{} nicht lesbar ({e}). Die App im Repository-Ordner starten (make run).",
self.path.display()
));
}
}
}
/// Springt zu einem Eintrag: Filter zurücksetzen, Eintrag hervorheben und ins Bild rollen.
fn jump(&mut self, id: u32) {
self.filter.clear();
self.section = None;
self.goto = Some(id);
self.scroll_pending = true;
}
}
fn status_color(status: Option<char>) -> Color32 {
match status {
Some('✓') => LED_GREEN,
Some('◐') => LED_YELLOW,
Some('✗') => LED_RED,
_ => ENGRAVING,
}
}
fn matches(item: &Item, section: Option<Section>, filter: &str) -> bool {
if section.is_some_and(|s| s != item.section) {
return false;
}
let f = filter.trim().to_lowercase();
if f.is_empty() {
return true;
}
let f = f.trim_start_matches('#');
format!("{} {} {}", item.id, item.title, item.detail)
.to_lowercase()
.contains(f)
}
impl App {
pub(super) fn roadmap_ui(&mut self, ui: &mut egui::Ui) {
if self.roadmap.roadmap.is_none() && self.roadmap.error.is_none() {
self.roadmap.load();
}
let st = &mut self.roadmap;
let mut jump_to: Option<u32> = None;
panel(ui, "Roadmap (nur Entwicklung)", |ui| {
ui.horizontal_wrapped(|ui| {
if ui.button("Neu laden").clicked() {
st.load();
}
ui.label(RichText::new(st.path.display().to_string()).color(ENGRAVING));
});
if let Some(e) = &st.error {
ui.colored_label(LED_RED, e);
}
if let Some(r) = &st.roadmap {
ui.label(format!("Stand: {}", r.stand));
ui.horizontal_wrapped(|ui| {
for s in Section::ALL {
ui.label(RichText::new(format!("{} {}", s.label(), r.count(s))).strong());
}
ui.separator();
for (mark, name) in [
('✓', "geprüft"),
('◐', "gebaut"),
('✗', "offen"),
('?', "unklar"),
] {
ui.label(
RichText::new(format!("{mark} {} {name}", r.count_status(mark)))
.color(status_color(Some(mark))),
);
}
if let Some(n) = r.next_id {
ui.separator();
ui.label(format!("nächste ID #{n}"));
}
});
}
});
let Some(r) = st.roadmap.clone() else { return };
ui.add_space(6.0);
ui.horizontal_wrapped(|ui| {
ui.label("Filter");
ui.add(
egui::TextEdit::singleline(&mut st.filter)
.desired_width(160.0)
.hint_text("Text oder ID"),
);
ui.selectable_value(&mut st.section, None, "Alle");
for s in Section::ALL {
ui.selectable_value(&mut st.section, Some(s), s.label());
}
ui.separator();
ui.label("Gehe zu #");
let resp = ui.add(egui::TextEdit::singleline(&mut st.goto_text).desired_width(60.0));
if resp.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) {
match st.goto_text.trim().trim_start_matches('#').parse::<u32>() {
Ok(id) if r.find(id).is_some() => jump_to = Some(id),
_ => {
st.error = Some(format!(
"Keine ID „{}“ in der Roadmap.",
st.goto_text.trim()
))
}
}
}
});
if st.goto_text.is_empty()
&& st
.error
.as_deref()
.is_some_and(|e| e.starts_with("Keine ID"))
{
st.error = None;
}
ui.add_space(6.0);
let mut shown = 0;
for item in r
.items
.iter()
.filter(|i| matches(i, st.section, &st.filter))
{
shown += 1;
let highlighted = st.goto == Some(item.id);
let frame = egui::Frame::new()
.fill(PLATE_BG)
.stroke(Stroke::new(
if highlighted { 2.0 } else { 1.0 },
if highlighted { AMBER } else { PLATE_EDGE },
))
.corner_radius(6.0)
.inner_margin(egui::Margin::symmetric(10, 6));
let out = frame.show(ui, |ui| {
ui.set_width(ui.available_width());
ui.horizontal_wrapped(|ui| {
ui.label(
RichText::new(format!("#{}", item.id))
.monospace()
.strong()
.color(AMBER),
);
if let Some(s) = item.status {
ui.label(
RichText::new(s.to_string())
.strong()
.color(status_color(item.status)),
);
}
ui.label(RichText::new(&item.title).strong());
let group = if item.group.is_empty() {
item.section.label().to_string()
} else {
item.group.clone()
};
ui.label(RichText::new(group).small().color(ENGRAVING));
});
if !item.detail.is_empty() {
ui.label(&item.detail);
}
if !item.refs.is_empty() {
ui.horizontal_wrapped(|ui| {
ui.label(RichText::new("→").color(ENGRAVING));
for &id in &item.refs {
let known = r.find(id).is_some();
if ui
.add_enabled(known, egui::Button::new(format!("#{id}")).small())
.clicked()
{
jump_to = Some(id);
}
}
});
}
});
if highlighted && st.scroll_pending {
out.response.scroll_to_me(Some(egui::Align::Center));
st.scroll_pending = false;
}
ui.add_space(4.0);
}
if shown == 0 {
ui.label(RichText::new("Nichts gefunden.").color(ENGRAVING));
}
if let Some(id) = jump_to {
st.jump(id);
}
}
}
#[cfg(test)]
mod tests {
use super::*;
fn item(id: u32, section: Section, title: &str, detail: &str) -> Item {
Item {
id,
section,
group: String::new(),
title: title.into(),
status: None,
detail: detail.into(),
refs: vec![],
}
}
#[test]
fn filter_matches_id_title_and_detail_case_insensitive() {
let i = item(1031, Section::Todo, "Paket installieren", "Nutzer: Pacman");
assert!(matches(&i, None, ""));
assert!(matches(&i, None, "#1031"));
assert!(matches(&i, None, "1031"));
assert!(matches(&i, None, "paket"));
assert!(matches(&i, None, "PACMAN"));
assert!(!matches(&i, None, "klicktest"));
}
#[test]
fn section_filter_excludes_other_sections() {
let i = item(1, Section::Risiko, "x", "");
assert!(matches(&i, Some(Section::Risiko), ""));
assert!(!matches(&i, Some(Section::Todo), ""));
}
#[test]
fn jump_clears_filters_and_marks_item() {
let mut st = RoadmapState::new();
st.filter = "abc".into();
st.section = Some(Section::Todo);
st.jump(1044);
assert_eq!(
(st.filter.as_str(), st.section, st.goto, st.scroll_pending),
("", None, Some(1044), true)
);
}
#[test]
fn missing_file_gives_hint_not_panic() {
let mut st = RoadmapState::new();
st.path = PathBuf::from("/nonexistent/ROADMAP.md");
st.load();
assert!(st.roadmap.is_none());
assert!(st.error.as_deref().is_some_and(|e| e.contains("make run")));
}
}