trustformers_debug/tutorial/
system.rs1use anyhow::Result;
7
8pub struct TutorialMode {
10 current_lesson: usize,
11 lessons: Vec<TutorialLesson>,
12 completed_lessons: Vec<bool>,
13}
14
15#[derive(Debug, Clone)]
17pub struct TutorialLesson {
18 pub title: String,
19 pub description: String,
20 pub objectives: Vec<String>,
21 pub example_code: String,
22 pub expected_output: String,
23 pub tips: Vec<String>,
24 pub common_mistakes: Vec<String>,
25}
26
27impl Default for TutorialMode {
28 fn default() -> Self {
29 Self::new()
30 }
31}
32
33impl TutorialMode {
34 pub fn new() -> Self {
36 let lessons = create_tutorial_lessons();
37 let completed_lessons = vec![false; lessons.len()];
38
39 Self {
40 current_lesson: 0,
41 lessons,
42 completed_lessons,
43 }
44 }
45
46 pub fn current_lesson(&self) -> Option<&TutorialLesson> {
48 self.lessons.get(self.current_lesson)
49 }
50
51 pub fn get_lesson(&self, index: usize) -> Option<&TutorialLesson> {
53 self.lessons.get(index)
54 }
55
56 pub fn total_lessons(&self) -> usize {
58 self.lessons.len()
59 }
60
61 pub fn progress(&self) -> f64 {
63 let completed = self.completed_lessons.iter().filter(|&&x| x).count();
64 (completed as f64 / self.total_lessons() as f64) * 100.0
65 }
66
67 pub fn complete_current_lesson(&mut self) -> Result<()> {
69 if self.current_lesson < self.total_lessons() {
70 self.completed_lessons[self.current_lesson] = true;
71 self.current_lesson += 1;
72 Ok(())
73 } else {
74 Err(anyhow::anyhow!("No more lessons to complete"))
75 }
76 }
77
78 pub fn goto_lesson(&mut self, index: usize) -> Result<()> {
80 if index < self.total_lessons() {
81 self.current_lesson = index;
82 Ok(())
83 } else {
84 Err(anyhow::anyhow!("Invalid lesson index"))
85 }
86 }
87
88 pub fn is_complete(&self) -> bool {
90 self.completed_lessons.iter().all(|&x| x)
91 }
92
93 pub fn lesson_titles(&self) -> Vec<String> {
95 self.lessons.iter().map(|l| l.title.clone()).collect()
96 }
97}
98
99fn create_tutorial_lessons() -> Vec<TutorialLesson> {
101 vec![
102 TutorialLesson {
103 title: "Getting Started with TrustformeRS Debug".to_string(),
104 description: "Learn the basics of debugging with TrustformeRS".to_string(),
105 objectives: vec![
106 "Create a debug session".to_string(),
107 "Perform basic model inspection".to_string(),
108 "Generate a simple report".to_string(),
109 ],
110 example_code: r#"
111use trustformers_debug::*;
112
113// Create a debug session with default configuration
114let mut session = debug_session();
115
116// Start debugging
117session.start().await?;
118
119// Your model operations here...
120
121// Generate report
122let report = session.stop().await?;
123println!("Debug report: {:?}", report.summary());
124"#
125 .to_string(),
126 expected_output: "Debug session should start successfully and generate a report"
127 .to_string(),
128 tips: vec![
129 "Always call start() before debugging operations".to_string(),
130 "Use stop() to generate final report".to_string(),
131 "Check the summary for quick insights".to_string(),
132 ],
133 common_mistakes: vec![
134 "Forgetting to call start() before debugging".to_string(),
135 "Not handling async operations properly".to_string(),
136 ],
137 },
138 TutorialLesson {
139 title: "One-Line Debugging".to_string(),
140 description: "Use simplified debugging functions for quick analysis".to_string(),
141 objectives: vec![
142 "Use the debug() function".to_string(),
143 "Understand different debug levels".to_string(),
144 "Interpret simplified results".to_string(),
145 ],
146 example_code: r#"
147use trustformers_debug::*;
148
149// Quick debugging with automatic level detection
150let result = debug(&model).await?;
151println!("Summary: {}", result.summary());
152
153// Check for critical issues
154if result.has_critical_issues() {
155 println!("Critical issues found!");
156 for rec in result.recommendations() {
157 println!("- {}", rec);
158 }
159}
160
161// Use specific debug levels
162let light_result = quick_debug(&model, QuickDebugLevel::Light).await?;
163let deep_result = quick_debug(&model, QuickDebugLevel::Deep).await?;
164"#
165 .to_string(),
166 expected_output: "Quick analysis results with recommendations".to_string(),
167 tips: vec![
168 "Use Light level for quick checks".to_string(),
169 "Use Deep level for thorough analysis".to_string(),
170 "Check recommendations for actionable advice".to_string(),
171 ],
172 common_mistakes: vec![
173 "Using Deep level when Light would suffice".to_string(),
174 "Ignoring critical issue warnings".to_string(),
175 ],
176 },
177 TutorialLesson {
178 title: "Guided Debugging".to_string(),
179 description: "Step-by-step debugging with the guided debugger".to_string(),
180 objectives: vec![
181 "Use the guided debugger".to_string(),
182 "Execute debugging steps".to_string(),
183 "Understand step results".to_string(),
184 ],
185 example_code: r#"
186use trustformers_debug::*;
187
188// Create guided debugger
189let mut guided = GuidedDebugger::new();
190
191// Execute steps one by one
192while !guided.is_complete() {
193 if let Some(step) = guided.current_step() {
194 println!("Step {}/{}: {}",
195 guided.current_step + 1,
196 guided.total_steps(),
197 step.name
198 );
199 println!("Description: {}", step.description);
200
201 // Execute the step
202 let result = guided.execute_current_step().await?;
203 println!("Result: {:?}", result);
204 }
205}
206
207println!("Debugging complete! Progress: {:.1}%", guided.progress());
208"#
209 .to_string(),
210 expected_output: "Step-by-step execution with progress updates".to_string(),
211 tips: vec![
212 "Read step descriptions carefully".to_string(),
213 "You can skip steps if not relevant".to_string(),
214 "Monitor progress percentage".to_string(),
215 ],
216 common_mistakes: vec![
217 "Skipping important steps".to_string(),
218 "Not reading step descriptions".to_string(),
219 ],
220 },
221 ]
222}