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.

Files changed (52) hide show
  1. kodit/_version.py +2 -2
  2. kodit/app.py +9 -2
  3. kodit/application/factories/code_indexing_factory.py +62 -13
  4. kodit/application/factories/reporting_factory.py +32 -0
  5. kodit/application/services/auto_indexing_service.py +41 -33
  6. kodit/application/services/code_indexing_application_service.py +137 -138
  7. kodit/application/services/indexing_worker_service.py +26 -30
  8. kodit/application/services/queue_service.py +12 -14
  9. kodit/application/services/reporting.py +104 -0
  10. kodit/application/services/sync_scheduler.py +21 -20
  11. kodit/cli.py +71 -85
  12. kodit/config.py +26 -3
  13. kodit/database.py +2 -1
  14. kodit/domain/entities.py +99 -1
  15. kodit/domain/protocols.py +34 -1
  16. kodit/domain/services/bm25_service.py +1 -6
  17. kodit/domain/services/index_service.py +23 -57
  18. kodit/domain/services/task_status_query_service.py +19 -0
  19. kodit/domain/value_objects.py +53 -8
  20. kodit/infrastructure/api/v1/dependencies.py +40 -12
  21. kodit/infrastructure/api/v1/routers/indexes.py +45 -0
  22. kodit/infrastructure/api/v1/schemas/task_status.py +39 -0
  23. kodit/infrastructure/cloning/git/working_copy.py +43 -7
  24. kodit/infrastructure/embedding/embedding_factory.py +8 -3
  25. kodit/infrastructure/embedding/embedding_providers/litellm_embedding_provider.py +48 -55
  26. kodit/infrastructure/enrichment/local_enrichment_provider.py +41 -30
  27. kodit/infrastructure/git/git_utils.py +3 -2
  28. kodit/infrastructure/mappers/index_mapper.py +1 -0
  29. kodit/infrastructure/mappers/task_status_mapper.py +85 -0
  30. kodit/infrastructure/reporting/__init__.py +1 -0
  31. kodit/infrastructure/reporting/db_progress.py +23 -0
  32. kodit/infrastructure/reporting/log_progress.py +37 -0
  33. kodit/infrastructure/reporting/tdqm_progress.py +38 -0
  34. kodit/infrastructure/sqlalchemy/embedding_repository.py +47 -68
  35. kodit/infrastructure/sqlalchemy/entities.py +89 -2
  36. kodit/infrastructure/sqlalchemy/index_repository.py +274 -236
  37. kodit/infrastructure/sqlalchemy/task_repository.py +55 -39
  38. kodit/infrastructure/sqlalchemy/task_status_repository.py +79 -0
  39. kodit/infrastructure/sqlalchemy/unit_of_work.py +59 -0
  40. kodit/mcp.py +15 -3
  41. kodit/migrations/env.py +0 -1
  42. kodit/migrations/versions/b9cd1c3fd762_add_task_status.py +77 -0
  43. {kodit-0.4.1.dist-info → kodit-0.4.3.dist-info}/METADATA +1 -1
  44. {kodit-0.4.1.dist-info → kodit-0.4.3.dist-info}/RECORD +47 -40
  45. kodit/domain/interfaces.py +0 -27
  46. kodit/infrastructure/ui/__init__.py +0 -1
  47. kodit/infrastructure/ui/progress.py +0 -170
  48. kodit/infrastructure/ui/spinner.py +0 -74
  49. kodit/reporting.py +0 -78
  50. {kodit-0.4.1.dist-info → kodit-0.4.3.dist-info}/WHEEL +0 -0
  51. {kodit-0.4.1.dist-info → kodit-0.4.3.dist-info}/entry_points.txt +0 -0
  52. {kodit-0.4.1.dist-info → kodit-0.4.3.dist-info}/licenses/LICENSE +0 -0
@@ -2,6 +2,7 @@
2
2
 
3
3
  from datetime import UTC, datetime
4
4
  from enum import Enum
5
+ from typing import Any
5
6
 
6
7
  from git import Actor
