Repository navigation
Expand file tree
/
Copy pathtypes.rs
More file actions
346 lines (311 loc) · 10.1 KB
/
Copy pathtypes.rs
File metadata and controls
346 lines (311 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
//! Shared types for debug commands.
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
// =============================================================================
// Config types
// =============================================================================
/// Config debug output.
#[derive(Debug, Serialize)]
pub struct ConfigDebugOutput {
pub resolved: ResolvedConfig,
pub locations: ConfigLocations,
#[serde(skip_serializing_if = "Option::is_none")]
pub environment: Option<HashMap<String, String>>,
}
/// Resolved configuration values.
#[derive(Debug, Serialize)]
pub struct ResolvedConfig {
pub model: String,
pub provider: String,
pub cwd: PathBuf,
pub cortex_home: PathBuf,
}
/// Config file locations.
#[derive(Debug, Serialize)]
pub struct ConfigLocations {
pub global_config: PathBuf,
pub global_config_exists: bool,
pub local_config: Option<PathBuf>,
pub local_config_exists: bool,
}
/// Result of comparing two config files.
#[derive(Debug, Serialize)]
pub struct ConfigDiff {
pub only_in_global: Vec<String>,
pub only_in_local: Vec<String>,
pub unified_diff: String,
}
// =============================================================================
// File types
// =============================================================================
/// File debug output.
#[derive(Debug, Serialize)]
pub struct FileDebugOutput {
pub path: PathBuf,
pub exists: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<FileMetadata>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mime_type: Option<String>,
pub encoding: Option<String>,
pub is_binary: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub error: Option<String>,
/// Warning when the file appears to be actively modified
#[serde(skip_serializing_if = "Option::is_none")]
pub active_modification_warning: Option<String>,
}
/// File metadata.
#[derive(Debug, Serialize)]
pub struct FileMetadata {
pub size: u64,
/// For virtual filesystems (procfs, sysfs), stat() returns 0 but reading
/// the file may return actual content. This field stores the actual
/// content size when available.
#[serde(skip_serializing_if = "Option::is_none")]
pub actual_size: Option<u64>,
/// Whether the file is on a virtual filesystem (procfs, sysfs, etc.)
#[serde(skip_serializing_if = "Option::is_none")]
pub is_virtual_fs: Option<bool>,
pub is_file: bool,
pub is_dir: bool,
pub is_symlink: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub file_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub symlink_target: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub modified: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub created: Option<String>,
pub readonly: bool,
/// Unix-style permission string (e.g., "rw-r--r--")
#[serde(skip_serializing_if = "Option::is_none")]
pub permissions: Option<String>,
/// Numeric permission mode (e.g., 644)
#[serde(skip_serializing_if = "Option::is_none")]
pub mode: Option<u32>,
}
// =============================================================================
// LSP types
// =============================================================================
/// LSP server info.
#[derive(Debug, Serialize)]
pub struct LspServerInfo {
pub name: String,
pub language: String,
pub command: String,
pub installed: bool,
pub version: Option<String>,
pub path: Option<PathBuf>,
}
/// LSP debug output.
#[derive(Debug, Serialize)]
pub struct LspDebugOutput {
pub servers: Vec<LspServerInfo>,
#[serde(skip_serializing_if = "Option::is_none")]
pub connection_test: Option<LspConnectionTest>,
}
/// LSP connection test result.
#[derive(Debug, Serialize)]
pub struct LspConnectionTest {
pub server: String,
pub success: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub latency_ms: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub error: Option<String>,
}
// =============================================================================
// Ripgrep types
// =============================================================================
/// Ripgrep debug output.
#[derive(Debug, Serialize)]
pub struct RipgrepDebugOutput {
pub available: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub path: Option<PathBuf>,
#[serde(skip_serializing_if = "Option::is_none")]
pub searched_paths: Option<Vec<PathBuf>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub test_result: Option<RipgrepTestResult>,
}
/// Ripgrep test result.
#[derive(Debug, Serialize)]
pub struct RipgrepTestResult {
pub pattern: String,
pub directory: PathBuf,
pub matches_found: usize,
pub duration_ms: u64,
#[serde(skip_serializing_if = "Option::is_none")]
pub error: Option<String>,
}
// =============================================================================
// Skill types
// =============================================================================
/// Skill debug output.
#[derive(Debug, Serialize)]
pub struct SkillDebugOutput {
pub name: String,
pub path: Option<PathBuf>,
pub found: bool,
pub valid: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub definition: Option<SkillDefinition>,
pub errors: Vec<String>,
pub warnings: Vec<String>,
}
/// Skill definition (simplified).
#[derive(Debug, Serialize, Deserialize)]
pub struct SkillDefinition {
#[serde(default)]
pub name: String,
#[serde(default)]
pub description: String,
#[serde(default)]
pub version: Option<String>,
#[serde(default)]
pub author: Option<String>,
#[serde(default)]
pub commands: Vec<SkillCommand>,
}
/// Skill command definition.
#[derive(Debug, Serialize, Deserialize)]
pub struct SkillCommand {
pub name: String,
#[serde(default)]
pub description: Option<String>,
#[serde(default)]
pub command: Option<String>,
}
// =============================================================================
// Snapshot types
// =============================================================================
/// Snapshot debug output.
#[derive(Debug, Serialize)]
pub struct SnapshotDebugOutput {
pub snapshots_dir: PathBuf,
pub snapshots_dir_exists: bool,
pub snapshot_count: usize,
#[serde(skip_serializing_if = "Option::is_none")]
pub session_snapshots: Option<Vec<SnapshotInfo>>,
pub total_size_bytes: u64,
}
/// Snapshot info.
#[derive(Debug, Serialize)]
pub struct SnapshotInfo {
pub id: String,
pub timestamp: String,
pub size_bytes: u64,
}
// =============================================================================
// Paths types
// =============================================================================
/// Paths debug output.
#[derive(Debug, Serialize)]
pub struct PathsDebugOutput {
pub cortex_home: PathInfo,
pub config_dir: PathInfo,
pub data_dir: PathInfo,
pub cache_dir: PathInfo,
pub sessions_dir: PathInfo,
pub plugins_dir: PathInfo,
pub skills_dir: PathInfo,
pub agents_dir: PathInfo,
pub mcp_dir: PathInfo,
pub logs_dir: PathInfo,
pub snapshots_dir: PathInfo,
pub temp_dir: PathInfo,
}
/// Path info.
#[derive(Debug, Serialize)]
pub struct PathInfo {
pub path: PathBuf,
pub exists: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub size_bytes: Option<u64>,
}
impl PathInfo {
pub fn new(path: PathBuf) -> Self {
let exists = path.exists();
let size_bytes = if exists && path.is_dir() {
crate::debug_cmd::utils::dir_size(&path).ok()
} else if exists {
std::fs::metadata(&path).ok().map(|m| m.len())
} else {
None
};
Self {
path,
exists,
size_bytes,
}
}
}
// =============================================================================
// Wait types
// =============================================================================
/// Wait result output.
#[derive(Debug, Serialize)]
pub struct WaitResult {
pub condition: String,
pub success: bool,
pub waited_ms: u64,
#[serde(skip_serializing_if = "Option::is_none")]
pub error: Option<String>,
}
// =============================================================================
// System types
// =============================================================================
/// System debug output.
#[derive(Debug, Serialize)]
pub struct SystemDebugOutput {
pub os: OsInfo,
pub hardware: HardwareInfo,
pub environment: EnvironmentInfo,
pub cortex: CortexInfo,
}
/// Operating system information.
#[derive(Debug, Serialize)]
pub struct OsInfo {
pub name: String,
pub version: Option<String>,
pub family: String,
}
/// Hardware information.
#[derive(Debug, Serialize)]
pub struct HardwareInfo {
pub arch: String,
pub cpu_cores: Option<usize>,
/// Total memory in bytes (considers container limits on Linux)
#[serde(skip_serializing_if = "Option::is_none")]
pub total_memory_bytes: Option<u64>,
/// Human-readable memory string
#[serde(skip_serializing_if = "Option::is_none")]
pub total_memory: Option<String>,
/// Whether running in a container with memory limits
#[serde(skip_serializing_if = "Option::is_none")]
pub container_memory_limit: Option<bool>,
}
/// Environment information.
#[derive(Debug, Serialize)]
pub struct EnvironmentInfo {
pub shell: Option<String>,
pub home_dir: Option<PathBuf>,
pub current_dir: Option<PathBuf>,
pub user: Option<String>,
/// User ID (Unix only) - useful for container environments
#[serde(skip_serializing_if = "Option::is_none")]
pub uid: Option<u32>,
pub term: Option<String>,
}
/// Cortex-specific information.
#[derive(Debug, Serialize)]
pub struct CortexInfo {
pub version: String,
pub cortex_home: PathBuf,
pub rust_version: Option<String>,
}