tldr_cli/commands/patterns/mod.rs
1//! Pattern Analysis commands for TLDR CLI
2//!
3//! This module provides commands for pattern analysis, including cohesion metrics,
4//! coupling analysis, interface extraction, temporal constraint
5//! mining, behavioral constraint extraction, and resource
6//! lifecycle analysis.
7//!
8//! # Commands
9//!
10//! - `cohesion`: Compute LCOM4 (Lack of Cohesion of Methods) metric for classes
11//! - `coupling`: Analyze coupling between two modules via cross-module calls
12//! - `interface`: Extract the public interface (API surface) of Python files
13//! - `temporal`: Mine temporal constraints (method call sequences) from a codebase
14//! - `behavioral`: Extract behavioral constraints (pre/postconditions, exceptions)
15//! - `resources`: Analyze resource lifecycle to detect leaks and issues
16//!
17//! # Module Structure
18//!
19//! ```text
20//! patterns/
21//! ├── mod.rs # Module exports and re-exports (this file)
22//! ├── types.rs # Shared data types across all commands
23//! ├── error.rs # PatternsError enum and Result type
24//! ├── validation.rs # Path safety, resource limits (TIGER mitigations)
25//! ├── cohesion.rs # cohesion command implementation
26//! ├── coupling.rs # coupling command implementation
27//! ├── interface.rs # interface command implementation
28//! ├── temporal.rs # temporal command implementation
29//! ├── behavioral.rs # behavioral command implementation
30//! └── resources.rs # resources command implementation
31//! ```
32//!
33//! # Schema Version
34//!
35//! All JSON output uses types from `types.rs` for consistent serialization.
36
37// behavioral: archived (T5 deep analysis)
38pub mod cohesion;
39pub mod coupling;
40pub mod error;
41pub mod interface;
42pub mod resources;
43pub mod temporal;
44pub mod types;
45pub mod validation;
46
47// Re-export core types for convenience
48pub use error::{PatternsError, PatternsResult};
49pub use types::{
50 // Behavioral types
51 BehavioralReport,
52 ClassBehavior,
53 // Cohesion types
54 ClassCohesion,
55 // Interface types
56 ClassInfo,
57 ClassInvariant,
58 CohesionReport,
59 CohesionSummary,
60 CohesionVerdict,
61 ComponentInfo,
62 ConditionSource,
63 // Enums
64 Confidence,
65 // Resource types
66 ContextSuggestion,
67 // Coupling types
68 CouplingReport,
69 CouplingVerdict,
70 CrossCall,
71 CrossCalls,
72 DocstringStyle,
73 DoubleCloseInfo,
74 EffectType,
75 ExceptionInfo,
76 FunctionBehavior,
77 FunctionInfo,
78 InterfaceInfo,
79 LeakInfo,
80 MethodInfo,
81 OutputFormat,
82 Postcondition,
83 Precondition,
84 ResourceConstraint,
85 ResourceInfo,
86 ResourceReport,
87 ResourceSummary,
88 SideEffect,
89 // Temporal types
90 TemporalConstraint,
91 TemporalExample,
92 TemporalMetadata,
93 TemporalReport,
94 Trigram,
95 UseAfterCloseInfo,
96 YieldInfo,
97};
98
99// Re-export Args types for CLI integration
100// BehavioralArgs: archived (T5 deep analysis)
101pub use cohesion::CohesionArgs;
102pub use coupling::CouplingArgs;
103pub use interface::InterfaceArgs;
104pub use resources::ResourcesArgs;
105pub use temporal::TemporalArgs;
106
107/// Schema version for JSON output format.
108/// Increment when output schema changes in incompatible ways.
109pub const SCHEMA_VERSION: &str = "1.0";
110
111// Phase 2: Re-export validation utilities (TIGER mitigations)
112pub use validation::{
113 // Depth checking (TIGER-03)
114 check_analysis_depth,
115 check_ast_depth,
116 check_directory_file_count,
117 // Path validation (TIGER-01, TIGER-02)
118 is_path_traversal_attempt,
119 // File validation (TIGER-08)
120 read_file_safe,
121 // Checked arithmetic (TIGER-03)
122 saturating_count_add,
123 saturating_depth_increment,
124 validate_directory_path,
125 validate_file_path,
126 validate_file_path_in_project,
127 validate_file_size,
128 // Function validation
129 validate_function_name,
130 within_limit,
131 // Constants (TIGER-08 mitigations)
132 MAX_ANALYSIS_DEPTH,
133 MAX_AST_DEPTH,
134 MAX_CLASSES_PER_FILE,
135 MAX_CLASS_COMPLEXITY,
136 MAX_CONSTRAINTS_PER_FILE,
137 MAX_DIRECTORY_FILES,
138 MAX_FIELDS_PER_CLASS,
139 MAX_FILE_SIZE,
140 MAX_FUNCTION_NAME_LEN,
141 MAX_METHODS_PER_CLASS,
142 MAX_PATHS,
143 MAX_TRIGRAMS,
144 WARN_FILE_SIZE,
145};