raggiecode 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- Agent/__init__.py +0 -0
- Agent/agent.py +891 -0
- Agent/chat_history_db.py +1500 -0
- Agent/command.py +49 -0
- Agent/config.py +46 -0
- Agent/effort_levels.py +33 -0
- Agent/git_manager.py +727 -0
- Agent/tools.py +35 -0
- Commands/__init__.py +18 -0
- Commands/effort.py +42 -0
- Commands/global_todo.py +23 -0
- Commands/help.py +22 -0
- Commands/reasoning.py +24 -0
- Commands/redo.py +11 -0
- Commands/reindex.py +27 -0
- Commands/shell.py +28 -0
- Commands/stream.py +24 -0
- Commands/undo.py +13 -0
- Commands/unlimited_effort.py +8 -0
- Commands/window_size.py +29 -0
- RAG/__init__.py +0 -0
- RAG/document.py +119 -0
- RAG/find.py +408 -0
- RAG/graph.py +231 -0
- Tools/GetFileCodeStructure.py +43 -0
- Tools/GetSymbolSourceCode.py +27 -0
- Tools/__init__.py +39 -0
- Tools/ask_user.py +102 -0
- Tools/dispatch_subagent.py +215 -0
- Tools/document.py +35 -0
- Tools/edit_symbol.py +250 -0
- Tools/fuzzy_search.py +119 -0
- Tools/list_dir.py +51 -0
- Tools/read.py +49 -0
- Tools/read_image.py +75 -0
- Tools/remove.py +75 -0
- Tools/replace.py +305 -0
- Tools/search.py +41 -0
- Tools/shell.py +149 -0
- Tools/shell_kill.py +87 -0
- Tools/temp_background_service.py +113 -0
- Tools/todo_list.py +481 -0
- Tools/utils.py +116 -0
- Tools/view_changes.py +179 -0
- Tools/walk_call_tree.py +30 -0
- Tools/web_fetch.py +175 -0
- Tools/web_search.py +69 -0
- Tools/write.py +48 -0
- cli.py +111 -0
- config/__init__.py +0 -0
- config/coder_system_prompt.md +119 -0
- config/roles.json +43 -0
- config/tools.json +709 -0
- indexing/__init__.py +0 -0
- indexing/cli.py +128 -0
- indexing/code_index_sdk.py +832 -0
- indexing/code_indexer.py +1763 -0
- indexing/db_schema.py +396 -0
- indexing/export_to_json.py +346 -0
- indexing/extractors.py +189 -0
- indexing/file_utils.py +97 -0
- indexing/frontend/__init__.py +0 -0
- indexing/frontend/css_extractor.py +195 -0
- indexing/frontend/css_parser.py +387 -0
- indexing/frontend/css_selector_utils.py +226 -0
- indexing/frontend/edit_safety.py +573 -0
- indexing/frontend/graph.py +838 -0
- indexing/frontend/html_extractor.py +496 -0
- indexing/frontend/html_parser.py +314 -0
- indexing/frontend/jsx_extractor.py +1204 -0
- indexing/frontend/location_lookup.py +247 -0
- indexing/frontend/resolver.py +485 -0
- indexing/frontend/runtime_resolver.py +862 -0
- indexing/frontend/semantic_output.py +705 -0
- indexing/frontend/source_location.py +69 -0
- indexing/frontend_config.py +72 -0
- indexing/frontend_models.py +347 -0
- indexing/language_config.py +360 -0
- indexing/models.py +284 -0
- indexing/node_utils.py +1112 -0
- indexing/parse_worker.py +1082 -0
- indexing/queries.py +1542 -0
- indexing/sdk_examples.py +426 -0
- interactive.py +248 -0
- raggie.py +673 -0
- raggiecode-0.2.1.dist-info/METADATA +944 -0
- raggiecode-0.2.1.dist-info/RECORD +93 -0
- raggiecode-0.2.1.dist-info/WHEEL +5 -0
- raggiecode-0.2.1.dist-info/entry_points.txt +2 -0
- raggiecode-0.2.1.dist-info/top_level.txt +10 -0
- skills/__init__.py +3 -0
- skills/manager.py +114 -0
- skills/tool.py +121 -0
indexing/db_schema.py
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
"""
|
|
2
|
+
SQLite database schema for code index.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
SCHEMA_SQL = """
|
|
6
|
+
-- Files table
|
|
7
|
+
CREATE TABLE IF NOT EXISTS files (
|
|
8
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
9
|
+
path TEXT NOT NULL UNIQUE,
|
|
10
|
+
absolute_path TEXT NOT NULL,
|
|
11
|
+
language TEXT NOT NULL,
|
|
12
|
+
content_hash TEXT,
|
|
13
|
+
mtime REAL
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
-- Functions table (includes both functions and methods)
|
|
17
|
+
CREATE TABLE IF NOT EXISTS functions (
|
|
18
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
19
|
+
file_id INTEGER NOT NULL,
|
|
20
|
+
parent_id INTEGER, -- For methods, points to class_id
|
|
21
|
+
parent_type TEXT, -- 'class' or NULL
|
|
22
|
+
name TEXT NOT NULL,
|
|
23
|
+
type TEXT NOT NULL, -- 'function' or 'method'
|
|
24
|
+
location TEXT,
|
|
25
|
+
parameters TEXT, -- JSON array
|
|
26
|
+
return_type TEXT,
|
|
27
|
+
docstring TEXT,
|
|
28
|
+
description TEXT, -- AI-generated or user-provided description
|
|
29
|
+
receiver TEXT, -- For Go methods
|
|
30
|
+
branch_count INTEGER DEFAULT 0, -- Number of conditional branches
|
|
31
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
-- Classes table
|
|
35
|
+
CREATE TABLE IF NOT EXISTS classes (
|
|
36
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
37
|
+
file_id INTEGER NOT NULL,
|
|
38
|
+
parent_id INTEGER, -- For nested classes
|
|
39
|
+
name TEXT NOT NULL,
|
|
40
|
+
location TEXT,
|
|
41
|
+
base_classes TEXT, -- JSON array
|
|
42
|
+
docstring TEXT,
|
|
43
|
+
description TEXT, -- AI-generated or user-provided description
|
|
44
|
+
namespace TEXT, -- Containing namespace (C#, etc.)
|
|
45
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
-- Variables table (includes both top-level variables and class attributes)
|
|
49
|
+
CREATE TABLE IF NOT EXISTS variables (
|
|
50
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
51
|
+
file_id INTEGER NOT NULL,
|
|
52
|
+
parent_id INTEGER, -- For class attributes, points to class_id
|
|
53
|
+
parent_type TEXT, -- 'class' or NULL
|
|
54
|
+
name TEXT NOT NULL,
|
|
55
|
+
type TEXT NOT NULL, -- 'variable' or 'attribute'
|
|
56
|
+
location TEXT,
|
|
57
|
+
field_type TEXT, -- For TypeScript public fields
|
|
58
|
+
description TEXT, -- AI-generated or user-provided description
|
|
59
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
-- Type aliases table
|
|
63
|
+
CREATE TABLE IF NOT EXISTS type_aliases (
|
|
64
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
65
|
+
file_id INTEGER NOT NULL,
|
|
66
|
+
name TEXT NOT NULL,
|
|
67
|
+
location TEXT,
|
|
68
|
+
type_definition TEXT,
|
|
69
|
+
description TEXT, -- AI-generated or user-provided description
|
|
70
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
-- Structs table (Go, Rust, C, etc.)
|
|
74
|
+
CREATE TABLE IF NOT EXISTS structs (
|
|
75
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
76
|
+
file_id INTEGER NOT NULL,
|
|
77
|
+
name TEXT NOT NULL,
|
|
78
|
+
location TEXT,
|
|
79
|
+
description TEXT, -- AI-generated or user-provided description
|
|
80
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
-- Interfaces table (Go, Rust, TypeScript, etc.)
|
|
84
|
+
CREATE TABLE IF NOT EXISTS interfaces (
|
|
85
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
86
|
+
file_id INTEGER NOT NULL,
|
|
87
|
+
name TEXT NOT NULL,
|
|
88
|
+
location TEXT,
|
|
89
|
+
description TEXT, -- AI-generated or user-provided description
|
|
90
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
-- Enums table (Rust, etc.)
|
|
94
|
+
CREATE TABLE IF NOT EXISTS enums (
|
|
95
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
96
|
+
file_id INTEGER NOT NULL,
|
|
97
|
+
name TEXT NOT NULL,
|
|
98
|
+
location TEXT,
|
|
99
|
+
description TEXT, -- AI-generated or user-provided description
|
|
100
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
-- Namespaces table (C#, etc.)
|
|
104
|
+
CREATE TABLE IF NOT EXISTS namespaces (
|
|
105
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
106
|
+
file_id INTEGER NOT NULL,
|
|
107
|
+
name TEXT NOT NULL,
|
|
108
|
+
location TEXT,
|
|
109
|
+
description TEXT, -- AI-generated or user-provided description
|
|
110
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
-- Temporary symbols table (unresolved dependencies waiting for definition)
|
|
114
|
+
-- symbol_type values: 'function_call', 'method_call', 'class_reference', 'variable_reference',
|
|
115
|
+
-- plus frontend types: 'component_reference', 'custom_property_reference', 'css_module_class_reference'
|
|
116
|
+
CREATE TABLE IF NOT EXISTS temp_symbols (
|
|
117
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
118
|
+
name TEXT NOT NULL,
|
|
119
|
+
symbol_type TEXT NOT NULL,
|
|
120
|
+
file_id INTEGER,
|
|
121
|
+
UNIQUE(name, symbol_type),
|
|
122
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
-- Dependencies table (tracks imports and all types of references with precise locations)
|
|
126
|
+
CREATE TABLE IF NOT EXISTS dependencies (
|
|
127
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
128
|
+
file_id INTEGER NOT NULL,
|
|
129
|
+
dependency_type TEXT NOT NULL, -- 'import', 'function_call', 'class_reference', 'variable_reference', 'method_call', 'module_reference'
|
|
130
|
+
name TEXT NOT NULL, -- Imported module, called function, referenced class/variable/method name
|
|
131
|
+
source_function_id INTEGER, -- Which function made the reference/call
|
|
132
|
+
target_function_id INTEGER, -- For method_call/function_call: the function being called
|
|
133
|
+
target_class_id INTEGER, -- For method_call: the class containing the method
|
|
134
|
+
temp_symbol_id INTEGER, -- For unresolved dependencies: points to temp_symbols
|
|
135
|
+
location TEXT, -- JSON: {start_line, start_column, end_line, end_column, start_byte, end_byte}
|
|
136
|
+
is_external INTEGER DEFAULT 0, -- 1 for external dependencies, 0 for internal
|
|
137
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE,
|
|
138
|
+
FOREIGN KEY (source_function_id) REFERENCES functions(id) ON DELETE SET NULL,
|
|
139
|
+
FOREIGN KEY (target_function_id) REFERENCES functions(id) ON DELETE SET NULL,
|
|
140
|
+
FOREIGN KEY (target_class_id) REFERENCES classes(id) ON DELETE SET NULL,
|
|
141
|
+
FOREIGN KEY (temp_symbol_id) REFERENCES temp_symbols(id) ON DELETE SET NULL
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
-- Indexes for better query performance
|
|
145
|
+
CREATE INDEX IF NOT EXISTS idx_functions_file_id ON functions(file_id);
|
|
146
|
+
CREATE INDEX IF NOT EXISTS idx_functions_parent_id ON functions(parent_id);
|
|
147
|
+
CREATE INDEX IF NOT EXISTS idx_functions_name ON functions(name);
|
|
148
|
+
CREATE INDEX IF NOT EXISTS idx_classes_file_id ON classes(file_id);
|
|
149
|
+
CREATE INDEX IF NOT EXISTS idx_classes_parent_id ON classes(parent_id);
|
|
150
|
+
CREATE INDEX IF NOT EXISTS idx_classes_name ON classes(name);
|
|
151
|
+
CREATE INDEX IF NOT EXISTS idx_variables_file_id ON variables(file_id);
|
|
152
|
+
CREATE INDEX IF NOT EXISTS idx_variables_parent_id ON variables(parent_id);
|
|
153
|
+
CREATE INDEX IF NOT EXISTS idx_variables_name ON variables(name);
|
|
154
|
+
CREATE INDEX IF NOT EXISTS idx_type_aliases_file_id ON type_aliases(file_id);
|
|
155
|
+
CREATE INDEX IF NOT EXISTS idx_type_aliases_name ON type_aliases(name);
|
|
156
|
+
CREATE INDEX IF NOT EXISTS idx_structs_file_id ON structs(file_id);
|
|
157
|
+
CREATE INDEX IF NOT EXISTS idx_structs_name ON structs(name);
|
|
158
|
+
CREATE INDEX IF NOT EXISTS idx_interfaces_file_id ON interfaces(file_id);
|
|
159
|
+
CREATE INDEX IF NOT EXISTS idx_interfaces_name ON interfaces(name);
|
|
160
|
+
CREATE INDEX IF NOT EXISTS idx_enums_file_id ON enums(file_id);
|
|
161
|
+
CREATE INDEX IF NOT EXISTS idx_enums_name ON enums(name);
|
|
162
|
+
CREATE INDEX IF NOT EXISTS idx_namespaces_file_id ON namespaces(file_id);
|
|
163
|
+
CREATE INDEX IF NOT EXISTS idx_namespaces_name ON namespaces(name);
|
|
164
|
+
CREATE INDEX IF NOT EXISTS idx_dependencies_file_id ON dependencies(file_id);
|
|
165
|
+
CREATE INDEX IF NOT EXISTS idx_dependencies_source_function_id ON dependencies(source_function_id);
|
|
166
|
+
CREATE INDEX IF NOT EXISTS idx_dependencies_target_function_id ON dependencies(target_function_id);
|
|
167
|
+
CREATE INDEX IF NOT EXISTS idx_dependencies_target_class_id ON dependencies(target_class_id);
|
|
168
|
+
CREATE INDEX IF NOT EXISTS idx_dependencies_temp_symbol_id ON dependencies(temp_symbol_id);
|
|
169
|
+
CREATE INDEX IF NOT EXISTS idx_temp_symbols_name_type ON temp_symbols(name, symbol_type);
|
|
170
|
+
CREATE INDEX IF NOT EXISTS idx_files_path ON files(path);
|
|
171
|
+
|
|
172
|
+
-- ═══════════════════════════════════════════════════════════════
|
|
173
|
+
-- Frontend semantic tables (Phase 1 — Requirements §4, §5, §12)
|
|
174
|
+
-- ═══════════════════════════════════════════════════════════════
|
|
175
|
+
|
|
176
|
+
-- Recognized UI components (React function/arrow/class/forwardRef/memo)
|
|
177
|
+
CREATE TABLE IF NOT EXISTS frontend_components (
|
|
178
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
179
|
+
file_id INTEGER NOT NULL,
|
|
180
|
+
name TEXT NOT NULL,
|
|
181
|
+
framework TEXT NOT NULL DEFAULT 'react',
|
|
182
|
+
source_range TEXT,
|
|
183
|
+
is_exported INTEGER DEFAULT 0,
|
|
184
|
+
impl_function_id INTEGER,
|
|
185
|
+
impl_class_id INTEGER,
|
|
186
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE,
|
|
187
|
+
FOREIGN KEY (impl_function_id) REFERENCES functions(id) ON DELETE SET NULL,
|
|
188
|
+
FOREIGN KEY (impl_class_id) REFERENCES classes(id) ON DELETE SET NULL
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
-- Elements in markup tree (HTML elements, JSX elements, fragments, templates, expressions)
|
|
192
|
+
CREATE TABLE IF NOT EXISTS markup_elements (
|
|
193
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
194
|
+
file_id INTEGER NOT NULL,
|
|
195
|
+
component_id INTEGER,
|
|
196
|
+
parent_element_id INTEGER,
|
|
197
|
+
tag_name TEXT NOT NULL,
|
|
198
|
+
element_type TEXT NOT NULL,
|
|
199
|
+
source_range TEXT,
|
|
200
|
+
element_id_attr TEXT,
|
|
201
|
+
static_classes TEXT,
|
|
202
|
+
attributes TEXT,
|
|
203
|
+
is_conditional INTEGER DEFAULT 0,
|
|
204
|
+
is_repeated INTEGER DEFAULT 0,
|
|
205
|
+
conditional_expr TEXT,
|
|
206
|
+
repeated_expr TEXT,
|
|
207
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE,
|
|
208
|
+
FOREIGN KEY (component_id) REFERENCES frontend_components(id) ON DELETE CASCADE,
|
|
209
|
+
FOREIGN KEY (parent_element_id) REFERENCES markup_elements(id) ON DELETE CASCADE
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
-- CSS selector definitions
|
|
213
|
+
CREATE TABLE IF NOT EXISTS style_selectors (
|
|
214
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
215
|
+
file_id INTEGER NOT NULL,
|
|
216
|
+
selector_text TEXT NOT NULL,
|
|
217
|
+
normalized_selector TEXT,
|
|
218
|
+
selector_type TEXT NOT NULL,
|
|
219
|
+
source_range TEXT,
|
|
220
|
+
component_id INTEGER,
|
|
221
|
+
is_scoped INTEGER DEFAULT 0,
|
|
222
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE,
|
|
223
|
+
FOREIGN KEY (component_id) REFERENCES frontend_components(id) ON DELETE SET NULL
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
-- CSS custom property definitions (--name: value)
|
|
227
|
+
CREATE TABLE IF NOT EXISTS style_custom_properties (
|
|
228
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
229
|
+
file_id INTEGER NOT NULL,
|
|
230
|
+
name TEXT NOT NULL,
|
|
231
|
+
value TEXT,
|
|
232
|
+
source_range TEXT,
|
|
233
|
+
scope_selector TEXT,
|
|
234
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
-- CSS custom property usages (var(--name))
|
|
238
|
+
CREATE TABLE IF NOT EXISTS style_custom_property_usages (
|
|
239
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
240
|
+
file_id INTEGER NOT NULL,
|
|
241
|
+
property_name TEXT NOT NULL,
|
|
242
|
+
source_range TEXT,
|
|
243
|
+
selector_id INTEGER,
|
|
244
|
+
resolved_property_id INTEGER,
|
|
245
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE,
|
|
246
|
+
FOREIGN KEY (selector_id) REFERENCES style_selectors(id) ON DELETE SET NULL,
|
|
247
|
+
FOREIGN KEY (resolved_property_id) REFERENCES style_custom_properties(id) ON DELETE SET NULL
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
-- Keyframe definitions (@keyframes name)
|
|
251
|
+
CREATE TABLE IF NOT EXISTS style_keyframes (
|
|
252
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
253
|
+
file_id INTEGER NOT NULL,
|
|
254
|
+
name TEXT NOT NULL,
|
|
255
|
+
source_range TEXT,
|
|
256
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
-- CSS/stylesheet imports (@import, <link rel="stylesheet">, CSS module imports)
|
|
260
|
+
CREATE TABLE IF NOT EXISTS style_imports (
|
|
261
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
262
|
+
file_id INTEGER NOT NULL,
|
|
263
|
+
import_path TEXT NOT NULL,
|
|
264
|
+
is_external INTEGER DEFAULT 0,
|
|
265
|
+
resolved_file_id INTEGER,
|
|
266
|
+
source_range TEXT,
|
|
267
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE,
|
|
268
|
+
FOREIGN KEY (resolved_file_id) REFERENCES files(id) ON DELETE SET NULL
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
-- Event handler bindings (onclick, onClick, etc.)
|
|
272
|
+
CREATE TABLE IF NOT EXISTS frontend_events (
|
|
273
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
274
|
+
file_id INTEGER NOT NULL,
|
|
275
|
+
element_id INTEGER,
|
|
276
|
+
event_name TEXT NOT NULL,
|
|
277
|
+
handler_type TEXT NOT NULL,
|
|
278
|
+
handler_expression TEXT,
|
|
279
|
+
handler_symbol_id INTEGER,
|
|
280
|
+
resolution_status TEXT NOT NULL DEFAULT 'unresolved',
|
|
281
|
+
source_range TEXT,
|
|
282
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE,
|
|
283
|
+
FOREIGN KEY (element_id) REFERENCES markup_elements(id) ON DELETE CASCADE,
|
|
284
|
+
FOREIGN KEY (handler_symbol_id) REFERENCES functions(id) ON DELETE SET NULL
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
-- Property/state bindings (disabled={x}, className={cn(...)}, {title}, etc.)
|
|
288
|
+
CREATE TABLE IF NOT EXISTS frontend_bindings (
|
|
289
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
290
|
+
file_id INTEGER NOT NULL,
|
|
291
|
+
element_id INTEGER,
|
|
292
|
+
binding_type TEXT NOT NULL,
|
|
293
|
+
binding_name TEXT,
|
|
294
|
+
binding_expression TEXT,
|
|
295
|
+
resolution_status TEXT NOT NULL DEFAULT 'unresolved',
|
|
296
|
+
source_range TEXT,
|
|
297
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE,
|
|
298
|
+
FOREIGN KEY (element_id) REFERENCES markup_elements(id) ON DELETE CASCADE
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
-- Component render graph (parent component renders child component or native element)
|
|
302
|
+
CREATE TABLE IF NOT EXISTS render_relationships (
|
|
303
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
304
|
+
parent_component_id INTEGER NOT NULL,
|
|
305
|
+
child_component_id INTEGER,
|
|
306
|
+
child_component_name TEXT, -- name of referenced component (for cross-file resolution)
|
|
307
|
+
child_element_id INTEGER,
|
|
308
|
+
render_type TEXT NOT NULL,
|
|
309
|
+
controlling_expr TEXT,
|
|
310
|
+
FOREIGN KEY (parent_component_id) REFERENCES frontend_components(id) ON DELETE CASCADE,
|
|
311
|
+
FOREIGN KEY (child_component_id) REFERENCES frontend_components(id) ON DELETE SET NULL,
|
|
312
|
+
FOREIGN KEY (child_element_id) REFERENCES markup_elements(id) ON DELETE SET NULL
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
-- Extraction diagnostics for frontend files
|
|
316
|
+
CREATE TABLE IF NOT EXISTS frontend_diagnostics (
|
|
317
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
318
|
+
file_id INTEGER NOT NULL,
|
|
319
|
+
diagnostic_type TEXT NOT NULL,
|
|
320
|
+
severity TEXT NOT NULL,
|
|
321
|
+
message TEXT,
|
|
322
|
+
source_range TEXT,
|
|
323
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
-- Pre-computed selector→element matches for blast radius analysis
|
|
327
|
+
CREATE TABLE IF NOT EXISTS style_selector_matches (
|
|
328
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
329
|
+
selector_id INTEGER NOT NULL,
|
|
330
|
+
element_id INTEGER NOT NULL,
|
|
331
|
+
match_type TEXT NOT NULL,
|
|
332
|
+
confidence TEXT NOT NULL DEFAULT 'high',
|
|
333
|
+
source_range TEXT,
|
|
334
|
+
FOREIGN KEY (selector_id) REFERENCES style_selectors(id) ON DELETE CASCADE,
|
|
335
|
+
FOREIGN KEY (element_id) REFERENCES markup_elements(id) ON DELETE CASCADE
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
-- Indexes for frontend tables
|
|
339
|
+
CREATE INDEX IF NOT EXISTS idx_frontend_components_file_id ON frontend_components(file_id);
|
|
340
|
+
CREATE INDEX IF NOT EXISTS idx_frontend_components_name ON frontend_components(name);
|
|
341
|
+
CREATE INDEX IF NOT EXISTS idx_frontend_components_impl_function_id ON frontend_components(impl_function_id);
|
|
342
|
+
CREATE INDEX IF NOT EXISTS idx_frontend_components_impl_class_id ON frontend_components(impl_class_id);
|
|
343
|
+
CREATE INDEX IF NOT EXISTS idx_markup_elements_file_id ON markup_elements(file_id);
|
|
344
|
+
CREATE INDEX IF NOT EXISTS idx_markup_elements_component_id ON markup_elements(component_id);
|
|
345
|
+
CREATE INDEX IF NOT EXISTS idx_markup_elements_parent_element_id ON markup_elements(parent_element_id);
|
|
346
|
+
CREATE INDEX IF NOT EXISTS idx_markup_elements_tag_name ON markup_elements(tag_name);
|
|
347
|
+
CREATE INDEX IF NOT EXISTS idx_style_selectors_file_id ON style_selectors(file_id);
|
|
348
|
+
CREATE INDEX IF NOT EXISTS idx_style_selectors_selector_type ON style_selectors(selector_type);
|
|
349
|
+
CREATE INDEX IF NOT EXISTS idx_style_selectors_component_id ON style_selectors(component_id);
|
|
350
|
+
CREATE INDEX IF NOT EXISTS idx_style_custom_properties_file_id ON style_custom_properties(file_id);
|
|
351
|
+
CREATE INDEX IF NOT EXISTS idx_style_custom_properties_name ON style_custom_properties(name);
|
|
352
|
+
CREATE INDEX IF NOT EXISTS idx_style_custom_property_usages_file_id ON style_custom_property_usages(file_id);
|
|
353
|
+
CREATE INDEX IF NOT EXISTS idx_style_custom_property_usages_selector_id ON style_custom_property_usages(selector_id);
|
|
354
|
+
CREATE INDEX IF NOT EXISTS idx_style_custom_property_usages_resolved_property_id ON style_custom_property_usages(resolved_property_id);
|
|
355
|
+
CREATE INDEX IF NOT EXISTS idx_style_keyframes_file_id ON style_keyframes(file_id);
|
|
356
|
+
CREATE INDEX IF NOT EXISTS idx_style_keyframes_name ON style_keyframes(name);
|
|
357
|
+
CREATE INDEX IF NOT EXISTS idx_style_imports_file_id ON style_imports(file_id);
|
|
358
|
+
CREATE INDEX IF NOT EXISTS idx_style_imports_resolved_file_id ON style_imports(resolved_file_id);
|
|
359
|
+
CREATE INDEX IF NOT EXISTS idx_frontend_events_file_id ON frontend_events(file_id);
|
|
360
|
+
CREATE INDEX IF NOT EXISTS idx_frontend_events_element_id ON frontend_events(element_id);
|
|
361
|
+
CREATE INDEX IF NOT EXISTS idx_frontend_events_handler_symbol_id ON frontend_events(handler_symbol_id);
|
|
362
|
+
CREATE INDEX IF NOT EXISTS idx_frontend_bindings_file_id ON frontend_bindings(file_id);
|
|
363
|
+
CREATE INDEX IF NOT EXISTS idx_frontend_bindings_element_id ON frontend_bindings(element_id);
|
|
364
|
+
CREATE INDEX IF NOT EXISTS idx_render_relationships_parent_component_id ON render_relationships(parent_component_id);
|
|
365
|
+
CREATE INDEX IF NOT EXISTS idx_render_relationships_child_component_id ON render_relationships(child_component_id);
|
|
366
|
+
CREATE INDEX IF NOT EXISTS idx_render_relationships_child_component_name ON render_relationships(child_component_name);
|
|
367
|
+
CREATE INDEX IF NOT EXISTS idx_render_relationships_child_element_id ON render_relationships(child_element_id);
|
|
368
|
+
CREATE INDEX IF NOT EXISTS idx_frontend_diagnostics_file_id ON frontend_diagnostics(file_id);
|
|
369
|
+
CREATE INDEX IF NOT EXISTS idx_frontend_diagnostics_severity ON frontend_diagnostics(severity);
|
|
370
|
+
CREATE INDEX IF NOT EXISTS idx_style_selector_matches_selector_id ON style_selector_matches(selector_id);
|
|
371
|
+
CREATE INDEX IF NOT EXISTS idx_style_selector_matches_element_id ON style_selector_matches(element_id);
|
|
372
|
+
CREATE INDEX IF NOT EXISTS idx_style_custom_property_usages_property_name ON style_custom_property_usages(property_name);
|
|
373
|
+
CREATE INDEX IF NOT EXISTS idx_frontend_events_resolution ON frontend_events(handler_symbol_id, handler_type);
|
|
374
|
+
|
|
375
|
+
-- Temporary file references table (unresolved file-path references waiting for target file to be indexed)
|
|
376
|
+
-- Used for: @import, <script src>, <link href>, CSS module imports
|
|
377
|
+
CREATE TABLE IF NOT EXISTS temp_file_references (
|
|
378
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
379
|
+
resolved_path TEXT NOT NULL, -- normalized relative path (e.g. "src/components/Button.tsx")
|
|
380
|
+
reference_type TEXT NOT NULL, -- 'style_import', 'script_import', 'component_import', 'css_module_import'
|
|
381
|
+
source_file_id INTEGER NOT NULL, -- file making the reference
|
|
382
|
+
target_table TEXT, -- which table row to update when resolved (e.g. 'style_imports')
|
|
383
|
+
target_row_id INTEGER, -- row ID in that table
|
|
384
|
+
FOREIGN KEY (source_file_id) REFERENCES files(id) ON DELETE CASCADE
|
|
385
|
+
);
|
|
386
|
+
CREATE INDEX IF NOT EXISTS idx_temp_file_refs_path ON temp_file_references(resolved_path);
|
|
387
|
+
CREATE INDEX IF NOT EXISTS idx_temp_file_refs_source ON temp_file_references(source_file_id);
|
|
388
|
+
"""
|
|
389
|
+
|
|
390
|
+
def init_database(db_path):
|
|
391
|
+
"""Initialize the database with the schema."""
|
|
392
|
+
import sqlite3
|
|
393
|
+
conn = sqlite3.connect(db_path, timeout=30) # Increase timeout for concurrent access
|
|
394
|
+
conn.executescript(SCHEMA_SQL)
|
|
395
|
+
conn.commit()
|
|
396
|
+
return conn
|