Skip to content

Commit 01c0bea

Browse files
committed
Render todo completion snapshots with pinned cards and full evidence
1 parent 9499712 commit 01c0bea

3 files changed

Lines changed: 168 additions & 6 deletions

File tree

‎crates/jcode-tui/src/tui/app/tests/todo_completion.rs‎

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ fn todo_completion_report_is_full_nonblocking_and_independent_of_poke() {
3131
crate::todo::save_todos(&session_id, &todos).unwrap();
3232
assert!(!app.refresh_completed_todo_report(true));
3333
todos = completion_report_todos("completed");
34+
todos[11].details = Some(format!(
35+
"Evidence for task 11 {} FINAL_EVIDENCE_MARKER",
36+
"long evidence with Unicode 測試 and punctuation * _ < > &. ".repeat(80)
37+
));
3438
crate::todo::save_todos(&session_id, &todos).unwrap();
3539
crate::todo::save_plan(
3640
&session_id,
@@ -51,6 +55,10 @@ fn todo_completion_report_is_full_nonblocking_and_independent_of_poke() {
5155
feedback_loop_relevance: Some(
5256
crate::todo::FeedbackLoopRelevance::AcceptanceBlocked,
5357
),
58+
feedback_loop_relevance_history: vec![
59+
crate::todo::FeedbackLoopRelevance::Indirect,
60+
crate::todo::FeedbackLoopRelevance::AcceptanceBlocked,
61+
],
5462
iteration_maturity: Some(crate::todo::IterationMaturity::ConstraintsExhausted),
5563
stopping_evidence: Some("External service unavailable".into()),
5664
..Default::default()
@@ -63,12 +71,13 @@ fn todo_completion_report_is_full_nonblocking_and_independent_of_poke() {
6371
assert_eq!(reports.len(), 1);
6472
let report = (*reports[0]).clone();
6573
let content = &report.content;
74+
let snapshot: serde_json::Value = serde_json::from_str(content).unwrap();
75+
assert_eq!(snapshot["todo_completion_version"], 1);
6676
for expected in [
6777
"Report task 0",
6878
"Report task 11",
6979
"Evidence for task 11",
70-
"acceptance&#95;blocked",
71-
"acceptance path blocked",
80+
"acceptance_blocked",
7281
"uncertain",
7382
"External service unavailable",
7483
"Show all evidence without another agent turn",
@@ -94,8 +103,22 @@ fn todo_completion_report_is_full_nonblocking_and_independent_of_poke() {
94103
.join("\n");
95104
let normalized = plain.split_whitespace().collect::<Vec<_>>().join(" ");
96105
assert!(normalized.contains("Report task 11"), "{plain}");
97-
if width >= 40 {
98-
assert!(plain.contains("acceptance_blocked"), "{plain}");
106+
// Removing wrap whitespace lets us assert every detail even when
107+
// an individual word has to be split at a narrow terminal width.
108+
let unwrapped: String = plain.chars().filter(|ch| !ch.is_whitespace()).collect();
109+
for expected in [
110+
"Evidence for task 11",
111+
"FINAL_EVIDENCE_MARKER",
112+
"acceptance_blocked",
113+
"acceptance path blocked",
114+
"Earlier weak states",
115+
"feedback_loop_relevance was indirect",
116+
"intent understanding was uncertain",
117+
"External service unavailable",
118+
"Current weaknesses, limitations, or missing assessments",
119+
] {
120+
let expected: String = expected.chars().filter(|ch| !ch.is_whitespace()).collect();
121+
assert!(unwrapped.contains(&expected), "missing {expected}: {plain}");
99122
}
100123
for line in &lines {
101124
assert!(line.width() <= width as usize, "width {width}: {line}");
@@ -121,6 +144,12 @@ fn todo_completion_report_refreshes_evidence_and_preserves_previous_cycles() {
121144
.content
122145
.contains("Additional acceptance evidence")
123146
);
147+
let first_report = completion_report_messages(&app)[0].clone();
148+
let first_render = crate::tui::ui::render_system_message(
149+
&first_report,
150+
40,
151+
crate::config::DiffDisplayMode::Off,
152+
);
124153

125154
todos[0].status = "in_progress".into();
126155
crate::todo::save_todos(&session_id, &todos).unwrap();
@@ -133,6 +162,15 @@ fn todo_completion_report_refreshes_evidence_and_preserves_previous_cycles() {
133162
assert_eq!(reports.len(), 2);
134163
assert!(!reports[0].content.contains("Second cycle task"));
135164
assert!(reports[1].content.contains("Second cycle task"));
165+
assert_eq!(
166+
crate::tui::ui::render_system_message(
167+
reports[0],
168+
40,
169+
crate::config::DiffDisplayMode::Off,
170+
),
171+
first_render,
172+
"historic report must not read the current todo file"
173+
);
136174
assert!(app.queued_messages.is_empty());
137175
});
138176
}

‎crates/jcode-tui/src/tui/app/todo_completion.rs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,15 @@ impl App {
6464
return false;
6565
}
6666

67-
let content =
68-
crate::todo::completion_report::render_completion_report(&todos, &plan, &goals);
67+
// Persist data rather than a reference to the live todo file so earlier
68+
// completion cycles remain unchanged when work resumes.
69+
let content = serde_json::json!({
70+
"todo_completion_version": 1,
71+
"todos": todos,
72+
"plan": plan,
73+
"goals": goals,
74+
})
75+
.to_string();
6976
let updating = self.todo_completion_report.fingerprint.is_some();
7077
self.todo_completion_report.fingerprint = Some(fingerprint);
7178
// Late evidence/assessment writes update this cycle's report rather
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//! Snapshot-based completion reports, with the same card as the pinned band.
2+
use super::*;
3+
4+
#[derive(serde::Deserialize)]
5+
struct Snapshot {
6+
todo_completion_version: u32,
7+
todos: Vec<crate::todo::TodoItem>,
8+
plan: crate::todo::TodoPlan,
9+
goals: Vec<crate::todo::TodoGoal>,
10+
}
11+
12+
pub(super) fn render(
13+
msg: &DisplayMessage,
14+
width: u16,
15+
diff_mode: crate::config::DiffDisplayMode,
16+
) -> Option<Vec<Line<'static>>> {
17+
if msg.title.as_deref() != Some("Todo completion") {
18+
return None;
19+
}
20+
// Legacy Markdown reports and unknown versions retain the normal system
21+
// renderer. Never fetch live state while rendering a historic message.
22+
let snapshot: Snapshot = serde_json::from_str(&msg.content).ok()?;
23+
if snapshot.todo_completion_version != 1 {
24+
return None;
25+
}
26+
let width = width.max(1) as usize;
27+
let mut lines = markdown::wrap_lines(
28+
vec![Line::from(Span::styled(
29+
"Todo completion",
30+
Style::default().fg(todo_score_color()).bold(),
31+
))],
32+
width,
33+
);
34+
// The snapshot is also a valid current card payload. Reuse the actual
35+
// pinned renderer, including its grouping, stages, pips and assessments.
36+
lines.extend(render_pinned_todos_message(msg, width as u16, diff_mode));
37+
lines.push(Line::default());
38+
39+
// Cards intentionally abbreviate prose. The appendix never does: include
40+
// every field plus current and historical weaknesses from the same frozen
41+
// snapshot. Keep Markdown's semantic heading/emphasis styles, not the
42+
// generic system renderer's uniform color or compact-notice path.
43+
let details = crate::todo::completion_report::render_completion_report(
44+
&snapshot.todos,
45+
&snapshot.plan,
46+
&snapshot.goals,
47+
);
48+
let details = preserve_hard_line_breaks_for_markdown(&details);
49+
let mut appendix = markdown::render_markdown_with_width(&details, Some(width));
50+
for line in &mut appendix {
51+
for span in &mut line.spans {
52+
if span.style.fg.is_none() {
53+
span.style.fg = Some(todo_meta_color());
54+
}
55+
}
56+
}
57+
lines.extend(markdown::wrap_lines(appendix, width));
58+
// Preserve the pinned card's spans verbatim. Only pathological terminal
59+
// widths smaller than its indent need an extra wrapping pass.
60+
Some(
61+
lines
62+
.into_iter()
63+
.flat_map(|line| {
64+
if line.width() > width {
65+
markdown::wrap_lines(vec![line], width)
66+
} else {
67+
vec![line]
68+
}
69+
})
70+
.collect(),
71+
)
72+
}
73+
74+
#[cfg(test)]
75+
mod tests {
76+
use super::*;
77+
78+
#[test]
79+
fn todo_completion_reuses_styled_pinned_cards_at_all_widths() {
80+
let mut msg = DisplayMessage::system(
81+
serde_json::json!({
82+
"todo_completion_version": 1,
83+
"todos": [{"id": "done", "content": "Completed work", "status": "completed",
84+
"priority": "high", "completion_confidence": "verified"}],
85+
"plan": {},
86+
"goals": []
87+
})
88+
.to_string(),
89+
);
90+
msg.title = Some("Todo completion".into());
91+
for width in [20, 40, 80] {
92+
let lines = render_system_message(&msg, width, crate::config::DiffDisplayMode::Off);
93+
let card =
94+
render_pinned_todos_message(&msg, width, crate::config::DiffDisplayMode::Off);
95+
assert!(!card.is_empty());
96+
// Line equality checks semantic styles as well as actual text.
97+
assert_eq!(&lines[1..1 + card.len()], card.as_slice());
98+
assert!(lines.iter().all(|line| line.width() <= width as usize));
99+
}
100+
}
101+
102+
#[test]
103+
fn todo_completion_legacy_and_unknown_payloads_fall_back() {
104+
for content in [
105+
"# Todo completion report\n\nHistoric Markdown evidence",
106+
r#"{"todo_completion_version":2,"todos":[],"plan":{},"goals":[]}"#,
107+
"malformed snapshot",
108+
] {
109+
let mut msg = DisplayMessage::system(content.to_owned());
110+
msg.title = Some("Todo completion".into());
111+
assert!(render(&msg, 40, crate::config::DiffDisplayMode::Off).is_none());
112+
assert!(
113+
!render_system_message(&msg, 40, crate::config::DiffDisplayMode::Off).is_empty()
114+
);
115+
}
116+
}
117+
}

0 commit comments

Comments
 (0)