7
8
  from sqlalchemy import (
@@ -9,6 +10,7 @@ from sqlalchemy import (
9
10
  ForeignKey,
10
11
  Integer,
11
12
  String,
13
+ TypeDecorator,
12
14
  UnicodeText,
13
15
  UniqueConstraint,
14
16
  )
@@ -18,6 +20,29 @@ from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
18
20
  from sqlalchemy.types import JSON
19
21
 
20
22
 
23
+ # See <https://docs.sqlalchemy.org/en/20/core/custom_types.html#store-timezone-aware-timestamps-as-timezone-naive-utc>
24
+ # And [this issue](https://github.com/sqlalchemy/sqlalchemy/issues/1985)
25
+ class TZDateTime(TypeDecorator):
26
+ """Timezone-aware datetime type."""
27
+
28
+ impl = DateTime
29
+ cache_ok = True
30
+
31
+ def process_bind_param(self, value: Any, dialect: Any) -> Any: # noqa: ARG002
32
+ """Process bind param."""
33
+ if value is not None:
34
+ if not value.tzinfo or value.tzinfo.utcoffset(value) is None:
35
+ raise TypeError("tzinfo is required")
36
+ value = value.astimezone(UTC).replace(tzinfo=None)
37
+ return value
38
+
39
+ def process_result_value(self, value: Any, dialect: Any) -> Any: # noqa: ARG002
40
+ """Process result value."""
41
+ if value is not None:
42
+ value = value.replace(tzinfo=UTC)
43
+ return value
44
+
45
+
21
46
  class Base(AsyncAttrs, DeclarativeBase):
22
47
  """Base class for all models."""
23
48
 
@@ -27,10 +52,11 @@ class CommonMixin:
27
52
 
28
53
  id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
29
54
  created_at: Mapped[datetime] = mapped_column(
30
- DateTime(timezone=True), default=lambda: datetime.now(UTC)
55
+ TZDateTime, nullable=False, default=lambda: datetime.now(UTC)
31
56
  )
32
57
  updated_at: Mapped[datetime] = mapped_column(
33
- DateTime(timezone=True),
58
+ TZDateTime,
59
+ nullable=False,
34
60
  default=lambda: datetime.now(UTC),
35
61
  onupdate=lambda: datetime.now(UTC),
36
62
  )
@@ -236,3 +262,64 @@ class Task(Base, CommonMixin):
236
262
  self.type = type
237
263
  self.payload = payload
238
264
  self.priority = priority
265
+
266
+
267
+ class TaskStatus(Base):
268
+ """Task status model."""
269
+
270
+ __tablename__ = "task_status"
271
+ id: Mapped[str] = mapped_column(
272
+ String(255), primary_key=True, index=True, nullable=False
273
+ )
274
+ created_at: Mapped[datetime] = mapped_column(
275
+ TZDateTime, nullable=False, default=lambda: datetime.now(UTC)
276
+ )
277
+ updated_at: Mapped[datetime] = mapped_column(
278
+ TZDateTime,
279
+ nullable=False,
280
+ default=lambda: datetime.now(UTC),
281
+ onupdate=lambda: datetime.now(UTC),
282
+ )
283
+ operation: Mapped[str] = mapped_column(String(255), index=True, nullable=False)
284
+ trackable_id: Mapped[int | None] = mapped_column(Integer, index=True, nullable=True)
285
+ trackable_type: Mapped[str | None] = mapped_column(
286
+ String(255), index=True, nullable=True
287
+ )
288
+ parent: Mapped[str | None] = mapped_column(
289
+ ForeignKey("task_status.id"), index=True, nullable=True
290
+ )
291
+ message: Mapped[str] = mapped_column(UnicodeText, default="")
292
+ state: Mapped[str] = mapped_column(String(255), default="")
293
+ error: Mapped[str] = mapped_column(UnicodeText, default="")
294
+ total: Mapped[int] = mapped_column(Integer, default=0)
295
+ current: Mapped[int] = mapped_column(Integer, default=0)
296
+
297
+ def __init__( # noqa: PLR0913
298
+ self,
299
+ id: str, # noqa: A002
300
+ operation: str,
301
+ created_at: datetime,
302
+ updated_at: datetime,
303
+ trackable_id: int | None,
304
+ trackable_type: str | None,
305
+ parent: str | None,
306
+ state: str,
307
+ error: str | None,
308
+ total: int,
309
+ current: int,
310
+ message: str,
311
+ ) -> None:
312
+ """Initialize the task status."""
313
+ super().__init__()
314
+ self.id = id
315
+ self.operation = operation
316
+ self.created_at = created_at
317
+ self.updated_at = updated_at
318
+ self.trackable_id = trackable_id
319
+ self.trackable_type = trackable_type
320
+ self.parent = parent
321
+ self.state = state
322
+ self.error = error or ""
323
+ self.total = total
324
+ self.current = current
325
+ self.message = message or ""