Skip to content

Commit 2818e5d

Browse files
committed
Show only recorded turn-end gate findings in todo completion
1 parent 932fe95 commit 2818e5d

3 files changed

Lines changed: 152 additions & 61 deletions

File tree

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

Lines changed: 91 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ fn todo_completion_report_is_full_nonblocking_and_independent_of_poke() {
8989
assert!(!app.refresh_completed_todo_report(true));
9090
assert_eq!(completion_report_messages(&app).len(), 1);
9191

92-
// The actual renderer keeps the entire report at narrow terminal widths.
92+
// Descriptive assessments alone never fabricate gate findings.
93+
assert_eq!(snapshot["observations"], serde_json::json!([]));
94+
// The actual renderer retains the full pinned card at narrow widths.
9395
for width in [20, 40, 80] {
9496
let lines = crate::tui::ui::render_system_message(
9597
&report,
@@ -102,23 +104,28 @@ fn todo_completion_report_is_full_nonblocking_and_independent_of_poke() {
102104
.collect::<Vec<_>>()
103105
.join("\n");
104106
let normalized = plain.split_whitespace().collect::<Vec<_>>().join(" ");
105-
assert!(normalized.contains("Report task 11"), "{plain}");
107+
if width == 80 {
108+
assert!(normalized.contains("Report task 11"), "{plain}");
109+
}
106110
// Removing wrap whitespace lets us assert every detail even when
107111
// an individual word has to be split at a narrow terminal width.
108112
let unwrapped: String = plain.chars().filter(|ch| !ch.is_whitespace()).collect();
109-
for expected in [
110-
"Evidence for task 11",
113+
for unexpected in [
111114
"FINAL_EVIDENCE_MARKER",
112-
"acceptance_blocked",
113-
"acceptance path blocked",
114115
"Earlier weak states",
115116
"feedback_loop_relevance was indirect",
116117
"intent understanding was uncertain",
117-
"External service unavailable",
118118
"Current weaknesses, limitations, or missing assessments",
119+
"Disabled turn-end gate findings",
119120
] {
120-
let expected: String = expected.chars().filter(|ch| !ch.is_whitespace()).collect();
121-
assert!(unwrapped.contains(&expected), "missing {expected}: {plain}");
121+
let unexpected: String = unexpected
122+
.chars()
123+
.filter(|ch| !ch.is_whitespace())
124+
.collect();
125+
assert!(
126+
!unwrapped.contains(&unexpected),
127+
"unexpected {unexpected}: {plain}"
128+
);
122129
}
123130
for line in &lines {
124131
assert!(line.width() <= width as usize, "width {width}: {line}");
@@ -144,13 +151,87 @@ fn todo_completion_report_refreshes_evidence_and_preserves_previous_cycles() {
144151
.content
145152
.contains("Additional acceptance evidence")
146153
);
154+
let observations = vec![crate::todo::GateObservation {
155+
kind: crate::todo::GateObservationKind::IntentUnderstanding,
156+
group: None,
157+
state: Some("uncertain".into()),
158+
}];
159+
crate::todo::save_gate_observations(&session_id, &observations).unwrap();
160+
crate::todo::save_plan(
161+
&session_id,
162+
&crate::todo::TodoPlan {
163+
understands_user_intent: Some(crate::todo::IntentUnderstanding::Clear),
164+
..Default::default()
165+
},
166+
)
167+
.unwrap();
168+
assert!(app.refresh_completed_todo_report(true));
169+
assert_eq!(completion_report_messages(&app).len(), 1);
170+
assert!(!app.refresh_completed_todo_report(true));
171+
// Observation-only late writes must invalidate the fingerprint, and
172+
// repeated observations must retain the digest's count and wording.
173+
crate::todo::save_gate_observations(
174+
&session_id,
175+
&[observations[0].clone(), observations[0].clone()],
176+
)
177+
.unwrap();
178+
assert!(app.refresh_completed_todo_report(true));
179+
assert_eq!(completion_report_messages(&app).len(), 1);
147180
let first_report = completion_report_messages(&app)[0].clone();
148181
let first_render = crate::tui::ui::render_system_message(
149182
&first_report,
150183
40,
151184
crate::config::DiffDisplayMode::Off,
152185
);
153186

187+
let plain = first_render
188+
.iter()
189+
.map(|line| line.to_string())
190+
.collect::<Vec<_>>()
191+
.join(" ");
192+
let normalized = plain.split_whitespace().collect::<Vec<_>>().join(" ");
193+
assert!(normalized.contains("Disabled turn-end gate findings"));
194+
assert!(normalized.contains("started this work without understanding"));
195+
assert!(normalized.contains("flagged 2 times this turn"));
196+
assert!(!plain.contains("[auto]"));
197+
assert!(!normalized.contains("Do not reply or wait for the user"));
198+
let snapshot: serde_json::Value = serde_json::from_str(&first_report.content).unwrap();
199+
assert_eq!(snapshot["observations"].as_array().unwrap().len(), 2);
200+
crate::todo::clear_gate_observations(&session_id).unwrap();
201+
assert!(!app.refresh_completed_todo_report(true));
202+
assert_eq!(
203+
completion_report_messages(&app)[0].content,
204+
first_report.content
205+
);
206+
crate::todo::save_plan(
207+
&session_id,
208+
&crate::todo::TodoPlan {
209+
understands_user_intent: Some(crate::todo::IntentUnderstanding::Uncertain),
210+
..Default::default()
211+
},
212+
)
213+
.unwrap();
214+
assert!(app.refresh_completed_todo_report(true));
215+
let updated = completion_report_messages(&app)[0].clone();
216+
let text = crate::tui::ui::render_system_message(
217+
&updated,
218+
200,
219+
crate::config::DiffDisplayMode::Off,
220+
)
221+
.iter()
222+
.map(|line| line.to_string())
223+
.collect::<Vec<_>>()
224+
.join(" ");
225+
let text = text.split_whitespace().collect::<Vec<_>>().join(" ");
226+
assert!(text.contains("never became solid"));
227+
assert!(text.contains("flagged 2 times this turn"));
228+
// This updated snapshot is the immutable record for the earlier cycle.
229+
let first_render = crate::tui::ui::render_system_message(
230+
&updated,
231+
40,
232+
crate::config::DiffDisplayMode::Off,
233+
);
234+
154235
todos[0].status = "in_progress".into();
155236
crate::todo::save_todos(&session_id, &todos).unwrap();
156237
assert!(!app.refresh_completed_todo_report(true));
@@ -162,6 +243,7 @@ fn todo_completion_report_refreshes_evidence_and_preserves_previous_cycles() {
162243
assert_eq!(reports.len(), 2);
163244
assert!(!reports[0].content.contains("Second cycle task"));
164245
assert!(reports[1].content.contains("Second cycle task"));
246+
assert!(reports[1].content.contains("\"observations\":[]"));
165247
assert_eq!(
166248
crate::tui::ui::render_system_message(
167249
reports[0],

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ pub(super) struct TodoCompletionReportState {
1313
session_id: Option<String>,
1414
fingerprint: Option<u64>,
1515
checked_at: Option<Instant>,
16+
observations: Vec<crate::todo::GateObservation>,
1617
}
1718

1819
impl App {
19-
/// Render every finished item and its assessments without entering the
20+
/// Render every finished item and recorded gate finding without entering the
2021
/// provider conversation or depending on auto-poke being enabled.
2122
pub(super) fn refresh_completed_todo_report(&mut self, force: bool) -> bool {
2223
if crate::tui::is_ssh_remote() {
@@ -50,11 +51,34 @@ impl App {
5051
{
5152
// Reopening work starts a new cycle; preserve its earlier report.
5253
self.todo_completion_report.fingerprint = None;
54+
self.todo_completion_report.observations.clear();
5355
return false;
5456
}
5557
let plan = crate::todo::load_plan(&session_id).unwrap_or_default();
5658
let goals = crate::todo::load_goals(&session_id).unwrap_or_default();
57-
let Ok(serialized) = serde_json::to_vec(&(&todos, &plan, &goals)) else {
59+
let recorded = crate::todo::load_gate_observations(&session_id).unwrap_or_default();
60+
// Turn-end processing clears the live log. Retain this completion
61+
// cycle's findings, including repeat counts, across that clearing and
62+
// late assessment writes. A reopened cycle starts a fresh collection.
63+
for (index, observation) in recorded.iter().enumerate() {
64+
let count = recorded[..=index]
65+
.iter()
66+
.filter(|entry| *entry == observation)
67+
.count();
68+
let captured_count = self
69+
.todo_completion_report
70+
.observations
71+
.iter()
72+
.filter(|entry| *entry == observation)
73+
.count();
74+
if count > captured_count {
75+
self.todo_completion_report
76+
.observations
77+
.push(observation.clone());
78+
}
79+
}
80+
let observations = &self.todo_completion_report.observations;
81+
let Ok(serialized) = serde_json::to_vec(&(&todos, &plan, &goals, &observations)) else {
5882
return false;
5983
};
6084
let mut hasher = DefaultHasher::new();
@@ -71,6 +95,7 @@ impl App {
7195
"todos": todos,
7296
"plan": plan,
7397
"goals": goals,
98+
"observations": observations,
7499
})
75100
.to_string();
76101
let updating = self.todo_completion_report.fingerprint.is_some();

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

Lines changed: 34 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use super::*;
44
#[derive(serde::Deserialize)]
55
struct Snapshot {
66
todo_completion_version: u32,
7-
todos: Vec<crate::todo::TodoItem>,
7+
#[serde(default)]
8+
observations: Vec<crate::todo::GateObservation>,
89
plan: crate::todo::TodoPlan,
910
goals: Vec<crate::todo::TodoGoal>,
1011
}
@@ -34,16 +35,12 @@ pub(super) fn render(
3435
// The snapshot is also a valid current card payload. Reuse the actual
3536
// pinned renderer, including its grouping, stages, pips and assessments.
3637
lines.extend(render_pinned_todos_message(msg, width as u16, diff_mode));
37-
lines.push(Line::default());
38-
39-
// Cards intentionally abbreviate prose. Keep the full evidence underneath
40-
// in compact semantic rows rather than a second, large Markdown document.
41-
let details = crate::todo::completion_report::render_completion_report(
42-
&snapshot.todos,
43-
&snapshot.plan,
44-
&snapshot.goals,
45-
);
46-
lines.extend(render_detail_rows(&details, width));
38+
if let Some(digest) =
39+
crate::todo::build_gate_digest(&snapshot.observations, &snapshot.plan, &snapshot.goals)
40+
{
41+
lines.push(Line::default());
42+
lines.extend(render_detail_rows(&digest, width));
43+
}
4744
// Preserve the pinned card's spans verbatim. Only pathological terminal
4845
// widths smaller than its indent need an extra wrapping pass.
4946
Some(
@@ -61,42 +58,22 @@ pub(super) fn render(
6158
}
6259

6360
fn render_detail_rows(details: &str, width: usize) -> Vec<Line<'static>> {
64-
let mut lines = Vec::new();
65-
let mut weaknesses = false;
66-
for raw in details.lines().filter(|line| !line.is_empty()) {
67-
if raw.starts_with("# ") {
68-
continue;
69-
}
70-
let (text, color, bold) = if let Some(heading) = raw.strip_prefix("## ") {
71-
weaknesses = heading.starts_with("Current weaknesses")
72-
|| heading.starts_with("Earlier weak states");
73-
lines.push(Line::default());
74-
(heading, todo_group_color(), true)
75-
} else if let Some(heading) = raw.strip_prefix("### ") {
76-
(heading, todo_group_color(), true)
77-
} else if let Some(item) = raw.strip_prefix("- ") {
78-
(
79-
item,
80-
if weaknesses {
81-
todo_warning_color()
82-
} else {
83-
todo_meta_color()
84-
},
85-
false,
86-
)
87-
} else {
88-
(raw, todo_meta_color(), false)
89-
};
90-
// Decode the formatter's escaped data through the existing Markdown
91-
// parser. It cannot become active markup because punctuation is escaped.
92-
let rendered = markdown::render_markdown_with_width(text, Some(width));
61+
let mut lines = markdown::wrap_lines(
62+
vec![Line::from(Span::styled(
63+
" Disabled turn-end gate findings",
64+
Style::default().fg(todo_group_color()).bold(),
65+
))],
66+
width,
67+
);
68+
// Only digest bullets are display data. Its automatic continuation header
69+
// must never appear here or be dispatched as a model instruction.
70+
for item in details.lines().filter_map(|line| line.strip_prefix("- ")) {
71+
let text = format!("• {item}");
72+
let rendered = markdown::wrap_lines(vec![Line::raw(text)], width.saturating_sub(2).max(1));
9373
for mut line in rendered {
9474
line.spans.insert(0, Span::raw(" "));
9575
for span in &mut line.spans {
96-
span.style.fg = Some(color);
97-
if bold {
98-
span.style = span.style.bold();
99-
}
76+
span.style.fg = Some(todo_warning_color());
10077
}
10178
lines.extend(markdown::wrap_lines(vec![line], width));
10279
}
@@ -111,10 +88,10 @@ mod tests {
11188
#[test]
11289
fn todo_completion_details_use_compact_warning_rows() {
11390
let lines = render_detail_rows(
114-
"# Todo completion report\n\n## Current weaknesses\n\n- acceptance path blocked\n\n## Plan\n\n- **User intention:** Preserve all evidence\n- **Intent:** clear\n",
91+
"[auto] Do not reply or wait for the user.\n- acceptance path blocked",
11592
80,
11693
);
117-
assert_eq!(lines.len(), 7);
94+
assert_eq!(lines.len(), 2);
11895
let warning = lines
11996
.iter()
12097
.find(|line| line.to_string().contains("acceptance path blocked"))
@@ -125,10 +102,12 @@ mod tests {
125102
.iter()
126103
.all(|span| span.style.fg == Some(todo_warning_color()))
127104
);
128-
assert!(lines.iter().any(|line| {
129-
line.to_string()
130-
.contains("User intention: Preserve all evidence")
131-
}));
105+
assert!(
106+
lines[0]
107+
.to_string()
108+
.contains("Disabled turn-end gate findings")
109+
);
110+
assert!(!lines.iter().any(|line| line.to_string().contains("[auto]")));
132111
}
133112

134113
#[test]
@@ -151,6 +130,11 @@ mod tests {
151130
assert!(!card.is_empty());
152131
// Line equality checks semantic styles as well as actual text.
153132
assert_eq!(&lines[1..1 + card.len()], card.as_slice());
133+
assert_eq!(
134+
lines.len(),
135+
1 + card.len(),
136+
"legacy snapshots have no appendix"
137+
);
154138
assert!(lines.iter().all(|line| line.width() <= width as usize));
155139
}
156140
}

0 commit comments

Comments
 (0)