Skip to main content

relay_knowledge/storage/
file_index.rs

1//! Storage contracts for local file-location indexes.
2
3use serde::{Deserialize, Serialize};
4
5/// Authorized root scanned by the local file indexer.
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
7pub struct FileIndexRoot {
8    pub scope_id: String,
9    pub root_id: String,
10    pub root_path: String,
11}
12
13/// Indexed file-location record produced by a bounded scan.
14#[derive(Debug, Clone, PartialEq, Eq)]
15pub struct FileIndexEntry {
16    pub scope_id: String,
17    pub root_id: String,
18    pub path: String,
19    pub relative_path: String,
20    pub file_name: String,
21    pub extension: Option<String>,
22    pub parent_dir: String,
23    pub size_bytes: u64,
24    pub modified_at_ms: u64,
25    pub fingerprint: String,
26}
27
28/// Full-root replacement produced by one scan pass.
29#[derive(Debug, Clone, PartialEq, Eq)]
30pub struct FileIndexRootUpdate {
31    pub root: FileIndexRoot,
32    pub entries: Vec<FileIndexEntry>,
33    pub scan_error_count: usize,
34    pub truncated: bool,
35    pub last_error: Option<String>,
36    pub now_ms: u64,
37}
38
39/// Root-level status surfaced to health and service diagnostics.
40#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
41pub struct FileIndexRootStatus {
42    pub scope_id: String,
43    pub root_id: String,
44    pub root_path: String,
45    pub indexed_file_count: usize,
46    pub missing_file_count: usize,
47    pub scan_error_count: usize,
48    pub truncated: bool,
49    pub last_indexed_at_ms: Option<u64>,
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub last_error: Option<String>,
52}
53
54/// Summary returned after one or more roots are indexed.
55#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
56pub struct FileIndexScanSummary {
57    pub root_count: usize,
58    pub indexed_file_count: usize,
59    pub missing_file_count: usize,
60    pub scan_error_count: usize,
61    pub truncated_root_count: usize,
62    pub roots: Vec<FileIndexRootStatus>,
63}
64
65/// Bounded file-location query.
66#[derive(Debug, Clone, PartialEq, Eq)]
67pub struct FileSearchRequest {
68    pub query: String,
69    pub source_scope: Option<String>,
70    pub root_id: Option<String>,
71    pub limit: usize,
72    pub timeout_ms: u64,
73}
74
75/// One file-location search hit.
76#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
77pub struct FileSearchHit {
78    pub scope_id: String,
79    pub root_id: String,
80    pub path: String,
81    pub relative_path: String,
82    pub file_name: String,
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub extension: Option<String>,
85    pub parent_dir: String,
86    pub size_bytes: u64,
87    pub modified_at_ms: u64,
88    pub status: String,
89    pub rank: usize,
90    pub score: f64,
91}
92
93/// Aggregated file-index diagnostics.
94#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
95pub struct FileIndexDiagnostics {
96    pub root_count: usize,
97    pub indexed_file_count: usize,
98    pub missing_file_count: usize,
99    pub scan_error_count: usize,
100    pub truncated_root_count: usize,
101    pub roots: Vec<FileIndexRootStatus>,
102}