返回 CodeWhale
plan.rs
根目录 / crates / tui / src / tui / history / plan.rs
1 //! Rendering for plan-update transcript cells.
2
3 use codewhale_localization::Locale;
4 use ratatui::text::Line;
5
6 use codewhale_engine::tools::plan::{PlanSnapshot, StepStatus};
7
8 use super::{ToolStatus, render_compact_kv, render_tool_header, tool_value_style};
9
10 /// Cell for plan updates emitted by the plan tool.
11 #[derive(Debug, Clone)]
12 pub struct PlanUpdateCell {
13 pub snapshot: PlanSnapshot,
14 pub status: ToolStatus,
15 }
16
17 impl PlanUpdateCell {
18 /// Render the plan update cell into lines.
19 #[cfg(test)]
20 pub fn lines_with_motion(&self, width: u16, low_motion: bool) -> Vec<Line<'static>> {
21 self.lines_with_motion_and_locale(width, low_motion, Locale::En)
22 }
23
24 pub fn lines_with_motion_and_locale(
25 &self,
26 width: u16,
27 low_motion: bool,
28 locale: Locale,
29 ) -> Vec<Line<'static>> {
30 let mut lines = Vec::new();
31 lines.push(render_tool_header(
32 "Legacy plan",
33 None,
34 self.status,
35 None,
36 low_motion,
37 locale,
38 ));
39
40 render_plan_snapshot_lines(&self.snapshot, &mut lines, width);
41
42 lines
43 }
44 }
45
46 fn render_plan_snapshot_lines(snapshot: &PlanSnapshot, lines: &mut Vec<Line<'static>>, width: u16) {
47 render_plan_optional(lines, "title", snapshot.title.as_deref(), width);
48 render_plan_optional(lines, "objective", snapshot.objective.as_deref(), width);
49 render_plan_optional(lines, "context", snapshot.context_summary.as_deref(), width);
50 render_plan_optional(lines, "explain", snapshot.explanation.as_deref(), width);
51 render_plan_list(lines, "source", &snapshot.sources_used, width);
52 render_plan_list(lines, "file", &snapshot.critical_files, width);
53 render_plan_list(lines, "constraint", &snapshot.constraints, width);
54 render_plan_optional(
55 lines,
56 "approach",
57 snapshot.recommended_approach.as_deref(),
58 width,
59 );
60 render_plan_optional(
61 lines,
62 "verify",
63 snapshot.verification_plan.as_deref(),
64 width,
65 );
66 render_plan_optional(lines, "risk", snapshot.risks_and_unknowns.as_deref(), width);
67 render_plan_optional(lines, "handoff", snapshot.handoff_packet.as_deref(), width);
68 render_plan_list(lines, "replan if", &snapshot.replan_if, width);
69
70 for step in &snapshot.items {
71 let marker = match step.status {
72 StepStatus::Completed => "done",
73 StepStatus::InProgress => "live",
74 StepStatus::Pending => "next",
75 };
76 lines.extend(render_compact_kv(
77 marker,
78 &step.step,
79 tool_value_style(),
80 width,
81 ));
82 }
83 }
84
85 fn render_plan_optional(
86 lines: &mut Vec<Line<'static>>,
87 label: &str,
88 value: Option<&str>,
89 width: u16,
90 ) {
91 if let Some(value) = value.map(str::trim).filter(|value| !value.is_empty()) {
92 lines.extend(render_compact_kv(label, value, tool_value_style(), width));
93 }
94 }
95
96 fn render_plan_list(lines: &mut Vec<Line<'static>>, label: &str, values: &[String], width: u16) {
97 for value in values {
98 let value = value.trim();
99 if !value.is_empty() {
100 lines.extend(render_compact_kv(label, value, tool_value_style(), width));
101 }
102 }
103 }
104
104 lines RUST