Skip to main content

code_kb_core/
models.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
4pub struct Symbol {
5    pub symbol_id: String,
6    pub file_id: String,
7    pub path: String,
8    pub language: String,
9    pub name: String,
10    pub kind: String,
11    pub signature: Option<String>,
12    pub doc_comment: Option<String>,
13    pub visibility: Option<String>,
14    pub parent_symbol_id: Option<String>,
15    pub start_line: usize,
16    pub start_column: usize,
17    pub end_line: usize,
18    pub end_column: usize,
19    pub start_byte: usize,
20    pub end_byte: usize,
21    pub body_start_line: Option<usize>,
22    pub body_start_column: Option<usize>,
23    pub body_end_line: Option<usize>,
24    pub body_end_column: Option<usize>,
25    pub body_start_byte: Option<usize>,
26    pub body_end_byte: Option<usize>,
27    pub body_hash: Option<String>,
28    pub semantic_group: Option<String>,
29    pub is_test: bool,
30    pub test_container: bool,
31}
32
33impl Symbol {
34    /// Helper to compute hidden line count in implementation body if present.
35    pub fn hidden_body_line_count(&self) -> Option<usize> {
36        match (self.body_start_line, self.body_end_line) {
37            (Some(start), Some(end)) if end >= start => Some(end - start + 1),
38            _ => None,
39        }
40    }
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
44pub struct FileFact {
45    pub file_id: String,
46    pub path: String,
47    pub language: String,
48    pub content_hash: String,
49    pub content_bytes: i64,
50    pub line_count: Option<i64>,
51    pub indexed_at: String,
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
55pub struct ReferenceSite {
56    pub from_symbol_name: String,
57    pub from_symbol_id: String,
58    pub to_symbol_name: String,
59    pub kind: String,
60    pub path: String,
61    pub start_line: Option<usize>,
62    pub start_column: Option<usize>,
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
66pub struct StructuralFact {
67    pub structural_fact_id: String,
68    pub path: String,
69    pub language: String,
70    pub pattern_id: String,
71    pub capture_name: String,
72    pub node_kind: String,
73    pub containing_symbol_name: Option<String>,
74    pub start_line: usize,
75    pub end_line: usize,
76    pub confidence: f64,
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
80pub struct LiteralFact {
81    pub literal_id: String,
82    pub path: String,
83    pub literal_text: String,
84    pub kind: String,
85    pub carrier: Option<String>,
86    pub start_line: usize,
87    pub containing_symbol_name: Option<String>,
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
91pub struct TypeFact {
92    pub type_fact_id: String,
93    pub symbol_id: String,
94    pub language: String,
95    pub resolved_type: String,
96    pub generic_params: Option<String>,
97}
98
99#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
100pub struct ContextSlice {
101    pub target_symbol: Symbol,
102    pub target_body: String,
103    pub callee_signatures: Vec<String>,
104    pub related_types: Vec<String>,
105    pub related_tests: Vec<Symbol>,
106}
107
108#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
109pub struct SymbolSearchResult {
110    pub symbol: Symbol,
111    pub score: f64,
112    pub snippet: Option<String>,
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
116pub struct BlastRadiusResult {
117    pub seed_type: String,
118    pub seeds: Vec<String>,
119    pub likely_tests: Vec<TestTarget>,
120    pub impacted_symbols: Vec<ImpactedSymbol>,
121    #[serde(default)]
122    pub traversal_ceiling_reached: bool,
123}
124
125#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
126pub struct TestTarget {
127    pub name: String,
128    pub path: String,
129    pub line: usize,
130    pub reason: String,
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
134pub struct ImpactedSymbol {
135    pub name: String,
136    pub kind: String,
137    pub path: String,
138    pub line: usize,
139    pub depth: usize,
140}