|
| 1 | +//! Display-only, uncapped completion reports. This module never schedules work. |
| 2 | +use crate::*; |
| 3 | +use std::fmt::Write; |
| 4 | + |
| 5 | +// Encode structural punctuation, HTML, and line breaks without losing Unicode. |
| 6 | +fn escape(value: &str) -> String { |
| 7 | + let mut out = String::new(); |
| 8 | + for ch in value.chars() { |
| 9 | + match ch { |
| 10 | + '\n' => out.push_str(" "), |
| 11 | + '\r' => out.push_str(" "), |
| 12 | + ch if ch.is_ascii_punctuation() => { |
| 13 | + write!(out, "&#{};", ch as u32).unwrap(); |
| 14 | + } |
| 15 | + ch if ch.is_control() => { |
| 16 | + write!(out, "&#{};", ch as u32).unwrap(); |
| 17 | + } |
| 18 | + ch => out.push(ch), |
| 19 | + } |
| 20 | + } |
| 21 | + out |
| 22 | +} |
| 23 | + |
| 24 | +fn text(out: &mut String, label: &str, value: Option<&str>) { |
| 25 | + writeln!( |
| 26 | + out, |
| 27 | + "- **{label}:** {}", |
| 28 | + value.map(escape).unwrap_or_else(|| "not recorded".into()) |
| 29 | + ) |
| 30 | + .unwrap(); |
| 31 | +} |
| 32 | + |
| 33 | +fn history(out: &mut String, label: &str, values: impl Iterator<Item = &'static str>) { |
| 34 | + let values: Vec<_> = values.map(escape).collect(); |
| 35 | + writeln!( |
| 36 | + out, |
| 37 | + "- **{label} history (oldest first):** {}", |
| 38 | + if values.is_empty() { |
| 39 | + "not recorded".into() |
| 40 | + } else { |
| 41 | + values.join(" → ") |
| 42 | + } |
| 43 | + ) |
| 44 | + .unwrap(); |
| 45 | +} |
| 46 | + |
| 47 | +fn issue(out: &mut Vec<String>, label: &str, passes: bool) { |
| 48 | + if !passes { |
| 49 | + out.push(label.to_owned()); |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +fn goal_issues(goal: &TodoGoal) -> Vec<String> { |
| 54 | + let mut issues = Vec::new(); |
| 55 | + issue( |
| 56 | + &mut issues, |
| 57 | + "feedback loop description missing", |
| 58 | + goal.feedback_loop |
| 59 | + .as_deref() |
| 60 | + .is_some_and(|v| !v.trim().is_empty()), |
| 61 | + ); |
| 62 | + issue( |
| 63 | + &mut issues, |
| 64 | + "feedback loop quality weak or missing", |
| 65 | + feedback_loop_passes(goal.closed_feedback_loop), |
| 66 | + ); |
| 67 | + issue( |
| 68 | + &mut issues, |
| 69 | + "feedback loop relevance weak or missing", |
| 70 | + feedback_loop_relevance_passes(goal), |
| 71 | + ); |
| 72 | + issue( |
| 73 | + &mut issues, |
| 74 | + "feedback loop coverage weak or missing", |
| 75 | + feedback_loop_coverage_passes(goal), |
| 76 | + ); |
| 77 | + issue( |
| 78 | + &mut issues, |
| 79 | + "feedback loop traceability weak or missing", |
| 80 | + feedback_loop_traceability_passes(goal), |
| 81 | + ); |
| 82 | + issue( |
| 83 | + &mut issues, |
| 84 | + "delivery state weak or missing", |
| 85 | + goal.delivery_state |
| 86 | + .is_some_and(|v| v >= required_delivery_state(goal.difficulty)), |
| 87 | + ); |
| 88 | + issue( |
| 89 | + &mut issues, |
| 90 | + "difficulty missing (descriptive)", |
| 91 | + goal.difficulty.is_some(), |
| 92 | + ); |
| 93 | + issue( |
| 94 | + &mut issues, |
| 95 | + "autonomy below policy threshold or missing (descriptive)", |
| 96 | + goal.autonomy |
| 97 | + .is_some_and(|v| v >= Autonomy::NecessaryFollowthrough), |
| 98 | + ); |
| 99 | + issue( |
| 100 | + &mut issues, |
| 101 | + "iteration maturity nonterminal or missing", |
| 102 | + goal.iteration_maturity |
| 103 | + .is_some_and(IterationMaturity::permits_completion), |
| 104 | + ); |
| 105 | + let needs_evidence = matches!( |
| 106 | + goal.iteration_maturity, |
| 107 | + Some( |
| 108 | + IterationMaturity::PlateauConfirmed |
| 109 | + | IterationMaturity::ConstraintsExhausted |
| 110 | + | IterationMaturity::BudgetExhausted |
| 111 | + ) |
| 112 | + ); |
| 113 | + issue( |
| 114 | + &mut issues, |
| 115 | + "required stopping evidence missing", |
| 116 | + !needs_evidence |
| 117 | + || goal |
| 118 | + .stopping_evidence |
| 119 | + .as_deref() |
| 120 | + .is_some_and(|v| !v.trim().is_empty()), |
| 121 | + ); |
| 122 | + issues |
| 123 | +} |
| 124 | + |
| 125 | +/// Render all recorded todo, plan, and goal data as display-only Markdown. |
| 126 | +/// Assessments are reported, not independently verified or used to trigger work. |
| 127 | +pub fn render_completion_report(todos: &[TodoItem], plan: &TodoPlan, goals: &[TodoGoal]) -> String { |
| 128 | + let mut current = Vec::new(); |
| 129 | + let mut earlier = Vec::new(); |
| 130 | + issue( |
| 131 | + &mut current, |
| 132 | + "Plan: intent understanding weak or missing", |
| 133 | + intent_understanding_passes(plan.understands_user_intent), |
| 134 | + ); |
| 135 | + issue( |
| 136 | + &mut current, |
| 137 | + "Plan: user intention missing", |
| 138 | + plan.user_intention |
| 139 | + .as_deref() |
| 140 | + .is_some_and(|v| !v.trim().is_empty()), |
| 141 | + ); |
| 142 | + for state in &plan.understands_user_intent_history { |
| 143 | + if !intent_understanding_passes(Some(*state)) { |
| 144 | + earlier.push(format!("Plan: intent understanding was {}", state.as_str())); |
| 145 | + } |
| 146 | + } |
| 147 | + for todo in todos { |
| 148 | + let label = format!("Todo {}", todo.id); |
| 149 | + issue( |
| 150 | + &mut current, |
| 151 | + &format!("{label}: confidence weak or missing"), |
| 152 | + completion_confidence_passes(todo.confidence), |
| 153 | + ); |
| 154 | + if todo_status_is_completed(&todo.status) { |
| 155 | + issue( |
| 156 | + &mut current, |
| 157 | + &format!("{label}: completion confidence weak or missing"), |
| 158 | + completion_confidence_passes(todo.completion_confidence), |
| 159 | + ); |
| 160 | + } |
| 161 | + for state in &todo.confidence_history { |
| 162 | + if !completion_confidence_passes(Some(*state)) { |
| 163 | + earlier.push(format!("{label}: confidence was {}", state.as_str())); |
| 164 | + } |
| 165 | + } |
| 166 | + if !goals.iter().any(|g| { |
| 167 | + normalized_group(g.group.as_deref()) == normalized_group(todo.group.as_deref()) |
| 168 | + }) { |
| 169 | + current.push(format!("{label}: goal assessment missing")); |
| 170 | + } |
| 171 | + } |
| 172 | + for goal in goals { |
| 173 | + let label = goal.group.as_deref().unwrap_or("ungrouped"); |
| 174 | + current.extend( |
| 175 | + goal_issues(goal) |
| 176 | + .into_iter() |
| 177 | + .map(|v| format!("Goal {label}: {v}")), |
| 178 | + ); |
| 179 | + macro_rules! past { |
| 180 | + ($field:ident, $hist:ident, $check:expr) => { |
| 181 | + for state in &goal.$hist { |
| 182 | + let mut prior = goal.clone(); |
| 183 | + prior.$field = Some(*state); |
| 184 | + if !$check(&prior) { |
| 185 | + earlier.push(format!( |
| 186 | + "Goal {label}: {} was {}", |
| 187 | + stringify!($field), |
| 188 | + state.as_str() |
| 189 | + )); |
| 190 | + } |
| 191 | + } |
| 192 | + }; |
| 193 | + } |
| 194 | + past!( |
| 195 | + closed_feedback_loop, |
| 196 | + closed_feedback_loop_history, |
| 197 | + |g: &TodoGoal| feedback_loop_passes(g.closed_feedback_loop) |
| 198 | + ); |
| 199 | + past!( |
| 200 | + feedback_loop_relevance, |
| 201 | + feedback_loop_relevance_history, |
| 202 | + feedback_loop_relevance_passes |
| 203 | + ); |
| 204 | + past!( |
| 205 | + feedback_loop_coverage, |
| 206 | + feedback_loop_coverage_history, |
| 207 | + feedback_loop_coverage_passes |
| 208 | + ); |
| 209 | + past!( |
| 210 | + feedback_loop_traceability, |
| 211 | + feedback_loop_traceability_history, |
| 212 | + feedback_loop_traceability_passes |
| 213 | + ); |
| 214 | + past!(delivery_state, delivery_state_history, |g: &TodoGoal| g |
| 215 | + .delivery_state |
| 216 | + .is_some_and(|v| v >= required_delivery_state(g.difficulty))); |
| 217 | + } |
| 218 | + let mut out = String::from( |
| 219 | + "# Todo completion report\n\nDisplay only. These are recorded descriptive self-assessments, not independently proven results. Status alone does not establish successful validation. Historical comparisons use current policy thresholds and current recorded difficulty.\n\n", |
| 220 | + ); |
| 221 | + for (heading, issues) in [ |
| 222 | + ("Current weak or missing assessments", current), |
| 223 | + ( |
| 224 | + "Earlier weak states (including subsequently improved assessments)", |
| 225 | + earlier, |
| 226 | + ), |
| 227 | + ] { |
| 228 | + writeln!(out, "## {heading}\n").unwrap(); |
| 229 | + if issues.is_empty() { |
| 230 | + out.push_str( |
| 231 | + "None identified in the recorded data. This is not independent verification.\n", |
| 232 | + ); |
| 233 | + } |
| 234 | + for value in issues { |
| 235 | + writeln!(out, "- {}", escape(&value)).unwrap(); |
| 236 | + } |
| 237 | + out.push('\n'); |
| 238 | + } |
| 239 | + out.push_str("## Plan\n\n"); |
| 240 | + text(&mut out, "User intention", plan.user_intention.as_deref()); |
| 241 | + text( |
| 242 | + &mut out, |
| 243 | + "Current intent understanding", |
| 244 | + plan.understands_user_intent.map(|v| v.as_str()), |
| 245 | + ); |
| 246 | + history( |
| 247 | + &mut out, |
| 248 | + "Intent understanding", |
| 249 | + plan.understands_user_intent_history |
| 250 | + .iter() |
| 251 | + .map(|v| v.as_str()), |
| 252 | + ); |
| 253 | + writeln!(out, "\n## Todos ({})\n", todos.len()).unwrap(); |
| 254 | + if todos.is_empty() { |
| 255 | + out.push_str("No todos recorded.\n"); |
| 256 | + } |
| 257 | + for (index, todo) in todos.iter().enumerate() { |
| 258 | + writeln!(out, "\n### {}. {}\n", index + 1, escape(&todo.content)).unwrap(); |
| 259 | + for (label, value) in [ |
| 260 | + ("ID", Some(todo.id.as_str())), |
| 261 | + ("Status", Some(todo.status.as_str())), |
| 262 | + ("Group", todo.group.as_deref()), |
| 263 | + ("Priority", Some(todo.priority.as_str())), |
| 264 | + ("Details", todo.details.as_deref()), |
| 265 | + ("Assigned to", todo.assigned_to.as_deref()), |
| 266 | + ("Confidence", todo.confidence.map(|v| v.as_str())), |
| 267 | + ( |
| 268 | + "Completion confidence", |
| 269 | + todo.completion_confidence.map(|v| v.as_str()), |
| 270 | + ), |
| 271 | + ] { |
| 272 | + text(&mut out, label, value); |
| 273 | + } |
| 274 | + text( |
| 275 | + &mut out, |
| 276 | + "Stage", |
| 277 | + todo.stage.map(|v| v.to_string()).as_deref(), |
| 278 | + ); |
| 279 | + text( |
| 280 | + &mut out, |
| 281 | + "Blocked by", |
| 282 | + if todo.blocked_by.is_empty() { |
| 283 | + None |
| 284 | + } else { |
| 285 | + Some(todo.blocked_by.join(", ")) |
| 286 | + } |
| 287 | + .as_deref(), |
| 288 | + ); |
| 289 | + history( |
| 290 | + &mut out, |
| 291 | + "Confidence", |
| 292 | + todo.confidence_history.iter().map(|v| v.as_str()), |
| 293 | + ); |
| 294 | + } |
| 295 | + writeln!(out, "\n## Goals ({})\n", goals.len()).unwrap(); |
| 296 | + if goals.is_empty() { |
| 297 | + out.push_str("No goal assessments recorded.\n"); |
| 298 | + } |
| 299 | + for goal in goals { |
| 300 | + writeln!( |
| 301 | + out, |
| 302 | + "\n### Goal: {}\n", |
| 303 | + escape(goal.group.as_deref().unwrap_or("ungrouped")) |
| 304 | + ) |
| 305 | + .unwrap(); |
| 306 | + text(&mut out, "Group", goal.group.as_deref()); |
| 307 | + text(&mut out, "Feedback loop", goal.feedback_loop.as_deref()); |
| 308 | + macro_rules! field { |
| 309 | + ($label:literal, $field:ident) => { |
| 310 | + text(&mut out, $label, goal.$field.map(|v| v.as_str())); |
| 311 | + }; |
| 312 | + } |
| 313 | + macro_rules! hist { |
| 314 | + ($label:literal, $field:ident) => { |
| 315 | + history(&mut out, $label, goal.$field.iter().map(|v| v.as_str())); |
| 316 | + }; |
| 317 | + } |
| 318 | + field!("Feedback loop quality", closed_feedback_loop); |
| 319 | + hist!("Feedback loop quality", closed_feedback_loop_history); |
| 320 | + field!("Feedback loop relevance", feedback_loop_relevance); |
| 321 | + hist!("Feedback loop relevance", feedback_loop_relevance_history); |
| 322 | + field!("Feedback loop coverage", feedback_loop_coverage); |
| 323 | + hist!("Feedback loop coverage", feedback_loop_coverage_history); |
| 324 | + field!("Feedback loop traceability", feedback_loop_traceability); |
| 325 | + hist!( |
| 326 | + "Feedback loop traceability", |
| 327 | + feedback_loop_traceability_history |
| 328 | + ); |
| 329 | + field!("Delivery state", delivery_state); |
| 330 | + hist!("Delivery state", delivery_state_history); |
| 331 | + field!("Difficulty (descriptive)", difficulty); |
| 332 | + field!("Autonomy (descriptive)", autonomy); |
| 333 | + field!("Iteration maturity", iteration_maturity); |
| 334 | + text( |
| 335 | + &mut out, |
| 336 | + "Stopping evidence", |
| 337 | + goal.stopping_evidence.as_deref(), |
| 338 | + ); |
| 339 | + } |
| 340 | + out |
| 341 | +} |
| 342 | + |
| 343 | +#[cfg(test)] |
| 344 | +#[path = "completion_report_tests.rs"] |
| 345 | +mod tests; |
0 commit comments