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 key: Option<String>,
74    pub containing_symbol_name: Option<String>,
75    pub start_line: usize,
76    pub end_line: usize,
77    pub confidence: f64,
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
81pub struct LiteralFact {
82    pub literal_id: String,
83    pub path: String,
84    pub literal_text: String,
85    pub kind: String,
86    pub carrier: Option<String>,
87    pub start_line: usize,
88    pub containing_symbol_name: Option<String>,
89}
90
91#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
92pub struct TypeFact {
93    pub type_fact_id: String,
94    pub symbol_id: String,
95    pub language: String,
96    pub resolved_type: String,
97    pub generic_params: Option<String>,
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
101pub struct ContextSlice {
102    pub target_symbol: Symbol,
103    pub target_body: String,
104    pub callee_signatures: Vec<String>,
105    pub related_types: Vec<String>,
106    pub related_tests: Vec<Symbol>,
107}
108
109/// One `search` hit. `score` is the rerank score; `explain` is present only when the
110/// caller asked for the breakdown.
111#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
112pub struct SymbolSearchResult {
113    pub symbol: Symbol,
114    pub score: f64,
115    pub snippet: Option<String>,
116    #[serde(default, skip_serializing_if = "Option::is_none")]
117    pub explain: Option<SearchExplain>,
118}
119
120/// Rerank breakdown for one `search` hit: which recall branches admitted the row, the name
121/// tier with its match strength, every score part, the query terms with the field that
122/// credited each and each term's rarity weight, and the timer over the whole candidate set.
123/// `score` is `term_score + name_bonus + kind_prior + path_role + documentation + test_intent`.
124#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
125pub struct SearchExplain {
126    pub bm25: Option<f64>,
127    pub branches: Vec<String>,
128    pub name_tier: String,
129    pub name_strength: u32,
130    pub terms: Vec<(String, String, f64)>,
131    pub term_score: f64,
132    pub name_bonus: f64,
133    pub kind_prior: f64,
134    pub path_role: f64,
135    pub documentation: f64,
136    pub test_intent: f64,
137    pub word_weights: Vec<(String, f64)>,
138    pub candidates: usize,
139    pub rerank_us: u128,
140}
141
142#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
143pub struct BlastRadiusResult {
144    pub seed_type: String,
145    pub seeds: Vec<String>,
146    pub likely_tests: Vec<TestTarget>,
147    pub impacted_symbols: Vec<ImpactedSymbol>,
148    #[serde(default)]
149    pub traversal_ceiling_reached: bool,
150}
151
152#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
153pub struct TestTarget {
154    pub name: String,
155    pub path: String,
156    pub line: usize,
157    pub reason: String,
158}
159
160#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
161pub struct ImpactedSymbol {
162    pub name: String,
163    pub kind: String,
164    pub path: String,
165    pub line: usize,
166    pub depth: usize,
167}