kodit 0.4.1__py3-none-any.whl → 0.4.3__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.
Potentially problematic release.
This version of kodit might be problematic. Click here for more details.
- kodit/_version.py +2 -2
- kodit/app.py +9 -2
- kodit/application/factories/code_indexing_factory.py +62 -13
- kodit/application/factories/reporting_factory.py +32 -0
- kodit/application/services/auto_indexing_service.py +41 -33
- kodit/application/services/code_indexing_application_service.py +137 -138
- kodit/application/services/indexing_worker_service.py +26 -30
- kodit/application/services/queue_service.py +12 -14
- kodit/application/services/reporting.py +104 -0
- kodit/application/services/sync_scheduler.py +21 -20
- kodit/cli.py +71 -85
- kodit/config.py +26 -3
- kodit/database.py +2 -1
- kodit/domain/entities.py +99 -1
- kodit/domain/protocols.py +34 -1
- kodit/domain/services/bm25_service.py +1 -6
- kodit/domain/services/index_service.py +23 -57
- kodit/domain/services/task_status_query_service.py +19 -0
- kodit/domain/value_objects.py +53 -8
- kodit/infrastructure/api/v1/dependencies.py +40 -12
- kodit/infrastructure/api/v1/routers/indexes.py +45 -0
- kodit/infrastructure/api/v1/schemas/task_status.py +39 -0
- kodit/infrastructure/cloning/git/working_copy.py +43 -7
- kodit/infrastructure/embedding/embedding_factory.py +8 -3
- kodit/infrastructure/embedding/embedding_providers/litellm_embedding_provider.py +48 -55
- kodit/infrastructure/enrichment/local_enrichment_provider.py +41 -30
- kodit/infrastructure/git/git_utils.py +3 -2
- kodit/infrastructure/mappers/index_mapper.py +1 -0
- kodit/infrastructure/mappers/task_status_mapper.py +85 -0
- kodit/infrastructure/reporting/__init__.py +1 -0
- kodit/infrastructure/reporting/db_progress.py +23 -0
- kodit/infrastructure/reporting/log_progress.py +37 -0
- kodit/infrastructure/reporting/tdqm_progress.py +38 -0
- kodit/infrastructure/sqlalchemy/embedding_repository.py +47 -68
- kodit/infrastructure/sqlalchemy/entities.py +89 -2
- kodit/infrastructure/sqlalchemy/index_repository.py +274 -236
- kodit/infrastructure/sqlalchemy/task_repository.py +55 -39
- kodit/infrastructure/sqlalchemy/task_status_repository.py +79 -0
- kodit/infrastructure/sqlalchemy/unit_of_work.py +59 -0
- kodit/mcp.py +15 -3
- kodit/migrations/env.py +0 -1
- kodit/migrations/versions/b9cd1c3fd762_add_task_status.py +77 -0
- {kodit-0.4.1.dist-info → kodit-0.4.3.dist-info}/METADATA +1 -1
- {kodit-0.4.1.dist-info → kodit-0.4.3.dist-info}/RECORD +47 -40
- kodit/domain/interfaces.py +0 -27
- kodit/infrastructure/ui/__init__.py +0 -1
- kodit/infrastructure/ui/progress.py +0 -170
- kodit/infrastructure/ui/spinner.py +0 -74
- kodit/reporting.py +0 -78
- {kodit-0.4.1.dist-info → kodit-0.4.3.dist-info}/WHEEL +0 -0
- {kodit-0.4.1.dist-info → kodit-0.4.3.dist-info}/entry_points.txt +0 -0
- {kodit-0.4.1.dist-info → kodit-0.4.3.dist-info}/licenses/LICENSE +0 -0
kodit/_version.py
CHANGED
|
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
|
28
28
|
commit_id: COMMIT_ID
|
|
29
29
|
__commit_id__: COMMIT_ID
|
|
30
30
|
|
|
31
|
-
__version__ = version = '0.4.
|
|
32
|
-
__version_tuple__ = version_tuple = (0, 4,
|
|
31
|
+
__version__ = version = '0.4.3'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 4, 3)
|
|
33
33
|
|
|
34
34
|
__commit_id__ = commit_id = None
|
kodit/app.py
CHANGED
|
@@ -8,6 +8,7 @@ from fastapi import FastAPI, Response
|
|
|
8
8
|
from fastapi.responses import RedirectResponse
|
|
9
9
|
|
|
10
10
|
from kodit._version import version
|
|
11
|
+
from kodit.application.factories.reporting_factory import create_server_operation
|
|
11
12
|
from kodit.application.services.auto_indexing_service import AutoIndexingService
|
|
12
13
|
from kodit.application.services.indexing_worker_service import IndexingWorkerService
|
|
13
14
|
from kodit.application.services.sync_scheduler import SyncSchedulerService
|
|
@@ -18,6 +19,9 @@ from kodit.infrastructure.api.v1.routers import (
|
|
|
18
19
|
search_router,
|
|
19
20
|
)
|
|
20
21
|
from kodit.infrastructure.api.v1.schemas.context import AppLifespanState
|
|
22
|
+
from kodit.infrastructure.sqlalchemy.task_status_repository import (
|
|
23
|
+
create_task_status_repository,
|
|
24
|
+
)
|
|
21
25
|
from kodit.mcp import mcp
|
|
22
26
|
from kodit.middleware import ASGICancelledErrorMiddleware, logging_middleware
|
|
23
27
|
|
|
@@ -34,20 +38,23 @@ async def app_lifespan(_: FastAPI) -> AsyncIterator[AppLifespanState]:
|
|
|
34
38
|
# App context has already been configured by the CLI.
|
|
35
39
|
app_context = AppContext()
|
|
36
40
|
db = await app_context.get_db()
|
|
41
|
+
operation = create_server_operation(
|
|
42
|
+
create_task_status_repository(db.session_factory)
|
|
43
|
+
)
|
|
37
44
|
|
|
38
45
|
# Start the queue worker service
|
|
39
46
|
_indexing_worker_service = IndexingWorkerService(
|
|
40
47
|
app_context=app_context,
|
|
41
48
|
session_factory=db.session_factory,
|
|
42
49
|
)
|
|
43
|
-
await _indexing_worker_service.start()
|
|
50
|
+
await _indexing_worker_service.start(operation)
|
|
44
51
|
|
|
45
52
|
# Start auto-indexing service
|
|
46
53
|
_auto_indexing_service = AutoIndexingService(
|
|
47
54
|
app_context=app_context,
|
|
48
55
|
session_factory=db.session_factory,
|
|
49
56
|
)
|
|
50
|
-
await _auto_indexing_service.start_background_indexing()
|
|
57
|
+
await _auto_indexing_service.start_background_indexing(operation)
|
|
51
58
|
|
|
52
59
|
# Start sync scheduler service
|
|
53
60
|
if app_context.periodic_sync.enabled:
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
"""Factory for creating the unified code indexing application service."""
|
|
2
2
|
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
|
|
3
5
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
4
6
|
|
|
7
|
+
from kodit.application.factories.reporting_factory import (
|
|
8
|
+
create_cli_operation,
|
|
9
|
+
create_noop_operation,
|
|
10
|
+
create_server_operation,
|
|
11
|
+
)
|
|
5
12
|
from kodit.application.services.code_indexing_application_service import (
|
|
6
13
|
CodeIndexingApplicationService,
|
|
7
14
|
)
|
|
15
|
+
from kodit.application.services.reporting import (
|
|
16
|
+
ProgressTracker,
|
|
17
|
+
)
|
|
8
18
|
from kodit.config import AppContext
|
|
9
19
|
from kodit.domain.services.bm25_service import BM25DomainService
|
|
10
20
|
from kodit.domain.services.embedding_service import EmbeddingDomainService
|
|
@@ -35,23 +45,35 @@ from kodit.infrastructure.slicing.language_detection_service import (
|
|
|
35
45
|
FileSystemLanguageDetectionService,
|
|
36
46
|
)
|
|
37
47
|
from kodit.infrastructure.sqlalchemy.embedding_repository import (
|
|
38
|
-
|
|
48
|
+
create_embedding_repository,
|
|
39
49
|
)
|
|
40
50
|
from kodit.infrastructure.sqlalchemy.entities import EmbeddingType
|
|
41
|
-
from kodit.infrastructure.sqlalchemy.index_repository import
|
|
51
|
+
from kodit.infrastructure.sqlalchemy.index_repository import (
|
|
52
|
+
create_index_repository,
|
|
53
|
+
)
|
|
54
|
+
from kodit.infrastructure.sqlalchemy.task_status_repository import (
|
|
55
|
+
create_task_status_repository,
|
|
56
|
+
)
|
|
42
57
|
|
|
43
58
|
|
|
44
59
|
def create_code_indexing_application_service(
|
|
45
60
|
app_context: AppContext,
|
|
46
|
-
|
|
61
|
+
session_factory: Callable[[], AsyncSession],
|
|
62
|
+
operation: ProgressTracker,
|
|
47
63
|
) -> CodeIndexingApplicationService:
|
|
48
64
|
"""Create a unified code indexing application service with all dependencies."""
|
|
49
65
|
# Create domain services
|
|
50
|
-
bm25_service = BM25DomainService(
|
|
51
|
-
|
|
52
|
-
|
|
66
|
+
bm25_service = BM25DomainService(
|
|
67
|
+
bm25_repository_factory(app_context, session_factory())
|
|
68
|
+
)
|
|
69
|
+
code_search_service = embedding_domain_service_factory(
|
|
70
|
+
"code", app_context, session_factory(), session_factory
|
|
71
|
+
)
|
|
72
|
+
text_search_service = embedding_domain_service_factory(
|
|
73
|
+
"text", app_context, session_factory(), session_factory
|
|
74
|
+
)
|
|
53
75
|
enrichment_service = enrichment_domain_service_factory(app_context)
|
|
54
|
-
index_repository =
|
|
76
|
+
index_repository = create_index_repository(session_factory=session_factory)
|
|
55
77
|
# Use the unified language mapping from the domain layer
|
|
56
78
|
language_map = LanguageMapping.get_extension_to_language_map()
|
|
57
79
|
|
|
@@ -77,18 +99,45 @@ def create_code_indexing_application_service(
|
|
|
77
99
|
code_search_service=code_search_service,
|
|
78
100
|
text_search_service=text_search_service,
|
|
79
101
|
enrichment_service=enrichment_service,
|
|
80
|
-
|
|
102
|
+
operation=operation,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def create_cli_code_indexing_application_service(
|
|
107
|
+
app_context: AppContext,
|
|
108
|
+
session_factory: Callable[[], AsyncSession],
|
|
109
|
+
) -> CodeIndexingApplicationService:
|
|
110
|
+
"""Create a CLI code indexing application service."""
|
|
111
|
+
return create_code_indexing_application_service(
|
|
112
|
+
app_context,
|
|
113
|
+
session_factory,
|
|
114
|
+
create_cli_operation(),
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def create_server_code_indexing_application_service(
|
|
119
|
+
app_context: AppContext,
|
|
120
|
+
session_factory: Callable[[], AsyncSession],
|
|
121
|
+
) -> CodeIndexingApplicationService:
|
|
122
|
+
"""Create a server code indexing application service."""
|
|
123
|
+
return create_code_indexing_application_service(
|
|
124
|
+
app_context,
|
|
125
|
+
session_factory,
|
|
126
|
+
create_server_operation(create_task_status_repository(session_factory)),
|
|
81
127
|
)
|
|
82
128
|
|
|
83
129
|
|
|
84
130
|
def create_fast_test_code_indexing_application_service(
|
|
85
131
|
app_context: AppContext,
|
|
86
|
-
|
|
132
|
+
session_factory: Callable[[], AsyncSession],
|
|
87
133
|
) -> CodeIndexingApplicationService:
|
|
88
134
|
"""Create a fast test code indexing application service."""
|
|
89
135
|
# Create domain services
|
|
90
|
-
bm25_service = BM25DomainService(
|
|
91
|
-
|
|
136
|
+
bm25_service = BM25DomainService(
|
|
137
|
+
bm25_repository_factory(app_context, session_factory())
|
|
138
|
+
)
|
|
139
|
+
embedding_repository = create_embedding_repository(session_factory=session_factory)
|
|
140
|
+
operation = create_noop_operation()
|
|
92
141
|
|
|
93
142
|
code_search_repository = LocalVectorSearchRepository(
|
|
94
143
|
embedding_repository=embedding_repository,
|
|
@@ -116,7 +165,7 @@ def create_fast_test_code_indexing_application_service(
|
|
|
116
165
|
enrichment_provider=NullEnrichmentProvider()
|
|
117
166
|
)
|
|
118
167
|
|
|
119
|
-
index_repository =
|
|
168
|
+
index_repository = create_index_repository(session_factory=session_factory)
|
|
120
169
|
# Use the unified language mapping from the domain layer
|
|
121
170
|
language_map = LanguageMapping.get_extension_to_language_map()
|
|
122
171
|
|
|
@@ -142,5 +191,5 @@ def create_fast_test_code_indexing_application_service(
|
|
|
142
191
|
code_search_service=code_search_service,
|
|
143
192
|
text_search_service=text_search_service,
|
|
144
193
|
enrichment_service=enrichment_service,
|
|
145
|
-
|
|
194
|
+
operation=operation,
|
|
146
195
|
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Reporting factory."""
|
|
2
|
+
|
|
3
|
+
from kodit.application.services.reporting import ProgressTracker, TaskOperation
|
|
4
|
+
from kodit.config import ReportingConfig
|
|
5
|
+
from kodit.domain.protocols import TaskStatusRepository
|
|
6
|
+
from kodit.infrastructure.reporting.db_progress import DBProgressReportingModule
|
|
7
|
+
from kodit.infrastructure.reporting.log_progress import LoggingReportingModule
|
|
8
|
+
from kodit.infrastructure.reporting.tdqm_progress import TQDMReportingModule
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def create_noop_operation() -> ProgressTracker:
|
|
12
|
+
"""Create a noop reporter."""
|
|
13
|
+
return ProgressTracker.create(TaskOperation.ROOT)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def create_cli_operation(config: ReportingConfig | None = None) -> ProgressTracker:
|
|
17
|
+
"""Create a CLI reporter."""
|
|
18
|
+
shared_config = config or ReportingConfig()
|
|
19
|
+
s = ProgressTracker.create(TaskOperation.ROOT)
|
|
20
|
+
s.subscribe(TQDMReportingModule(shared_config))
|
|
21
|
+
return s
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def create_server_operation(
|
|
25
|
+
task_status_repository: TaskStatusRepository, config: ReportingConfig | None = None
|
|
26
|
+
) -> ProgressTracker:
|
|
27
|
+
"""Create a server reporter."""
|
|
28
|
+
shared_config = config or ReportingConfig()
|
|
29
|
+
s = ProgressTracker.create(TaskOperation.ROOT)
|
|
30
|
+
s.subscribe(LoggingReportingModule(shared_config))
|
|
31
|
+
s.subscribe(DBProgressReportingModule(task_status_repository, shared_config))
|
|
32
|
+
return s
|
|
@@ -11,7 +11,9 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
11
11
|
from kodit.application.factories.code_indexing_factory import (
|
|
12
12
|
create_code_indexing_application_service,
|
|
13
13
|
)
|
|
14
|
+
from kodit.application.factories.reporting_factory import create_noop_operation
|
|
14
15
|
from kodit.application.services.queue_service import QueueService
|
|
16
|
+
from kodit.application.services.reporting import ProgressTracker
|
|
15
17
|
from kodit.config import AppContext
|
|
16
18
|
from kodit.domain.entities import Task
|
|
17
19
|
from kodit.domain.value_objects import QueuePriority
|
|
@@ -31,8 +33,11 @@ class AutoIndexingService:
|
|
|
31
33
|
self.log = structlog.get_logger(__name__)
|
|
32
34
|
self._indexing_task: asyncio.Task | None = None
|
|
33
35
|
|
|
34
|
-
async def start_background_indexing(
|
|
36
|
+
async def start_background_indexing(
|
|
37
|
+
self, operation: ProgressTracker | None = None
|
|
38
|
+
) -> None:
|
|
35
39
|
"""Start background indexing of configured sources."""
|
|
40
|
+
operation = operation or create_noop_operation()
|
|
36
41
|
if (
|
|
37
42
|
not self.app_context.auto_indexing
|
|
38
43
|
or len(self.app_context.auto_indexing.sources) == 0
|
|
@@ -48,40 +53,43 @@ class AutoIndexingService:
|
|
|
48
53
|
|
|
49
54
|
auto_sources = [source.uri for source in self.app_context.auto_indexing.sources]
|
|
50
55
|
self.log.info("Starting background indexing", num_sources=len(auto_sources))
|
|
51
|
-
self._indexing_task = asyncio.create_task(
|
|
56
|
+
self._indexing_task = asyncio.create_task(
|
|
57
|
+
self._index_sources(auto_sources, operation)
|
|
58
|
+
)
|
|
52
59
|
|
|
53
|
-
async def _index_sources(
|
|
60
|
+
async def _index_sources(
|
|
61
|
+
self, sources: list[str], operation: ProgressTracker | None = None
|
|
62
|
+
) -> None:
|
|
54
63
|
"""Index all configured sources in the background."""
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
# Continue with other sources even if one fails
|
|
64
|
+
operation = operation or create_noop_operation()
|
|
65
|
+
queue_service = QueueService(session_factory=self.session_factory)
|
|
66
|
+
service = create_code_indexing_application_service(
|
|
67
|
+
app_context=self.app_context,
|
|
68
|
+
session_factory=self.session_factory,
|
|
69
|
+
operation=operation,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
for source in sources:
|
|
73
|
+
try:
|
|
74
|
+
# Only auto-index a source if it is new
|
|
75
|
+
if await service.does_index_exist(source):
|
|
76
|
+
self.log.info("Index already exists, skipping", source=source)
|
|
77
|
+
continue
|
|
78
|
+
|
|
79
|
+
self.log.info("Adding auto-indexing task to queue", source=source)
|
|
80
|
+
|
|
81
|
+
# Create index
|
|
82
|
+
index = await service.create_index_from_uri(source)
|
|
83
|
+
|
|
84
|
+
await queue_service.enqueue_task(
|
|
85
|
+
Task.create_index_update_task(index.id, QueuePriority.BACKGROUND)
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
except Exception as exc:
|
|
89
|
+
self.log.exception(
|
|
90
|
+
"Failed to auto-index source", source=source, error=str(exc)
|
|
91
|
+
)
|
|
92
|
+
# Continue with other sources even if one fails
|
|
85
93
|
|
|
86
94
|
async def stop(self) -> None:
|
|
87
95
|
"""Stop background indexing."""
|