Skip to main content

SessionReport

Struct SessionReport 

Source
pub struct SessionReport {
    pub metrics: SessionMetrics,
    pub duration: Duration,
    pub safety_stop_reason: Option<String>,
}
Expand description

Complete session report combining metrics, duration, and stop reason, with serialization to both JSON and Markdown formats.

Fields§

§metrics: SessionMetrics

Aggregated session metrics.

§duration: Duration

Total wall-clock duration of the session.

§safety_stop_reason: Option<String>

Human-readable reason the session stopped, if a safety stop occurred.

Implementations§

Source§

impl SessionReport

Source

pub fn new( metrics: SessionMetrics, duration: Duration, stop_reason: Option<SafetyStop>, ) -> Self

Create a new session report from metrics, duration, and optional stop reason.

Examples found in repository?
examples/session_metrics.rs (lines 82-86)
11fn main() {
12    println!("=== Session Metrics & Reporting Example ===\n");
13
14    // 1. Build up session metrics
15    let mut metrics = SessionMetrics::new();
16
17    // Simulate a session with multiple strategies
18    let strategies = [
19        ("clippy", 3, 2, vec![5, 8]),
20        ("dead_code", 2, 1, vec![12]),
21        ("doc_gaps", 4, 3, vec![3, 6, 4]),
22        ("refactoring", 1, 0, vec![]),
23    ];
24
25    println!("--- Recording Tasks ---");
26    for (name, generated, succeeded, iters) in &strategies {
27        metrics.record_generated(name, *generated);
28        for _ in 0..*generated {
29            metrics.record_attempt(name);
30        }
31        for &iter_count in iters.iter() {
32            metrics.record_success(name, iter_count);
33        }
34        let failed = *generated - *succeeded;
35        for _ in 0..failed {
36            metrics.record_failure(name);
37        }
38        println!(
39            "  {name}: generated={generated}, succeeded={succeeded}, failed={}",
40            generated - succeeded
41        );
42    }
43
44    // Record commits
45    metrics.record_commit("a1b2c3d".to_string());
46    metrics.record_commit("e4f5g6h".to_string());
47    metrics.record_commit("i7j8k9l".to_string());
48
49    // Record a dual-path comparison
50    metrics.record_comparison(ComparisonResult {
51        both_succeeded: true,
52        both_failed: false,
53        diffs_match: true,
54        iteration_delta: -3,
55        bridge_specific_errors: vec![],
56    });
57    metrics.record_comparison(ComparisonResult {
58        both_succeeded: false,
59        both_failed: false,
60        diffs_match: false,
61        iteration_delta: 5,
62        bridge_specific_errors: vec!["timeout on bridge path".to_string()],
63    });
64
65    println!();
66
67    // 2. Print summary
68    println!("--- Summary ---");
69    println!("  Tasks attempted  : {}", metrics.tasks_attempted);
70    println!("  Tasks succeeded  : {}", metrics.tasks_succeeded);
71    println!("  Tasks failed     : {}", metrics.tasks_failed);
72    println!("  Total iterations : {}", metrics.total_iterations);
73    println!(
74        "  Success rate     : {:.1}%",
75        metrics.success_rate() * 100.0
76    );
77    println!("  Commits          : {}", metrics.commits.len());
78    println!("  Comparisons      : {}", metrics.comparisons.len());
79    println!();
80
81    // 3. Generate a session report
82    let report = SessionReport::new(
83        metrics,
84        Duration::from_secs(185),
85        None, // no safety stop
86    );
87
88    // 4. JSON output
89    println!("--- JSON Report (truncated) ---");
90    let json = report.to_json().unwrap();
91    // Print first 500 chars
92    let preview: String = json.chars().take(500).collect();
93    println!("{preview}...\n");
94
95    // 5. Markdown output
96    println!("--- Markdown Report ---");
97    let md = report.to_markdown();
98    println!("{md}");
99
100    println!("Done.");
101}
Source

pub fn to_json(&self) -> Result<String, Error>

Serialize the report to pretty-printed JSON.

