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