git-contribution-analyzer 0.8.0__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.
- git_contribution_analyzer/__init__.py +3 -0
- git_contribution_analyzer/adapters/__init__.py +1 -0
- git_contribution_analyzer/adapters/git/__init__.py +1 -0
- git_contribution_analyzer/adapters/git/local_identity.py +51 -0
- git_contribution_analyzer/adapters/git/native_git.py +353 -0
- git_contribution_analyzer/adapters/git/pydriller_history.py +57 -0
- git_contribution_analyzer/adapters/git/repository_discovery.py +75 -0
- git_contribution_analyzer/adapters/gui/__init__.py +1 -0
- git_contribution_analyzer/adapters/gui/app.py +63 -0
- git_contribution_analyzer/adapters/gui/controller.py +1084 -0
- git_contribution_analyzer/adapters/gui/models/__init__.py +3 -0
- git_contribution_analyzer/adapters/gui/models/base_table.py +108 -0
- git_contribution_analyzer/adapters/gui/settings.py +53 -0
- git_contribution_analyzer/adapters/gui/task_runner.py +196 -0
- git_contribution_analyzer/adapters/llm/__init__.py +1 -0
- git_contribution_analyzer/adapters/llm/anthropic.py +52 -0
- git_contribution_analyzer/adapters/llm/base.py +142 -0
- git_contribution_analyzer/adapters/llm/cache.py +148 -0
- git_contribution_analyzer/adapters/llm/claude_cli.py +52 -0
- git_contribution_analyzer/adapters/llm/codex_cli.py +52 -0
- git_contribution_analyzer/adapters/llm/command_base.py +153 -0
- git_contribution_analyzer/adapters/llm/mock.py +82 -0
- git_contribution_analyzer/adapters/llm/ollama.py +53 -0
- git_contribution_analyzer/adapters/llm/openai_compatible.py +61 -0
- git_contribution_analyzer/adapters/llm/registry.py +117 -0
- git_contribution_analyzer/adapters/mcp/__init__.py +13 -0
- git_contribution_analyzer/adapters/mcp/installer.py +175 -0
- git_contribution_analyzer/adapters/mcp/prompts_resources.py +218 -0
- git_contribution_analyzer/adapters/mcp/protocol.py +361 -0
- git_contribution_analyzer/adapters/mcp/server.py +52 -0
- git_contribution_analyzer/adapters/mcp/tools.py +621 -0
- git_contribution_analyzer/adapters/outcomes/__init__.py +1 -0
- git_contribution_analyzer/adapters/outcomes/yaml_loader.py +55 -0
- git_contribution_analyzer/adapters/outcomes/yaml_store.py +104 -0
- git_contribution_analyzer/adapters/reporting/__init__.py +1 -0
- git_contribution_analyzer/adapters/reporting/brag_markdown.py +115 -0
- git_contribution_analyzer/adapters/reporting/html_report.py +1413 -0
- git_contribution_analyzer/adapters/reporting/markdown.py +217 -0
- git_contribution_analyzer/adapters/reporting/portfolio_markdown.py +167 -0
- git_contribution_analyzer/adapters/reporting/recap_markdown.py +212 -0
- git_contribution_analyzer/adapters/reporting/resume_markdown.py +37 -0
- git_contribution_analyzer/adapters/reporting/work_assessment_csv.py +117 -0
- git_contribution_analyzer/adapters/reporting/work_assessment_markdown.py +90 -0
- git_contribution_analyzer/adapters/reporting/work_assessment_series_markdown.py +31 -0
- git_contribution_analyzer/adapters/storage/__init__.py +1 -0
- git_contribution_analyzer/adapters/storage/sqlite/__init__.py +1 -0
- git_contribution_analyzer/adapters/storage/sqlite/analysis.py +708 -0
- git_contribution_analyzer/adapters/storage/sqlite/database.py +98 -0
- git_contribution_analyzer/adapters/storage/sqlite/git_index.py +482 -0
- git_contribution_analyzer/adapters/storage/sqlite/identity_merge.py +373 -0
- git_contribution_analyzer/adapters/storage/sqlite/llm_audit.py +109 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/env.py +34 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/script.py.mako +22 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0001_initial.py +51 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0002_git_index.py +146 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0003_analysis.py +79 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0004_llm_audit.py +69 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0005_run_types.py +42 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0006_identity_merges.py +83 -0
- git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0007_structural_baselines.py +173 -0
- git_contribution_analyzer/adapters/storage/sqlite/models.py +354 -0
- git_contribution_analyzer/adapters/storage/sqlite/structural_baseline.py +841 -0
- git_contribution_analyzer/adapters/workspace/__init__.py +1 -0
- git_contribution_analyzer/adapters/workspace/config.py +135 -0
- git_contribution_analyzer/adapters/workspace/git_exclude.py +32 -0
- git_contribution_analyzer/adapters/workspace/layout.py +40 -0
- git_contribution_analyzer/adapters/workspace/locks.py +27 -0
- git_contribution_analyzer/adapters/workspace/portfolio_workspace.py +380 -0
- git_contribution_analyzer/adapters/workspace/ranking_config.py +17 -0
- git_contribution_analyzer/application/__init__.py +1 -0
- git_contribution_analyzer/application/dto/__init__.py +19 -0
- git_contribution_analyzer/application/dto/gui.py +86 -0
- git_contribution_analyzer/application/dto/results.py +21 -0
- git_contribution_analyzer/application/facades/__init__.py +3 -0
- git_contribution_analyzer/application/facades/gui.py +568 -0
- git_contribution_analyzer/application/ports/__init__.py +22 -0
- git_contribution_analyzer/application/ports/cancellation.py +50 -0
- git_contribution_analyzer/application/ports/git_history.py +22 -0
- git_contribution_analyzer/application/ports/llm.py +44 -0
- git_contribution_analyzer/application/ports/portfolio_store.py +34 -0
- git_contribution_analyzer/application/ports/progress.py +43 -0
- git_contribution_analyzer/application/ports/structural_baseline.py +93 -0
- git_contribution_analyzer/application/services/__init__.py +1 -0
- git_contribution_analyzer/application/services/assessment_explanation.py +127 -0
- git_contribution_analyzer/application/services/default_person.py +61 -0
- git_contribution_analyzer/application/services/evidence_snapshot.py +64 -0
- git_contribution_analyzer/application/services/person_selection.py +88 -0
- git_contribution_analyzer/application/services/resume_generation.py +318 -0
- git_contribution_analyzer/application/services/semantic_enhancement.py +157 -0
- git_contribution_analyzer/application/services/time_boundaries.py +49 -0
- git_contribution_analyzer/application/use_cases/__init__.py +1 -0
- git_contribution_analyzer/application/use_cases/analyze_contributions.py +276 -0
- git_contribution_analyzer/application/use_cases/analyze_project.py +295 -0
- git_contribution_analyzer/application/use_cases/assess_portfolio.py +327 -0
- git_contribution_analyzer/application/use_cases/assess_work.py +602 -0
- git_contribution_analyzer/application/use_cases/assess_work_series.py +212 -0
- git_contribution_analyzer/application/use_cases/compare_assessment_runs.py +121 -0
- git_contribution_analyzer/application/use_cases/export_report.py +49 -0
- git_contribution_analyzer/application/use_cases/generate_brag.py +308 -0
- git_contribution_analyzer/application/use_cases/generate_portfolio_recap.py +244 -0
- git_contribution_analyzer/application/use_cases/generate_portfolio_resume.py +152 -0
- git_contribution_analyzer/application/use_cases/generate_recap.py +316 -0
- git_contribution_analyzer/application/use_cases/generate_report.py +32 -0
- git_contribution_analyzer/application/use_cases/generate_resume.py +209 -0
- git_contribution_analyzer/application/use_cases/get_portfolio_status.py +83 -0
- git_contribution_analyzer/application/use_cases/get_run.py +16 -0
- git_contribution_analyzer/application/use_cases/get_status.py +69 -0
- git_contribution_analyzer/application/use_cases/index_repository.py +267 -0
- git_contribution_analyzer/application/use_cases/init_portfolio.py +89 -0
- git_contribution_analyzer/application/use_cases/init_project.py +71 -0
- git_contribution_analyzer/application/use_cases/list_identities.py +16 -0
- git_contribution_analyzer/application/use_cases/list_providers.py +29 -0
- git_contribution_analyzer/application/use_cases/list_runs.py +17 -0
- git_contribution_analyzer/application/use_cases/manage_identity_merges.py +48 -0
- git_contribution_analyzer/application/use_cases/manage_outcomes.py +189 -0
- git_contribution_analyzer/application/use_cases/manage_structural_baselines.py +262 -0
- git_contribution_analyzer/application/use_cases/map_identity.py +28 -0
- git_contribution_analyzer/application/use_cases/recover_runs.py +22 -0
- git_contribution_analyzer/application/use_cases/run_doctor.py +81 -0
- git_contribution_analyzer/application/use_cases/sync_portfolio.py +232 -0
- git_contribution_analyzer/application/use_cases/test_provider.py +22 -0
- git_contribution_analyzer/application/use_cases/uninit_project.py +23 -0
- git_contribution_analyzer/application/use_cases/verify_portfolio.py +165 -0
- git_contribution_analyzer/cli/__init__.py +1 -0
- git_contribution_analyzer/cli/app.py +1430 -0
- git_contribution_analyzer/cli/exit_codes.py +13 -0
- git_contribution_analyzer/cli/output.py +26 -0
- git_contribution_analyzer/cli/portfolio_commands.py +629 -0
- git_contribution_analyzer/domain/__init__.py +1 -0
- git_contribution_analyzer/domain/errors.py +55 -0
- git_contribution_analyzer/domain/models/__init__.py +3 -0
- git_contribution_analyzer/domain/models/analysis.py +29 -0
- git_contribution_analyzer/domain/models/assessment.py +12 -0
- git_contribution_analyzer/domain/models/brag.py +148 -0
- git_contribution_analyzer/domain/models/contribution.py +55 -0
- git_contribution_analyzer/domain/models/git_history.py +69 -0
- git_contribution_analyzer/domain/models/person_selection.py +46 -0
- git_contribution_analyzer/domain/models/portfolio.py +498 -0
- git_contribution_analyzer/domain/models/ranking.py +48 -0
- git_contribution_analyzer/domain/models/recap.py +235 -0
- git_contribution_analyzer/domain/models/repository.py +10 -0
- git_contribution_analyzer/domain/models/resume.py +59 -0
- git_contribution_analyzer/domain/models/run.py +10 -0
- git_contribution_analyzer/domain/models/semantic.py +34 -0
- git_contribution_analyzer/domain/models/snapshot.py +208 -0
- git_contribution_analyzer/domain/models/structural_baseline.py +120 -0
- git_contribution_analyzer/domain/models/work_assessment.py +81 -0
- git_contribution_analyzer/domain/services/assessment_periods.py +182 -0
- git_contribution_analyzer/domain/services/brag_rules.py +250 -0
- git_contribution_analyzer/domain/services/capability_rules.py +91 -0
- git_contribution_analyzer/domain/services/contribution_clustering.py +98 -0
- git_contribution_analyzer/domain/services/contribution_rules.py +79 -0
- git_contribution_analyzer/domain/services/difficulty_rules.py +191 -0
- git_contribution_analyzer/domain/services/dimensional_summary.py +117 -0
- git_contribution_analyzer/domain/services/portfolio_aggregation.py +250 -0
- git_contribution_analyzer/domain/services/portfolio_resume_rules.py +265 -0
- git_contribution_analyzer/domain/services/portfolio_verifier.py +238 -0
- git_contribution_analyzer/domain/services/ranking_rules.py +226 -0
- git_contribution_analyzer/domain/services/recap_rules.py +268 -0
- git_contribution_analyzer/domain/services/resume_claim_rules.py +70 -0
- git_contribution_analyzer/domain/services/structural_baseline.py +317 -0
- git_contribution_analyzer/domain/services/structural_signals.py +151 -0
- git_contribution_analyzer/domain/services/workload_rules.py +185 -0
- git_contribution_analyzer/gui/__init__.py +1 -0
- git_contribution_analyzer/gui/qml/Main.qml +1141 -0
- git_contribution_analyzer/gui/qml/__init__.py +1 -0
- git_contribution_analyzer/prompts/__init__.py +1 -0
- git_contribution_analyzer/prompts/assessment/__init__.py +1 -0
- git_contribution_analyzer/prompts/assessment/v1/__init__.py +1 -0
- git_contribution_analyzer/prompts/assessment/v1/explanation.txt +4 -0
- git_contribution_analyzer/prompts/resume/__init__.py +1 -0
- git_contribution_analyzer/prompts/resume/v1/__init__.py +1 -0
- git_contribution_analyzer/prompts/resume/v1/style-concise.txt +1 -0
- git_contribution_analyzer/prompts/resume/v1/style-star.txt +1 -0
- git_contribution_analyzer/prompts/resume/v1/style-xyz.txt +1 -0
- git_contribution_analyzer/prompts/resume/v1/system.txt +3 -0
- git_contribution_analyzer/prompts/v1/__init__.py +1 -0
- git_contribution_analyzer/prompts/v1/capability_explanation.txt +2 -0
- git_contribution_analyzer/prompts/v1/contribution_summary.txt +2 -0
- git_contribution_analyzer/prompts/v1/overall_summary.txt +2 -0
- git_contribution_analyzer/prompts/v1/resume_bullet.txt +2 -0
- git_contribution_analyzer-0.8.0.dist-info/METADATA +667 -0
- git_contribution_analyzer-0.8.0.dist-info/RECORD +187 -0
- git_contribution_analyzer-0.8.0.dist-info/WHEEL +4 -0
- git_contribution_analyzer-0.8.0.dist-info/entry_points.txt +3 -0
- git_contribution_analyzer-0.8.0.dist-info/licenses/LICENSE +201 -0
- git_contribution_analyzer-0.8.0.dist-info/licenses/NOTICE +6 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from PySide6.QtCore import (
|
|
7
|
+
QAbstractTableModel,
|
|
8
|
+
QByteArray,
|
|
9
|
+
QModelIndex,
|
|
10
|
+
QPersistentModelIndex,
|
|
11
|
+
Qt,
|
|
12
|
+
Slot,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
_INVALID_INDEX = QModelIndex()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True, slots=True)
|
|
19
|
+
class Column:
|
|
20
|
+
key: str
|
|
21
|
+
title: str
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class DictTableModel(QAbstractTableModel):
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
*,
|
|
28
|
+
columns: tuple[Column, ...],
|
|
29
|
+
rows: tuple[dict[str, Any], ...] = (),
|
|
30
|
+
) -> None:
|
|
31
|
+
super().__init__()
|
|
32
|
+
self._columns = columns
|
|
33
|
+
self._source_rows = tuple(dict(row) for row in rows)
|
|
34
|
+
self._rows = self._source_rows
|
|
35
|
+
self._filter = ""
|
|
36
|
+
self._roles = {
|
|
37
|
+
int(Qt.ItemDataRole.UserRole) + index + 1: QByteArray(column.key.encode("utf-8"))
|
|
38
|
+
for index, column in enumerate(columns)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
def rowCount(
|
|
42
|
+
self,
|
|
43
|
+
parent: QModelIndex | QPersistentModelIndex = _INVALID_INDEX,
|
|
44
|
+
) -> int:
|
|
45
|
+
return 0 if parent.isValid() else len(self._rows)
|
|
46
|
+
|
|
47
|
+
def columnCount(
|
|
48
|
+
self,
|
|
49
|
+
parent: QModelIndex | QPersistentModelIndex = _INVALID_INDEX,
|
|
50
|
+
) -> int:
|
|
51
|
+
return 0 if parent.isValid() else len(self._columns)
|
|
52
|
+
|
|
53
|
+
def data(
|
|
54
|
+
self,
|
|
55
|
+
index: QModelIndex | QPersistentModelIndex,
|
|
56
|
+
role: int = int(Qt.ItemDataRole.DisplayRole),
|
|
57
|
+
) -> Any:
|
|
58
|
+
if not index.isValid() or not 0 <= index.row() < len(self._rows):
|
|
59
|
+
return None
|
|
60
|
+
row = self._rows[index.row()]
|
|
61
|
+
if role == int(Qt.ItemDataRole.DisplayRole):
|
|
62
|
+
if not 0 <= index.column() < len(self._columns):
|
|
63
|
+
return None
|
|
64
|
+
value = row.get(self._columns[index.column()].key)
|
|
65
|
+
return "" if value is None else value
|
|
66
|
+
role_name = self._roles.get(role)
|
|
67
|
+
if role_name is not None:
|
|
68
|
+
return row.get(bytes(role_name.data()).decode("utf-8"))
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
def headerData(
|
|
72
|
+
self,
|
|
73
|
+
section: int,
|
|
74
|
+
orientation: Qt.Orientation,
|
|
75
|
+
role: int = int(Qt.ItemDataRole.DisplayRole),
|
|
76
|
+
) -> Any:
|
|
77
|
+
if (
|
|
78
|
+
role == int(Qt.ItemDataRole.DisplayRole)
|
|
79
|
+
and orientation == Qt.Orientation.Horizontal
|
|
80
|
+
and 0 <= section < len(self._columns)
|
|
81
|
+
):
|
|
82
|
+
return self._columns[section].title
|
|
83
|
+
return None
|
|
84
|
+
|
|
85
|
+
def roleNames(self) -> dict[int, QByteArray]:
|
|
86
|
+
return dict(self._roles)
|
|
87
|
+
|
|
88
|
+
def set_rows(self, rows: tuple[dict[str, Any], ...] | list[dict[str, Any]]) -> None:
|
|
89
|
+
self.beginResetModel()
|
|
90
|
+
self._source_rows = tuple(dict(row) for row in rows)
|
|
91
|
+
self._rows = self._filtered_rows()
|
|
92
|
+
self.endResetModel()
|
|
93
|
+
|
|
94
|
+
@Slot(str)
|
|
95
|
+
def set_filter(self, value: str) -> None:
|
|
96
|
+
self.beginResetModel()
|
|
97
|
+
self._filter = value.strip().casefold()
|
|
98
|
+
self._rows = self._filtered_rows()
|
|
99
|
+
self.endResetModel()
|
|
100
|
+
|
|
101
|
+
def _filtered_rows(self) -> tuple[dict[str, Any], ...]:
|
|
102
|
+
if not self._filter:
|
|
103
|
+
return self._source_rows
|
|
104
|
+
return tuple(
|
|
105
|
+
row
|
|
106
|
+
for row in self._source_rows
|
|
107
|
+
if any(self._filter in str(value).casefold() for value in row.values())
|
|
108
|
+
)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from PySide6.QtCore import QSettings
|
|
7
|
+
|
|
8
|
+
_MAX_RECENT_REPOSITORIES = 10
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class GuiSettings:
|
|
12
|
+
def __init__(self, path: Path | None = None) -> None:
|
|
13
|
+
self._settings = (
|
|
14
|
+
QSettings(str(path), QSettings.Format.IniFormat)
|
|
15
|
+
if path is not None
|
|
16
|
+
else QSettings("GCA", "Git Contribution Analyzer")
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
def remember_repository(self, repository: Path) -> None:
|
|
20
|
+
resolved = str(repository.expanduser().resolve())
|
|
21
|
+
recent = [item for item in self.recent_repositories() if item != resolved]
|
|
22
|
+
recent.insert(0, resolved)
|
|
23
|
+
self._settings.setValue(
|
|
24
|
+
"repositories/recent",
|
|
25
|
+
json.dumps(recent[:_MAX_RECENT_REPOSITORIES], ensure_ascii=False),
|
|
26
|
+
)
|
|
27
|
+
self._settings.sync()
|
|
28
|
+
|
|
29
|
+
def recent_repositories(self) -> list[str]:
|
|
30
|
+
raw_value = self._settings.value("repositories/recent", "[]", type=str)
|
|
31
|
+
raw = str(raw_value) if raw_value is not None else "[]"
|
|
32
|
+
try:
|
|
33
|
+
values = json.loads(raw)
|
|
34
|
+
except (TypeError, ValueError):
|
|
35
|
+
return []
|
|
36
|
+
if not isinstance(values, list):
|
|
37
|
+
return []
|
|
38
|
+
return [str(value) for value in values if isinstance(value, str)][:_MAX_RECENT_REPOSITORIES]
|
|
39
|
+
|
|
40
|
+
def clear_recent_repositories(self) -> None:
|
|
41
|
+
self._settings.remove("repositories/recent")
|
|
42
|
+
self._settings.sync()
|
|
43
|
+
|
|
44
|
+
def set_theme(self, theme: str) -> None:
|
|
45
|
+
normalized = theme.casefold()
|
|
46
|
+
if normalized not in {"system", "light", "dark"}:
|
|
47
|
+
raise ValueError(f"Unsupported theme: {theme}")
|
|
48
|
+
self._settings.setValue("ui/theme", normalized)
|
|
49
|
+
self._settings.sync()
|
|
50
|
+
|
|
51
|
+
def theme(self) -> str:
|
|
52
|
+
value = self._settings.value("ui/theme", "system", type=str)
|
|
53
|
+
return str(value) if value is not None else "system"
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections import defaultdict, deque
|
|
4
|
+
from collections.abc import Callable
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
from uuid import uuid4
|
|
9
|
+
|
|
10
|
+
from PySide6.QtCore import QObject, QRunnable, QThreadPool, Signal, Slot
|
|
11
|
+
|
|
12
|
+
from git_contribution_analyzer.application.ports.cancellation import (
|
|
13
|
+
CancellationSource,
|
|
14
|
+
CancellationToken,
|
|
15
|
+
OperationCancelled,
|
|
16
|
+
)
|
|
17
|
+
from git_contribution_analyzer.application.ports.progress import (
|
|
18
|
+
ProgressEvent,
|
|
19
|
+
ProgressReporter,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
TaskOperation = Callable[[ProgressReporter, CancellationToken], Any]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class _TaskSignals(QObject):
|
|
26
|
+
progress = Signal(str, dict)
|
|
27
|
+
finished = Signal(str, str, str, object)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class _SignalProgressReporter:
|
|
31
|
+
def __init__(self, task_id: str, signals: _TaskSignals) -> None:
|
|
32
|
+
self._task_id = task_id
|
|
33
|
+
self._signals = signals
|
|
34
|
+
|
|
35
|
+
def report(self, event: ProgressEvent) -> None:
|
|
36
|
+
self._signals.progress.emit(
|
|
37
|
+
self._task_id,
|
|
38
|
+
{
|
|
39
|
+
"schemaVersion": event.schema_version,
|
|
40
|
+
"operation": event.operation,
|
|
41
|
+
"stage": event.stage,
|
|
42
|
+
"repository": str(event.repository),
|
|
43
|
+
"current": event.current,
|
|
44
|
+
"total": event.total,
|
|
45
|
+
"message": event.message,
|
|
46
|
+
"occurredAt": event.occurred_at.isoformat(),
|
|
47
|
+
},
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass(slots=True)
|
|
52
|
+
class _TaskRecord:
|
|
53
|
+
task_id: str
|
|
54
|
+
repository_key: str
|
|
55
|
+
operation_name: str
|
|
56
|
+
mutates_workspace: bool
|
|
57
|
+
operation: TaskOperation
|
|
58
|
+
cancellation: CancellationSource
|
|
59
|
+
signals: _TaskSignals
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class _TaskRunnable(QRunnable):
|
|
63
|
+
def __init__(self, record: _TaskRecord) -> None:
|
|
64
|
+
super().__init__()
|
|
65
|
+
self.setAutoDelete(True)
|
|
66
|
+
self._record = record
|
|
67
|
+
|
|
68
|
+
@Slot()
|
|
69
|
+
def run(self) -> None:
|
|
70
|
+
record = self._record
|
|
71
|
+
reporter = _SignalProgressReporter(record.task_id, record.signals)
|
|
72
|
+
try:
|
|
73
|
+
record.cancellation.token.raise_if_cancelled()
|
|
74
|
+
result = record.operation(reporter, record.cancellation.token)
|
|
75
|
+
except OperationCancelled as error:
|
|
76
|
+
record.signals.finished.emit(
|
|
77
|
+
record.task_id,
|
|
78
|
+
record.repository_key,
|
|
79
|
+
"cancelled",
|
|
80
|
+
error,
|
|
81
|
+
)
|
|
82
|
+
except Exception as error:
|
|
83
|
+
record.signals.finished.emit(
|
|
84
|
+
record.task_id,
|
|
85
|
+
record.repository_key,
|
|
86
|
+
"failed",
|
|
87
|
+
error,
|
|
88
|
+
)
|
|
89
|
+
else:
|
|
90
|
+
record.signals.finished.emit(
|
|
91
|
+
record.task_id,
|
|
92
|
+
record.repository_key,
|
|
93
|
+
"succeeded",
|
|
94
|
+
result,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class RepositoryTaskRunner(QObject):
|
|
99
|
+
taskQueued = Signal(str, str)
|
|
100
|
+
taskStarted = Signal(str, str)
|
|
101
|
+
taskProgress = Signal(str, dict)
|
|
102
|
+
taskSucceeded = Signal(str, object)
|
|
103
|
+
taskFailed = Signal(str, object)
|
|
104
|
+
taskCancelled = Signal(str)
|
|
105
|
+
|
|
106
|
+
def __init__(self, *, max_threads: int = 4) -> None:
|
|
107
|
+
super().__init__()
|
|
108
|
+
self._pool = QThreadPool()
|
|
109
|
+
self._pool.setMaxThreadCount(max(1, max_threads))
|
|
110
|
+
self._queues: dict[str, deque[_TaskRecord]] = defaultdict(deque)
|
|
111
|
+
self._active: dict[str, _TaskRecord] = {}
|
|
112
|
+
|
|
113
|
+
def submit(
|
|
114
|
+
self,
|
|
115
|
+
repository: Path,
|
|
116
|
+
operation_name: str,
|
|
117
|
+
*,
|
|
118
|
+
mutates_workspace: bool,
|
|
119
|
+
operation: TaskOperation,
|
|
120
|
+
) -> str:
|
|
121
|
+
task_id = str(uuid4())
|
|
122
|
+
repository_key = str(repository.expanduser().resolve())
|
|
123
|
+
signals = _TaskSignals()
|
|
124
|
+
signals.progress.connect(self.taskProgress)
|
|
125
|
+
signals.finished.connect(self._task_finished)
|
|
126
|
+
record = _TaskRecord(
|
|
127
|
+
task_id=task_id,
|
|
128
|
+
repository_key=repository_key,
|
|
129
|
+
operation_name=operation_name,
|
|
130
|
+
mutates_workspace=mutates_workspace,
|
|
131
|
+
operation=operation,
|
|
132
|
+
cancellation=CancellationSource(),
|
|
133
|
+
signals=signals,
|
|
134
|
+
)
|
|
135
|
+
self._queues[repository_key].append(record)
|
|
136
|
+
self.taskQueued.emit(task_id, operation_name)
|
|
137
|
+
self._start_next(repository_key)
|
|
138
|
+
return task_id
|
|
139
|
+
|
|
140
|
+
def cancel(self, task_id: str) -> bool:
|
|
141
|
+
for active in self._active.values():
|
|
142
|
+
if active.task_id == task_id:
|
|
143
|
+
active.cancellation.cancel()
|
|
144
|
+
return True
|
|
145
|
+
for repository_key, queue in self._queues.items():
|
|
146
|
+
for record in tuple(queue):
|
|
147
|
+
if record.task_id == task_id:
|
|
148
|
+
queue.remove(record)
|
|
149
|
+
self.taskCancelled.emit(task_id)
|
|
150
|
+
if not queue and repository_key not in self._active:
|
|
151
|
+
self._queues.pop(repository_key, None)
|
|
152
|
+
return True
|
|
153
|
+
return False
|
|
154
|
+
|
|
155
|
+
def has_active_tasks(self) -> bool:
|
|
156
|
+
return bool(self._active or any(self._queues.values()))
|
|
157
|
+
|
|
158
|
+
def cancel_all(self) -> None:
|
|
159
|
+
for active in self._active.values():
|
|
160
|
+
active.cancellation.cancel()
|
|
161
|
+
for queue in self._queues.values():
|
|
162
|
+
while queue:
|
|
163
|
+
record = queue.popleft()
|
|
164
|
+
self.taskCancelled.emit(record.task_id)
|
|
165
|
+
|
|
166
|
+
def wait_for_done(self, milliseconds: int = -1) -> bool:
|
|
167
|
+
return self._pool.waitForDone(milliseconds)
|
|
168
|
+
|
|
169
|
+
def _start_next(self, repository_key: str) -> None:
|
|
170
|
+
if repository_key in self._active:
|
|
171
|
+
return
|
|
172
|
+
queue = self._queues.get(repository_key)
|
|
173
|
+
if not queue:
|
|
174
|
+
self._queues.pop(repository_key, None)
|
|
175
|
+
return
|
|
176
|
+
record = queue.popleft()
|
|
177
|
+
self._active[repository_key] = record
|
|
178
|
+
self.taskStarted.emit(record.task_id, record.operation_name)
|
|
179
|
+
self._pool.start(_TaskRunnable(record))
|
|
180
|
+
|
|
181
|
+
@Slot(str, str, str, object)
|
|
182
|
+
def _task_finished(
|
|
183
|
+
self,
|
|
184
|
+
task_id: str,
|
|
185
|
+
repository_key: str,
|
|
186
|
+
state: str,
|
|
187
|
+
payload: object,
|
|
188
|
+
) -> None:
|
|
189
|
+
self._active.pop(repository_key, None)
|
|
190
|
+
if state == "succeeded":
|
|
191
|
+
self.taskSucceeded.emit(task_id, payload)
|
|
192
|
+
elif state == "cancelled":
|
|
193
|
+
self.taskCancelled.emit(task_id)
|
|
194
|
+
else:
|
|
195
|
+
self.taskFailed.emit(task_id, payload)
|
|
196
|
+
self._start_next(repository_key)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Pluggable LLM provider adapters."""
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
from git_contribution_analyzer.adapters.llm.base import JsonHttpProvider
|
|
8
|
+
from git_contribution_analyzer.application.ports.llm import LlmTask
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class AnthropicProvider(JsonHttpProvider):
|
|
12
|
+
provider_id = "anthropic"
|
|
13
|
+
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
*,
|
|
17
|
+
model: str,
|
|
18
|
+
base_url: str,
|
|
19
|
+
api_key: str,
|
|
20
|
+
timeout_seconds: float = 30.0,
|
|
21
|
+
max_retries: int = 2,
|
|
22
|
+
transport: httpx.BaseTransport | None = None,
|
|
23
|
+
) -> None:
|
|
24
|
+
super().__init__(
|
|
25
|
+
model=model,
|
|
26
|
+
base_url=base_url,
|
|
27
|
+
timeout_seconds=timeout_seconds,
|
|
28
|
+
max_retries=max_retries,
|
|
29
|
+
transport=transport,
|
|
30
|
+
)
|
|
31
|
+
self._api_key = api_key
|
|
32
|
+
|
|
33
|
+
def _request(self, task: LlmTask) -> dict[str, Any]:
|
|
34
|
+
return {
|
|
35
|
+
"url": f"{self.base_url}/v1/messages",
|
|
36
|
+
"headers": {
|
|
37
|
+
"x-api-key": self._api_key,
|
|
38
|
+
"anthropic-version": "2023-06-01",
|
|
39
|
+
},
|
|
40
|
+
"json": {
|
|
41
|
+
"model": self.model,
|
|
42
|
+
"max_tokens": 4096,
|
|
43
|
+
"system": task.system_prompt,
|
|
44
|
+
"messages": [{"role": "user", "content": task.user_prompt}],
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
def _health_request(self) -> dict[str, Any]:
|
|
49
|
+
return {"url": self.base_url, "headers": {"x-api-key": self._api_key}}
|
|
50
|
+
|
|
51
|
+
def _extract_text(self, payload: dict[str, Any]) -> str:
|
|
52
|
+
return str(payload["content"][0]["text"])
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from abc import ABC, abstractmethod
|
|
5
|
+
from dataclasses import replace
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import httpx
|
|
9
|
+
|
|
10
|
+
from git_contribution_analyzer.application.ports.llm import (
|
|
11
|
+
LlmCompletion,
|
|
12
|
+
LlmTask,
|
|
13
|
+
ProviderCapabilities,
|
|
14
|
+
)
|
|
15
|
+
from git_contribution_analyzer.domain.errors import (
|
|
16
|
+
LlmAuthenticationError,
|
|
17
|
+
LlmOutputError,
|
|
18
|
+
LlmProviderError,
|
|
19
|
+
LlmRateLimitError,
|
|
20
|
+
LlmTimeoutError,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class JsonHttpProvider(ABC):
|
|
25
|
+
provider_id: str
|
|
26
|
+
|
|
27
|
+
def __init__(
|
|
28
|
+
self,
|
|
29
|
+
*,
|
|
30
|
+
model: str,
|
|
31
|
+
base_url: str,
|
|
32
|
+
timeout_seconds: float = 30.0,
|
|
33
|
+
max_retries: int = 2,
|
|
34
|
+
transport: httpx.BaseTransport | None = None,
|
|
35
|
+
) -> None:
|
|
36
|
+
self.model = model
|
|
37
|
+
self.base_url = base_url.rstrip("/")
|
|
38
|
+
self.timeout_seconds = timeout_seconds
|
|
39
|
+
self.max_retries = max_retries
|
|
40
|
+
self.transport = transport
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def capabilities(self) -> ProviderCapabilities:
|
|
44
|
+
return ProviderCapabilities(structured_output=True, local_execution=False)
|
|
45
|
+
|
|
46
|
+
def complete(self, task: LlmTask) -> LlmCompletion:
|
|
47
|
+
attempts = 0
|
|
48
|
+
request_task = task
|
|
49
|
+
repair_attempted = False
|
|
50
|
+
while attempts <= self.max_retries:
|
|
51
|
+
attempts += 1
|
|
52
|
+
try:
|
|
53
|
+
with httpx.Client(
|
|
54
|
+
timeout=self.timeout_seconds,
|
|
55
|
+
transport=self.transport,
|
|
56
|
+
) as client:
|
|
57
|
+
response = client.post(**self._request(request_task))
|
|
58
|
+
except httpx.TimeoutException as exc:
|
|
59
|
+
if attempts <= self.max_retries:
|
|
60
|
+
continue
|
|
61
|
+
timeout_error = LlmTimeoutError()
|
|
62
|
+
timeout_error.attempts = attempts
|
|
63
|
+
raise timeout_error from exc
|
|
64
|
+
error = self._response_error(response)
|
|
65
|
+
if error is not None:
|
|
66
|
+
if error.retriable and attempts <= self.max_retries:
|
|
67
|
+
continue
|
|
68
|
+
error.attempts = attempts
|
|
69
|
+
raise error
|
|
70
|
+
try:
|
|
71
|
+
raw_text = self._extract_text(response.json())
|
|
72
|
+
content = _parse_json(raw_text)
|
|
73
|
+
except (ValueError, KeyError, TypeError) as exc:
|
|
74
|
+
if not repair_attempted and attempts <= self.max_retries:
|
|
75
|
+
repair_attempted = True
|
|
76
|
+
request_task = replace(
|
|
77
|
+
task,
|
|
78
|
+
user_prompt=(
|
|
79
|
+
f"{task.user_prompt}\n\n"
|
|
80
|
+
"Repair the previous invalid response. Return only a JSON object "
|
|
81
|
+
"that conforms exactly to the supplied output schema."
|
|
82
|
+
),
|
|
83
|
+
)
|
|
84
|
+
continue
|
|
85
|
+
output_error = LlmOutputError()
|
|
86
|
+
output_error.attempts = attempts
|
|
87
|
+
raise output_error from exc
|
|
88
|
+
return LlmCompletion(
|
|
89
|
+
provider_id=self.provider_id,
|
|
90
|
+
model=self.model,
|
|
91
|
+
content=content,
|
|
92
|
+
attempts=attempts,
|
|
93
|
+
input_chars=len(task.system_prompt) + len(task.user_prompt),
|
|
94
|
+
output_chars=len(raw_text),
|
|
95
|
+
)
|
|
96
|
+
raise LlmProviderError("LLM provider retry loop exhausted")
|
|
97
|
+
|
|
98
|
+
def health_check(self) -> bool:
|
|
99
|
+
try:
|
|
100
|
+
with httpx.Client(timeout=self.timeout_seconds, transport=self.transport) as client:
|
|
101
|
+
response = client.get(**self._health_request())
|
|
102
|
+
return response.status_code < 400
|
|
103
|
+
except httpx.HTTPError:
|
|
104
|
+
return False
|
|
105
|
+
|
|
106
|
+
def _response_error(self, response: httpx.Response) -> LlmProviderError | None:
|
|
107
|
+
if response.status_code in (401, 403):
|
|
108
|
+
return LlmAuthenticationError()
|
|
109
|
+
if response.status_code == 429:
|
|
110
|
+
return LlmRateLimitError()
|
|
111
|
+
if response.status_code >= 500:
|
|
112
|
+
return LlmProviderError(
|
|
113
|
+
f"LLM provider server error: HTTP {response.status_code}",
|
|
114
|
+
code="SERVER_ERROR",
|
|
115
|
+
retriable=True,
|
|
116
|
+
)
|
|
117
|
+
if response.status_code >= 400:
|
|
118
|
+
return LlmProviderError(
|
|
119
|
+
f"LLM provider request failed: HTTP {response.status_code}",
|
|
120
|
+
code="REQUEST_ERROR",
|
|
121
|
+
)
|
|
122
|
+
return None
|
|
123
|
+
|
|
124
|
+
@abstractmethod
|
|
125
|
+
def _request(self, task: LlmTask) -> dict[str, Any]: ...
|
|
126
|
+
|
|
127
|
+
@abstractmethod
|
|
128
|
+
def _health_request(self) -> dict[str, Any]: ...
|
|
129
|
+
|
|
130
|
+
@abstractmethod
|
|
131
|
+
def _extract_text(self, payload: dict[str, Any]) -> str: ...
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _parse_json(raw_text: str) -> dict[str, Any]:
|
|
135
|
+
stripped = raw_text.strip()
|
|
136
|
+
if stripped.startswith("```"):
|
|
137
|
+
lines = stripped.splitlines()
|
|
138
|
+
stripped = "\n".join(lines[1:-1]).strip()
|
|
139
|
+
parsed = json.loads(stripped)
|
|
140
|
+
if not isinstance(parsed, dict):
|
|
141
|
+
raise ValueError("Structured output must be a JSON object")
|
|
142
|
+
return parsed
|