emdash-core 0.1.7__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.
- emdash_core/__init__.py +3 -0
- emdash_core/agent/__init__.py +37 -0
- emdash_core/agent/agents.py +225 -0
- emdash_core/agent/code_reviewer.py +476 -0
- emdash_core/agent/compaction.py +143 -0
- emdash_core/agent/context_manager.py +140 -0
- emdash_core/agent/events.py +338 -0
- emdash_core/agent/handlers.py +224 -0
- emdash_core/agent/inprocess_subagent.py +377 -0
- emdash_core/agent/mcp/__init__.py +50 -0
- emdash_core/agent/mcp/client.py +346 -0
- emdash_core/agent/mcp/config.py +302 -0
- emdash_core/agent/mcp/manager.py +496 -0
- emdash_core/agent/mcp/tool_factory.py +213 -0
- emdash_core/agent/prompts/__init__.py +38 -0
- emdash_core/agent/prompts/main_agent.py +104 -0
- emdash_core/agent/prompts/subagents.py +131 -0
- emdash_core/agent/prompts/workflow.py +136 -0
- emdash_core/agent/providers/__init__.py +34 -0
- emdash_core/agent/providers/base.py +143 -0
- emdash_core/agent/providers/factory.py +80 -0
- emdash_core/agent/providers/models.py +220 -0
- emdash_core/agent/providers/openai_provider.py +463 -0
- emdash_core/agent/providers/transformers_provider.py +217 -0
- emdash_core/agent/research/__init__.py +81 -0
- emdash_core/agent/research/agent.py +143 -0
- emdash_core/agent/research/controller.py +254 -0
- emdash_core/agent/research/critic.py +428 -0
- emdash_core/agent/research/macros.py +469 -0
- emdash_core/agent/research/planner.py +449 -0
- emdash_core/agent/research/researcher.py +436 -0
- emdash_core/agent/research/state.py +523 -0
- emdash_core/agent/research/synthesizer.py +594 -0
- emdash_core/agent/reviewer_profile.py +475 -0
- emdash_core/agent/rules.py +123 -0
- emdash_core/agent/runner.py +601 -0
- emdash_core/agent/session.py +262 -0
- emdash_core/agent/spec_schema.py +66 -0
- emdash_core/agent/specification.py +479 -0
- emdash_core/agent/subagent.py +397 -0
- emdash_core/agent/subagent_prompts.py +13 -0
- emdash_core/agent/toolkit.py +482 -0
- emdash_core/agent/toolkits/__init__.py +64 -0
- emdash_core/agent/toolkits/base.py +96 -0
- emdash_core/agent/toolkits/explore.py +47 -0
- emdash_core/agent/toolkits/plan.py +55 -0
- emdash_core/agent/tools/__init__.py +141 -0
- emdash_core/agent/tools/analytics.py +436 -0
- emdash_core/agent/tools/base.py +131 -0
- emdash_core/agent/tools/coding.py +484 -0
- emdash_core/agent/tools/github_mcp.py +592 -0
- emdash_core/agent/tools/history.py +13 -0
- emdash_core/agent/tools/modes.py +153 -0
- emdash_core/agent/tools/plan.py +206 -0
- emdash_core/agent/tools/plan_write.py +135 -0
- emdash_core/agent/tools/search.py +412 -0
- emdash_core/agent/tools/spec.py +341 -0
- emdash_core/agent/tools/task.py +262 -0
- emdash_core/agent/tools/task_output.py +204 -0
- emdash_core/agent/tools/tasks.py +454 -0
- emdash_core/agent/tools/traversal.py +588 -0
- emdash_core/agent/tools/web.py +179 -0
- emdash_core/analytics/__init__.py +5 -0
- emdash_core/analytics/engine.py +1286 -0
- emdash_core/api/__init__.py +5 -0
- emdash_core/api/agent.py +308 -0
- emdash_core/api/agents.py +154 -0
- emdash_core/api/analyze.py +264 -0
- emdash_core/api/auth.py +173 -0
- emdash_core/api/context.py +77 -0
- emdash_core/api/db.py +121 -0
- emdash_core/api/embed.py +131 -0
- emdash_core/api/feature.py +143 -0
- emdash_core/api/health.py +93 -0
- emdash_core/api/index.py +162 -0
- emdash_core/api/plan.py +110 -0
- emdash_core/api/projectmd.py +210 -0
- emdash_core/api/query.py +320 -0
- emdash_core/api/research.py +122 -0
- emdash_core/api/review.py +161 -0
- emdash_core/api/router.py +76 -0
- emdash_core/api/rules.py +116 -0
- emdash_core/api/search.py +119 -0
- emdash_core/api/spec.py +99 -0
- emdash_core/api/swarm.py +223 -0
- emdash_core/api/tasks.py +109 -0
- emdash_core/api/team.py +120 -0
- emdash_core/auth/__init__.py +17 -0
- emdash_core/auth/github.py +389 -0
- emdash_core/config.py +74 -0
- emdash_core/context/__init__.py +52 -0
- emdash_core/context/models.py +50 -0
- emdash_core/context/providers/__init__.py +11 -0
- emdash_core/context/providers/base.py +74 -0
- emdash_core/context/providers/explored_areas.py +183 -0
- emdash_core/context/providers/touched_areas.py +360 -0
- emdash_core/context/registry.py +73 -0
- emdash_core/context/reranker.py +199 -0
- emdash_core/context/service.py +260 -0
- emdash_core/context/session.py +352 -0
- emdash_core/core/__init__.py +104 -0
- emdash_core/core/config.py +454 -0
- emdash_core/core/exceptions.py +55 -0
- emdash_core/core/models.py +265 -0
- emdash_core/core/review_config.py +57 -0
- emdash_core/db/__init__.py +67 -0
- emdash_core/db/auth.py +134 -0
- emdash_core/db/models.py +91 -0
- emdash_core/db/provider.py +222 -0
- emdash_core/db/providers/__init__.py +5 -0
- emdash_core/db/providers/supabase.py +452 -0
- emdash_core/embeddings/__init__.py +24 -0
- emdash_core/embeddings/indexer.py +534 -0
- emdash_core/embeddings/models.py +192 -0
- emdash_core/embeddings/providers/__init__.py +7 -0
- emdash_core/embeddings/providers/base.py +112 -0
- emdash_core/embeddings/providers/fireworks.py +141 -0
- emdash_core/embeddings/providers/openai.py +104 -0
- emdash_core/embeddings/registry.py +146 -0
- emdash_core/embeddings/service.py +215 -0
- emdash_core/graph/__init__.py +26 -0
- emdash_core/graph/builder.py +134 -0
- emdash_core/graph/connection.py +692 -0
- emdash_core/graph/schema.py +416 -0
- emdash_core/graph/writer.py +667 -0
- emdash_core/ingestion/__init__.py +7 -0
- emdash_core/ingestion/change_detector.py +150 -0
- emdash_core/ingestion/git/__init__.py +5 -0
- emdash_core/ingestion/git/commit_analyzer.py +196 -0
- emdash_core/ingestion/github/__init__.py +6 -0
- emdash_core/ingestion/github/pr_fetcher.py +296 -0
- emdash_core/ingestion/github/task_extractor.py +100 -0
- emdash_core/ingestion/orchestrator.py +540 -0
- emdash_core/ingestion/parsers/__init__.py +10 -0
- emdash_core/ingestion/parsers/base_parser.py +66 -0
- emdash_core/ingestion/parsers/call_graph_builder.py +121 -0
- emdash_core/ingestion/parsers/class_extractor.py +154 -0
- emdash_core/ingestion/parsers/function_extractor.py +202 -0
- emdash_core/ingestion/parsers/import_analyzer.py +119 -0
- emdash_core/ingestion/parsers/python_parser.py +123 -0
- emdash_core/ingestion/parsers/registry.py +72 -0
- emdash_core/ingestion/parsers/ts_ast_parser.js +313 -0
- emdash_core/ingestion/parsers/typescript_parser.py +278 -0
- emdash_core/ingestion/repository.py +346 -0
- emdash_core/models/__init__.py +38 -0
- emdash_core/models/agent.py +68 -0
- emdash_core/models/index.py +77 -0
- emdash_core/models/query.py +113 -0
- emdash_core/planning/__init__.py +7 -0
- emdash_core/planning/agent_api.py +413 -0
- emdash_core/planning/context_builder.py +265 -0
- emdash_core/planning/feature_context.py +232 -0
- emdash_core/planning/feature_expander.py +646 -0
- emdash_core/planning/llm_explainer.py +198 -0
- emdash_core/planning/similarity.py +509 -0
- emdash_core/planning/team_focus.py +821 -0
- emdash_core/server.py +153 -0
- emdash_core/sse/__init__.py +5 -0
- emdash_core/sse/stream.py +196 -0
- emdash_core/swarm/__init__.py +17 -0
- emdash_core/swarm/merge_agent.py +383 -0
- emdash_core/swarm/session_manager.py +274 -0
- emdash_core/swarm/swarm_runner.py +226 -0
- emdash_core/swarm/task_definition.py +137 -0
- emdash_core/swarm/worker_spawner.py +319 -0
- emdash_core/swarm/worktree_manager.py +278 -0
- emdash_core/templates/__init__.py +10 -0
- emdash_core/templates/defaults/agent-builder.md.template +82 -0
- emdash_core/templates/defaults/focus.md.template +115 -0
- emdash_core/templates/defaults/pr-review-enhanced.md.template +309 -0
- emdash_core/templates/defaults/pr-review.md.template +80 -0
- emdash_core/templates/defaults/project.md.template +85 -0
- emdash_core/templates/defaults/research_critic.md.template +112 -0
- emdash_core/templates/defaults/research_planner.md.template +85 -0
- emdash_core/templates/defaults/research_synthesizer.md.template +128 -0
- emdash_core/templates/defaults/reviewer.md.template +81 -0
- emdash_core/templates/defaults/spec.md.template +41 -0
- emdash_core/templates/defaults/tasks.md.template +78 -0
- emdash_core/templates/loader.py +296 -0
- emdash_core/utils/__init__.py +45 -0
- emdash_core/utils/git.py +84 -0
- emdash_core/utils/image.py +502 -0
- emdash_core/utils/logger.py +51 -0
- emdash_core-0.1.7.dist-info/METADATA +35 -0
- emdash_core-0.1.7.dist-info/RECORD +187 -0
- emdash_core-0.1.7.dist-info/WHEEL +4 -0
- emdash_core-0.1.7.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
"""Kuzu schema initialization and management."""
|
|
2
|
+
|
|
3
|
+
from .connection import KuzuConnection, get_connection
|
|
4
|
+
from ..utils.logger import log
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class SchemaManager:
|
|
8
|
+
"""Manages Kuzu database schema (tables, indexes)."""
|
|
9
|
+
|
|
10
|
+
# Node table definitions
|
|
11
|
+
NODE_TABLES = {
|
|
12
|
+
"File": """
|
|
13
|
+
CREATE NODE TABLE File (
|
|
14
|
+
path STRING,
|
|
15
|
+
name STRING,
|
|
16
|
+
extension STRING,
|
|
17
|
+
size_bytes INT64,
|
|
18
|
+
lines_of_code INT64,
|
|
19
|
+
hash STRING,
|
|
20
|
+
last_modified TIMESTAMP,
|
|
21
|
+
commit_importance DOUBLE,
|
|
22
|
+
commit_count INT64,
|
|
23
|
+
author_count INT64,
|
|
24
|
+
PRIMARY KEY (path)
|
|
25
|
+
)
|
|
26
|
+
""",
|
|
27
|
+
"Class": """
|
|
28
|
+
CREATE NODE TABLE Class (
|
|
29
|
+
qualified_name STRING,
|
|
30
|
+
name STRING,
|
|
31
|
+
file_path STRING,
|
|
32
|
+
line_start INT64,
|
|
33
|
+
line_end INT64,
|
|
34
|
+
docstring STRING,
|
|
35
|
+
is_abstract BOOL,
|
|
36
|
+
decorators STRING[],
|
|
37
|
+
base_classes STRING[],
|
|
38
|
+
attributes STRING[],
|
|
39
|
+
methods STRING[],
|
|
40
|
+
pagerank DOUBLE,
|
|
41
|
+
betweenness DOUBLE,
|
|
42
|
+
community INT64,
|
|
43
|
+
embedding DOUBLE[],
|
|
44
|
+
PRIMARY KEY (qualified_name)
|
|
45
|
+
)
|
|
46
|
+
""",
|
|
47
|
+
"Function": """
|
|
48
|
+
CREATE NODE TABLE Function (
|
|
49
|
+
qualified_name STRING,
|
|
50
|
+
name STRING,
|
|
51
|
+
file_path STRING,
|
|
52
|
+
line_start INT64,
|
|
53
|
+
line_end INT64,
|
|
54
|
+
docstring STRING,
|
|
55
|
+
parameters STRING[],
|
|
56
|
+
return_annotation STRING,
|
|
57
|
+
is_async BOOL,
|
|
58
|
+
is_method BOOL,
|
|
59
|
+
is_static BOOL,
|
|
60
|
+
is_classmethod BOOL,
|
|
61
|
+
decorators STRING[],
|
|
62
|
+
cyclomatic_complexity INT64,
|
|
63
|
+
calls STRING[],
|
|
64
|
+
pagerank DOUBLE,
|
|
65
|
+
betweenness DOUBLE,
|
|
66
|
+
community INT64,
|
|
67
|
+
embedding DOUBLE[],
|
|
68
|
+
PRIMARY KEY (qualified_name)
|
|
69
|
+
)
|
|
70
|
+
""",
|
|
71
|
+
"Community": """
|
|
72
|
+
CREATE NODE TABLE Community (
|
|
73
|
+
community_id INT64,
|
|
74
|
+
description STRING,
|
|
75
|
+
source STRING,
|
|
76
|
+
embedding DOUBLE[],
|
|
77
|
+
PRIMARY KEY (community_id)
|
|
78
|
+
)
|
|
79
|
+
""",
|
|
80
|
+
"Module": """
|
|
81
|
+
CREATE NODE TABLE Module (
|
|
82
|
+
name STRING,
|
|
83
|
+
import_path STRING,
|
|
84
|
+
is_external BOOL,
|
|
85
|
+
package STRING,
|
|
86
|
+
PRIMARY KEY (name)
|
|
87
|
+
)
|
|
88
|
+
""",
|
|
89
|
+
"Repository": """
|
|
90
|
+
CREATE NODE TABLE Repository (
|
|
91
|
+
url STRING,
|
|
92
|
+
name STRING,
|
|
93
|
+
owner STRING,
|
|
94
|
+
default_branch STRING,
|
|
95
|
+
last_ingested TIMESTAMP,
|
|
96
|
+
last_indexed_commit STRING,
|
|
97
|
+
ingestion_status STRING,
|
|
98
|
+
commit_count INT64,
|
|
99
|
+
file_count INT64,
|
|
100
|
+
primary_language STRING,
|
|
101
|
+
PRIMARY KEY (url)
|
|
102
|
+
)
|
|
103
|
+
""",
|
|
104
|
+
"GitCommit": """
|
|
105
|
+
CREATE NODE TABLE GitCommit (
|
|
106
|
+
sha STRING,
|
|
107
|
+
message STRING,
|
|
108
|
+
timestamp TIMESTAMP,
|
|
109
|
+
author_name STRING,
|
|
110
|
+
author_email STRING,
|
|
111
|
+
committer_name STRING,
|
|
112
|
+
committer_email STRING,
|
|
113
|
+
insertions INT64,
|
|
114
|
+
deletions INT64,
|
|
115
|
+
files_changed INT64,
|
|
116
|
+
is_merge BOOL,
|
|
117
|
+
parent_shas STRING[],
|
|
118
|
+
PRIMARY KEY (sha)
|
|
119
|
+
)
|
|
120
|
+
""",
|
|
121
|
+
"Author": """
|
|
122
|
+
CREATE NODE TABLE Author (
|
|
123
|
+
email STRING,
|
|
124
|
+
name STRING,
|
|
125
|
+
first_commit TIMESTAMP,
|
|
126
|
+
last_commit TIMESTAMP,
|
|
127
|
+
total_commits INT64,
|
|
128
|
+
total_lines_added INT64,
|
|
129
|
+
total_lines_deleted INT64,
|
|
130
|
+
PRIMARY KEY (email)
|
|
131
|
+
)
|
|
132
|
+
""",
|
|
133
|
+
"PullRequest": """
|
|
134
|
+
CREATE NODE TABLE PullRequest (
|
|
135
|
+
number INT64,
|
|
136
|
+
title STRING,
|
|
137
|
+
state STRING,
|
|
138
|
+
created_at TIMESTAMP,
|
|
139
|
+
author STRING,
|
|
140
|
+
description STRING,
|
|
141
|
+
merged_at TIMESTAMP,
|
|
142
|
+
reviewers STRING[],
|
|
143
|
+
labels STRING[],
|
|
144
|
+
additions INT64,
|
|
145
|
+
deletions INT64,
|
|
146
|
+
files_changed INT64,
|
|
147
|
+
commit_shas STRING[],
|
|
148
|
+
base_branch STRING,
|
|
149
|
+
head_branch STRING,
|
|
150
|
+
embedding DOUBLE[],
|
|
151
|
+
PRIMARY KEY (number)
|
|
152
|
+
)
|
|
153
|
+
""",
|
|
154
|
+
"Task": """
|
|
155
|
+
CREATE NODE TABLE Task (
|
|
156
|
+
id STRING,
|
|
157
|
+
pr_number INT64,
|
|
158
|
+
description STRING,
|
|
159
|
+
is_completed BOOL,
|
|
160
|
+
task_order INT64,
|
|
161
|
+
PRIMARY KEY (id)
|
|
162
|
+
)
|
|
163
|
+
""",
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
# Relationship table definitions
|
|
167
|
+
REL_TABLES = {
|
|
168
|
+
"CONTAINS_CLASS": """
|
|
169
|
+
CREATE REL TABLE CONTAINS_CLASS (
|
|
170
|
+
FROM File TO Class,
|
|
171
|
+
line_start INT64
|
|
172
|
+
)
|
|
173
|
+
""",
|
|
174
|
+
"CONTAINS_FUNCTION": """
|
|
175
|
+
CREATE REL TABLE CONTAINS_FUNCTION (
|
|
176
|
+
FROM File TO Function,
|
|
177
|
+
line_start INT64
|
|
178
|
+
)
|
|
179
|
+
""",
|
|
180
|
+
"HAS_METHOD": """
|
|
181
|
+
CREATE REL TABLE HAS_METHOD (
|
|
182
|
+
FROM Class TO Function
|
|
183
|
+
)
|
|
184
|
+
""",
|
|
185
|
+
"INHERITS_FROM": """
|
|
186
|
+
CREATE REL TABLE INHERITS_FROM (
|
|
187
|
+
FROM Class TO Class
|
|
188
|
+
)
|
|
189
|
+
""",
|
|
190
|
+
"CALLS": """
|
|
191
|
+
CREATE REL TABLE CALLS (
|
|
192
|
+
FROM Function TO Function
|
|
193
|
+
)
|
|
194
|
+
""",
|
|
195
|
+
"IMPORTS": """
|
|
196
|
+
CREATE REL TABLE IMPORTS (
|
|
197
|
+
FROM File TO Module,
|
|
198
|
+
import_type STRING,
|
|
199
|
+
line_number INT64,
|
|
200
|
+
alias STRING
|
|
201
|
+
)
|
|
202
|
+
""",
|
|
203
|
+
"AUTHORED_BY": """
|
|
204
|
+
CREATE REL TABLE AUTHORED_BY (
|
|
205
|
+
FROM GitCommit TO Author
|
|
206
|
+
)
|
|
207
|
+
""",
|
|
208
|
+
"COMMIT_MODIFIES": """
|
|
209
|
+
CREATE REL TABLE COMMIT_MODIFIES (
|
|
210
|
+
FROM GitCommit TO File,
|
|
211
|
+
change_type STRING,
|
|
212
|
+
insertions INT64,
|
|
213
|
+
deletions INT64,
|
|
214
|
+
old_path STRING
|
|
215
|
+
)
|
|
216
|
+
""",
|
|
217
|
+
"PR_CONTAINS": """
|
|
218
|
+
CREATE REL TABLE PR_CONTAINS (
|
|
219
|
+
FROM PullRequest TO GitCommit
|
|
220
|
+
)
|
|
221
|
+
""",
|
|
222
|
+
"PR_MODIFIES": """
|
|
223
|
+
CREATE REL TABLE PR_MODIFIES (
|
|
224
|
+
FROM PullRequest TO File
|
|
225
|
+
)
|
|
226
|
+
""",
|
|
227
|
+
"HAS_TASK": """
|
|
228
|
+
CREATE REL TABLE HAS_TASK (
|
|
229
|
+
FROM PullRequest TO Task
|
|
230
|
+
)
|
|
231
|
+
""",
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
def __init__(self, connection: KuzuConnection = None):
|
|
235
|
+
"""Initialize schema manager.
|
|
236
|
+
|
|
237
|
+
Args:
|
|
238
|
+
connection: Kuzu connection. If None, uses global connection.
|
|
239
|
+
"""
|
|
240
|
+
self.connection = connection or get_connection()
|
|
241
|
+
|
|
242
|
+
def initialize_schema(self):
|
|
243
|
+
"""Initialize the complete database schema."""
|
|
244
|
+
log.info("Initializing Kuzu schema...")
|
|
245
|
+
|
|
246
|
+
self.create_node_tables()
|
|
247
|
+
self.create_rel_tables()
|
|
248
|
+
self.create_indexes()
|
|
249
|
+
|
|
250
|
+
log.info("Schema initialization complete")
|
|
251
|
+
|
|
252
|
+
def create_node_tables(self):
|
|
253
|
+
"""Create all node tables."""
|
|
254
|
+
log.info("Creating node tables...")
|
|
255
|
+
|
|
256
|
+
conn = self.connection.connect()
|
|
257
|
+
for table_name, ddl in self.NODE_TABLES.items():
|
|
258
|
+
try:
|
|
259
|
+
conn.execute(ddl)
|
|
260
|
+
log.debug(f"Created node table: {table_name}")
|
|
261
|
+
except Exception as e:
|
|
262
|
+
# Table might already exist
|
|
263
|
+
if "already exists" not in str(e).lower():
|
|
264
|
+
log.warning(f"Failed to create node table {table_name}: {e}")
|
|
265
|
+
|
|
266
|
+
log.info("Node tables created successfully")
|
|
267
|
+
|
|
268
|
+
def create_rel_tables(self):
|
|
269
|
+
"""Create all relationship tables."""
|
|
270
|
+
log.info("Creating relationship tables...")
|
|
271
|
+
|
|
272
|
+
conn = self.connection.connect()
|
|
273
|
+
for table_name, ddl in self.REL_TABLES.items():
|
|
274
|
+
try:
|
|
275
|
+
conn.execute(ddl)
|
|
276
|
+
log.debug(f"Created relationship table: {table_name}")
|
|
277
|
+
except Exception as e:
|
|
278
|
+
# Table might already exist
|
|
279
|
+
if "already exists" not in str(e).lower():
|
|
280
|
+
log.warning(f"Failed to create rel table {table_name}: {e}")
|
|
281
|
+
|
|
282
|
+
log.info("Relationship tables created successfully")
|
|
283
|
+
|
|
284
|
+
def create_indexes(self):
|
|
285
|
+
"""Create performance indexes."""
|
|
286
|
+
log.info("Creating indexes...")
|
|
287
|
+
|
|
288
|
+
# Kuzu index creation - no IF NOT EXISTS support
|
|
289
|
+
# Format: CREATE INDEX idx_name ON TableName(property)
|
|
290
|
+
indexes = [
|
|
291
|
+
# File indexes
|
|
292
|
+
("idx_file_name", "File", "name"),
|
|
293
|
+
("idx_file_extension", "File", "extension"),
|
|
294
|
+
|
|
295
|
+
# Class indexes
|
|
296
|
+
("idx_class_name", "Class", "name"),
|
|
297
|
+
("idx_class_file_path", "Class", "file_path"),
|
|
298
|
+
("idx_class_qualified_name", "Class", "qualified_name"),
|
|
299
|
+
|
|
300
|
+
# Function indexes
|
|
301
|
+
("idx_func_name", "Function", "name"),
|
|
302
|
+
("idx_func_file_path", "Function", "file_path"),
|
|
303
|
+
("idx_func_qualified_name", "Function", "qualified_name"),
|
|
304
|
+
|
|
305
|
+
# Module indexes
|
|
306
|
+
("idx_module_import_path", "Module", "import_path"),
|
|
307
|
+
|
|
308
|
+
# Commit indexes
|
|
309
|
+
("idx_commit_timestamp", "Commit", "timestamp"),
|
|
310
|
+
("idx_commit_author", "Commit", "author_name"),
|
|
311
|
+
|
|
312
|
+
# Author indexes
|
|
313
|
+
("idx_author_name", "Author", "name"),
|
|
314
|
+
|
|
315
|
+
# Pull Request indexes
|
|
316
|
+
("idx_pr_state", "PullRequest", "state"),
|
|
317
|
+
("idx_pr_created", "PullRequest", "created_at"),
|
|
318
|
+
|
|
319
|
+
# Task indexes
|
|
320
|
+
("idx_task_pr", "Task", "pr_number"),
|
|
321
|
+
("idx_task_completed", "Task", "is_completed"),
|
|
322
|
+
]
|
|
323
|
+
|
|
324
|
+
conn = self.connection.connect()
|
|
325
|
+
for idx_name, table, prop in indexes:
|
|
326
|
+
try:
|
|
327
|
+
conn.execute(f"CREATE INDEX {idx_name} ON {table}({prop})")
|
|
328
|
+
log.debug(f"Created index: {idx_name}")
|
|
329
|
+
except Exception as e:
|
|
330
|
+
# Index might already exist
|
|
331
|
+
if "already exists" not in str(e).lower():
|
|
332
|
+
log.debug(f"Index {idx_name} skipped: {e}")
|
|
333
|
+
|
|
334
|
+
log.info("Indexes created successfully")
|
|
335
|
+
|
|
336
|
+
def drop_all_tables(self):
|
|
337
|
+
"""Drop all tables in the database."""
|
|
338
|
+
log.warning("Dropping all tables...")
|
|
339
|
+
|
|
340
|
+
conn = self.connection.connect()
|
|
341
|
+
|
|
342
|
+
# Get all tables
|
|
343
|
+
result = conn.execute("CALL show_tables() RETURN *")
|
|
344
|
+
tables = []
|
|
345
|
+
while result.has_next():
|
|
346
|
+
row = result.get_next()
|
|
347
|
+
tables.append((row[0], row[1] if len(row) > 1 else "NODE"))
|
|
348
|
+
|
|
349
|
+
# Drop relationship tables first (they depend on node tables)
|
|
350
|
+
for table_name, table_type in tables:
|
|
351
|
+
if table_type == "REL":
|
|
352
|
+
try:
|
|
353
|
+
conn.execute(f"DROP TABLE {table_name}")
|
|
354
|
+
log.debug(f"Dropped table: {table_name}")
|
|
355
|
+
except Exception as e:
|
|
356
|
+
log.warning(f"Failed to drop table {table_name}: {e}")
|
|
357
|
+
|
|
358
|
+
# Then drop node tables
|
|
359
|
+
for table_name, table_type in tables:
|
|
360
|
+
if table_type == "NODE":
|
|
361
|
+
try:
|
|
362
|
+
conn.execute(f"DROP TABLE {table_name}")
|
|
363
|
+
log.debug(f"Dropped table: {table_name}")
|
|
364
|
+
except Exception as e:
|
|
365
|
+
log.warning(f"Failed to drop table {table_name}: {e}")
|
|
366
|
+
|
|
367
|
+
log.info("All tables dropped")
|
|
368
|
+
|
|
369
|
+
def reset_schema(self):
|
|
370
|
+
"""Reset the entire schema (drop and recreate)."""
|
|
371
|
+
log.warning("Resetting schema...")
|
|
372
|
+
self.drop_all_tables()
|
|
373
|
+
self.initialize_schema()
|
|
374
|
+
log.info("Schema reset complete")
|
|
375
|
+
|
|
376
|
+
def get_schema_info(self) -> dict:
|
|
377
|
+
"""Get information about the current schema.
|
|
378
|
+
|
|
379
|
+
Returns:
|
|
380
|
+
Dictionary with table information
|
|
381
|
+
"""
|
|
382
|
+
conn = self.connection.connect()
|
|
383
|
+
|
|
384
|
+
# Get all tables
|
|
385
|
+
result = conn.execute("CALL show_tables() RETURN *")
|
|
386
|
+
node_tables = []
|
|
387
|
+
rel_tables = []
|
|
388
|
+
|
|
389
|
+
while result.has_next():
|
|
390
|
+
row = result.get_next()
|
|
391
|
+
table_name = row[0]
|
|
392
|
+
table_type = row[1] if len(row) > 1 else "NODE"
|
|
393
|
+
|
|
394
|
+
if table_type == "NODE":
|
|
395
|
+
node_tables.append(table_name)
|
|
396
|
+
elif table_type == "REL":
|
|
397
|
+
rel_tables.append(table_name)
|
|
398
|
+
|
|
399
|
+
return {
|
|
400
|
+
"node_tables": node_tables,
|
|
401
|
+
"rel_tables": rel_tables,
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def initialize_database():
|
|
406
|
+
"""Initialize the Kuzu database with schema.
|
|
407
|
+
|
|
408
|
+
This is a convenience function that can be called from CLI.
|
|
409
|
+
"""
|
|
410
|
+
connection = get_connection()
|
|
411
|
+
connection.connect()
|
|
412
|
+
|
|
413
|
+
schema_manager = SchemaManager(connection)
|
|
414
|
+
schema_manager.initialize_schema()
|
|
415
|
+
|
|
416
|
+
log.info("Database initialized successfully")
|