Skip to main content

winx_code_agent/utils/
mod.rs

1//! Utility modules for the Winx application.
2//!
3//! This module contains various utility functions and types used throughout
4//! the application, such as file and path handling, repository analysis, etc.
5
6pub mod bash_parser;
7pub mod command_safety;
8pub mod display_tree;
9pub mod encoder;
10pub mod file_cache;
11pub mod mmap;
12pub mod output_compress;
13pub mod path;
14pub mod path_prob;
15pub mod repo;
16pub mod syntax;
17pub mod workspace_stats;
18
19use crate::types::Initialize;
20use serde_json::Value;
21use tracing::debug;
22
23/// Debug helper to test JSON parsing of an Initialize request
24pub fn test_json_parsing(json_str: &str) -> Result<(), String> {
25    // First, try to parse as raw JSON to see if the format is valid
26    let raw_json_result = serde_json::from_str::<Value>(json_str);
27    if let Err(e) = raw_json_result {
28        return Err(format!("Invalid JSON format: {e}"));
29    }
30
31    // Now try to parse into our Initialize struct
32    let init_result = serde_json::from_str::<Initialize>(json_str);
33    match init_result {
34        Ok(init) => {
35            debug!(
36                init_type = ?init.init_type,
37                mode_name = ?init.mode_name,
38                code_writer_config = ?init.code_writer_config,
39                task_id_to_resume = init.task_id_to_resume,
40                "Successfully parsed JSON into Initialize struct"
41            );
42            Ok(())
43        }
44        Err(e) => Err(format!("Failed to parse JSON into Initialize struct: {e}")),
45    }
46}