Examples found in repository?
examples/session_metrics.rs (line 90)
11fn main() {
12    println!("=== Session Metrics & Reporting Example ===\n");
13
14    // 1. Build up session metrics
15    let mut metrics = SessionMetrics::new();
16
17    // Simulate a session with multiple strategies
18    let strategies = [
19        ("clippy", 3, 2, vec![5, 8]),
20        ("dead_code", 2, 1, vec![12]),
21        ("doc_gaps", 4, 3, vec![3, 6, 4]),
22        ("refactoring", 1, 0, vec![]),
23    ];
24
25    println!("--- Recording Tasks ---");
26    for (name, generated, succeeded, iters) in &strategies {
27        metrics.record_generated(name, *generated);
28        for _ in 0..*generated {
29            metrics.record_attempt(name);
30        }
31        for &iter_count in iters.iter() {
32            metrics.record_success(name, iter_count);
33        }
34        let failed = *generated - *succeeded;
35        for _ in 0..failed {
36            metrics.record_failure(name);
37        }
38        println!(
39            "  {name}: generated={generated}, succeeded={succeeded}, failed={}",
40            generated - succeeded
41        );
42    }
43
44    // Record commits
45    metrics.record_commit("a1b2c3d".to_string());
46    metrics.record_commit("e4f5g6h".to_string());
47    metrics.record_commit("i7j8k9l".to_string());
48
49    // Record a dual-path comparison
50    metrics.record_comparison(ComparisonResult {
51        both_succeeded: true,
52        both_failed: false,
53        diffs_match: true,
54        iteration_delta: -3,
55        bridge_specific_errors: vec![],
56    });
57    metrics.record_comparison(ComparisonResult {
58        both_succeeded: false,
59        both_failed: false,
60        diffs_match: false,
61        iteration_delta: 5,
62        bridge_specific_errors: vec!["timeout on bridge path".to_string()],
63    });
64
65    println!();
66
67    // 2. Print summary
68    println!("--- Summary ---");
69    println!("  Tasks attempted  : {}", metrics.tasks_attempted);
70    println!("  Tasks succeeded  : {}", metrics.tasks_succeeded);
71    println!("  Tasks failed     : {}", metrics.tasks_failed);
72    println!("  Total iterations : {}", metrics.total_iterations);
73    println!(
74        "  Success rate     : {:.1}%",
75        metrics.success_rate() * 100.0
76    );
77    println!("  Commits          : {}", metrics.commits.len());
78    println!("  Comparisons      : {}", metrics.comparisons.len());
79    println!();
80
81    // 3. Generate a session report
82    let report = SessionReport::new(
83        metrics,
84        Duration::from_secs(185),
85        None, // no safety stop
86    );
87
88    // 4. JSON output
89    println!("--- JSON Report (truncated) ---");
90    let json = report.to_json().unwrap();
91    // Print first 500 chars
92    let preview: String = json.chars().take(500).collect();
93    println!("{preview}...\n");
94
95    // 5. Markdown output
96    println!("--- Markdown Report ---");
97    let md = report.to_markdown();
98    println!("{md}");
99
100    println!("Done.");
101}
Source

pub fn to_markdown(&self) -> String

Render the report as a Markdown document.

Examples found in repository?
examples/session_metrics.rs (line 97)
11fn main() {
12    println!("=== Session Metrics & Reporting Example ===\n");
13
14    // 1. Build up session metrics
15    let mut metrics = SessionMetrics::new();
16
17    // Simulate a session with multiple strategies
18    let strategies = [
19        ("clippy", 3, 2, vec![5, 8]),
20        ("dead_code", 2, 1, vec![12]),
21        ("doc_gaps", 4, 3, vec![3, 6, 4]),
22        ("refactoring", 1, 0, vec![]),
23    ];
24
25    println!("--- Recording Tasks ---");
26    for (name, generated, succeeded, iters) in &strategies {
27        metrics.record_generated(name, *generated);
28        for _ in 0..*generated {
29            metrics.record_attempt(name);
30        }
31        for &iter_count in iters.iter() {
32            metrics.record_success(name, iter_count);
33        }
34        let failed = *generated - *succeeded;
35        for _ in 0..failed {
36            metrics.record_failure(name);
37        }
38        println!(
39            "  {name}: generated={generated}, succeeded={succeeded}, failed={}",
40            generated - succeeded
41        );
42    }
43
44    // Record commits
45    metrics.record_commit("a1b2c3d".to_string());
46    metrics.record_commit("e4f5g6h".to_string());
47    metrics.record_commit("i7j8k9l".to_string());
48
49    // Record a dual-path comparison
50    metrics.record_comparison(ComparisonResult {
51        both_succeeded: true,
52        both_failed: false,
53        diffs_match: true,
54        iteration_delta: -3,
55        bridge_specific_errors: vec![],
56    });
57    metrics.record_comparison(ComparisonResult {
58        both_succeeded: false,
59        both_failed: false,
60        diffs_match: false,
61        iteration_delta: 5,
62        bridge_specific_errors: vec!["timeout on bridge path".to_string()],
63    });
64
65    println!();
66
67    // 2. Print summary
68    println!("--- Summary ---");
69    println!("  Tasks attempted  : {}", metrics.tasks_attempted);
70    println!("  Tasks succeeded  : {}", metrics.tasks_succeeded);
71    println!("  Tasks failed     : {}", metrics.tasks_failed);
72    println!("  Total iterations : {}", metrics.total_iterations);
73    println!(
74        "  Success rate     : {:.1}%",
75        metrics.success_rate() * 100.0
76    );
77    println!("  Commits          : {}", metrics.commits.len());
78    println!("  Comparisons      : {}", metrics.comparisons.len());
79    println!();
80
81    // 3. Generate a session report
82    let report = SessionReport::new(
83        metrics,
84        Duration::from_secs(185),
85        None, // no safety stop
86    );
87
88    // 4. JSON output
89    println!("--- JSON Report (truncated) ---");
90    let json = report.to_json().unwrap();
91    // Print first 500 chars
92    let preview: String = json.chars().take(500).collect();
93    println!("{preview}...\n");
94
95    // 5. Markdown output
96    println!("--- Markdown Report ---");
97    let md = report.to_markdown();
98    println!("{md}");
99
100    println!("Done.");
101}
Source

pub fn save(&self, output_dir: &str) -> Result<()>

Save the report to both JSON and Markdown files in the given directory.

Trait Implementations§

Source§

impl Clone for SessionReport

Source§

fn clone(&self) -> SessionReport

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SessionReport

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for SessionReport

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for SessionReport

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,