cadi_core/rehydration/
config.rs

1//! View configuration
2
3use serde::{Deserialize, Serialize};
4
5/// Configuration for creating virtual views
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct ViewConfig {
8    /// Maximum tokens to include
9    #[serde(default = "default_max_tokens")]
10    pub max_tokens: usize,
11
12    /// Depth of automatic dependency expansion (Ghost Imports)
13    #[serde(default = "default_expansion_depth")]
14    pub expansion_depth: usize,
15
16    /// Include doc comments
17    #[serde(default = "default_true")]
18    pub include_docs: bool,
19
20    /// Include type definitions for referenced types
21    #[serde(default = "default_true")]
22    pub include_types: bool,
23
24    /// Format for the view output
25    #[serde(default)]
26    pub format: ViewFormat,
27
28    /// Add separator comments between atoms
29    #[serde(default = "default_true")]
30    pub add_separators: bool,
31
32    /// Sort atoms by type (imports first, then types, then functions)
33    #[serde(default = "default_true")]
34    pub sort_by_type: bool,
35
36    /// Deduplicate atoms that appear multiple times
37    #[serde(default = "default_true")]
38    pub deduplicate: bool,
39}
40
41fn default_max_tokens() -> usize { 8000 }
42fn default_expansion_depth() -> usize { 1 }
43fn default_true() -> bool { true }
44
45impl Default for ViewConfig {
46    fn default() -> Self {
47        Self {
48            max_tokens: default_max_tokens(),
49            expansion_depth: default_expansion_depth(),
50            include_docs: true,
51            include_types: true,
52            format: ViewFormat::Source,
53            add_separators: true,
54            sort_by_type: true,
55            deduplicate: true,
56        }
57    }
58}
59
60impl ViewConfig {
61    /// Create a minimal config (no expansion, compact output)
62    pub fn minimal() -> Self {
63        Self {
64            max_tokens: 2000,
65            expansion_depth: 0,
66            include_docs: false,
67            include_types: false,
68            format: ViewFormat::Minimal,
69            add_separators: false,
70            sort_by_type: false,
71            deduplicate: true,
72        }
73    }
74
75    /// Create a config for documentation purposes
76    pub fn documented() -> Self {
77        Self {
78            max_tokens: 16000,
79            expansion_depth: 2,
80            include_docs: true,
81            include_types: true,
82            format: ViewFormat::Documented,
83            add_separators: true,
84            sort_by_type: true,
85            deduplicate: true,
86        }
87    }
88
89    /// Set maximum tokens
90    pub fn with_max_tokens(mut self, tokens: usize) -> Self {
91        self.max_tokens = tokens;
92        self
93    }
94
95    /// Set expansion depth
96    pub fn with_expansion(mut self, depth: usize) -> Self {
97        self.expansion_depth = depth;
98        self
99    }
100
101    /// Disable Ghost Imports
102    pub fn no_expansion(mut self) -> Self {
103        self.expansion_depth = 0;
104        self
105    }
106}
107
108/// Output format for views
109#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
110#[serde(rename_all = "snake_case")]
111pub enum ViewFormat {
112    /// Full source code
113    #[default]
114    Source,
115    /// Minimal (no comments, compact)
116    Minimal,
117    /// With documentation
118    Documented,
119    /// Type signatures only (no function bodies)
120    Signatures,
121    /// JSON representation
122    Json,
123}