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
121/// rarity-weighted coverage fractions, the fixed priors as score points, the query words
122/// with their rarity weights, and the timer over the whole candidate set.
123#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
124pub struct SearchExplain {
125    pub bm25: Option<f64>,
126    pub branches: Vec<String>,
127    pub name_tier: String,
128    pub name_coverage: f64,
129    pub signature_coverage: f64,
130    pub doc_coverage: f64,
131    pub kind_prior: f64,
132    pub path_role: f64,
133    pub documentation: f64,
134    pub test_intent: f64,
135    pub word_weights: Vec<(String, f64)>,
136    pub candidates: usize,
137    pub rerank_us: u128,
138}
139
140#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
141pub struct BlastRadiusResult {
142    pub seed_type: String,
143    pub seeds: Vec<String>,
144    pub likely_tests: Vec<TestTarget>,
145    pub impacted_symbols: Vec<ImpactedSymbol>,
146    #[serde(default)]
147    pub traversal_ceiling_reached: bool,
148}
149
150#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
151pub struct TestTarget {
152    pub name: String,
153    pub path: String,
154    pub line: usize,
155    pub reason: String,
156}
157
158#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
159pub struct ImpactedSymbol {
160    pub name: String,
161    pub kind: String,
162    pub path: String,
163    pub line: usize,
164    pub depth: usize,
165}