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,148 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
from time import perf_counter
|
|
6
|
+
from typing import Any, Protocol
|
|
7
|
+
|
|
8
|
+
from git_contribution_analyzer.application.ports.llm import (
|
|
9
|
+
LlmCompletion,
|
|
10
|
+
LlmProvider,
|
|
11
|
+
LlmTask,
|
|
12
|
+
ProviderCapabilities,
|
|
13
|
+
)
|
|
14
|
+
from git_contribution_analyzer.domain.errors import LlmProviderError
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class LlmAuditStore(Protocol):
|
|
18
|
+
def get_cached(self, request_hash: str) -> dict[str, Any] | None: ...
|
|
19
|
+
|
|
20
|
+
def put_cached(
|
|
21
|
+
self,
|
|
22
|
+
*,
|
|
23
|
+
request_hash: str,
|
|
24
|
+
provider_id: str,
|
|
25
|
+
model: str,
|
|
26
|
+
prompt_version: str,
|
|
27
|
+
schema_version: str,
|
|
28
|
+
response: dict[str, Any],
|
|
29
|
+
) -> None: ...
|
|
30
|
+
|
|
31
|
+
def record_invocation(
|
|
32
|
+
self,
|
|
33
|
+
*,
|
|
34
|
+
run_id: str | None,
|
|
35
|
+
request_hash: str,
|
|
36
|
+
provider_id: str,
|
|
37
|
+
model: str,
|
|
38
|
+
prompt_version: str,
|
|
39
|
+
schema_version: str,
|
|
40
|
+
attempts: int,
|
|
41
|
+
latency_ms: int,
|
|
42
|
+
status: str,
|
|
43
|
+
error_code: str | None = None,
|
|
44
|
+
error_message: str | None = None,
|
|
45
|
+
cache_hit: bool = False,
|
|
46
|
+
) -> None: ...
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def llm_request_hash(task: LlmTask, provider_id: str, model: str) -> str:
|
|
50
|
+
payload = {
|
|
51
|
+
"providerId": provider_id,
|
|
52
|
+
"model": model,
|
|
53
|
+
"promptVersion": task.prompt_version,
|
|
54
|
+
"schemaVersion": task.schema_version,
|
|
55
|
+
"systemPrompt": task.system_prompt,
|
|
56
|
+
"userPrompt": task.user_prompt,
|
|
57
|
+
"outputSchema": task.output_schema,
|
|
58
|
+
}
|
|
59
|
+
canonical = json.dumps(payload, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
|
|
60
|
+
return hashlib.sha256(canonical.encode("utf-8")).hexdigest()
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class CachedAuditedProvider:
|
|
64
|
+
def __init__(
|
|
65
|
+
self,
|
|
66
|
+
delegate: LlmProvider,
|
|
67
|
+
store: LlmAuditStore,
|
|
68
|
+
*,
|
|
69
|
+
run_id: str | None = None,
|
|
70
|
+
) -> None:
|
|
71
|
+
self._delegate = delegate
|
|
72
|
+
self._store = store
|
|
73
|
+
self._run_id = run_id
|
|
74
|
+
self.provider_id = delegate.provider_id
|
|
75
|
+
self.model = delegate.model
|
|
76
|
+
|
|
77
|
+
@property
|
|
78
|
+
def capabilities(self) -> ProviderCapabilities:
|
|
79
|
+
return self._delegate.capabilities
|
|
80
|
+
|
|
81
|
+
def health_check(self) -> bool:
|
|
82
|
+
return self._delegate.health_check()
|
|
83
|
+
|
|
84
|
+
def complete(self, task: LlmTask) -> LlmCompletion:
|
|
85
|
+
request_hash = llm_request_hash(task, self.provider_id, self.model)
|
|
86
|
+
cached = self._store.get_cached(request_hash)
|
|
87
|
+
if cached is not None:
|
|
88
|
+
self._record(
|
|
89
|
+
task,
|
|
90
|
+
request_hash=request_hash,
|
|
91
|
+
attempts=0,
|
|
92
|
+
latency_ms=0,
|
|
93
|
+
status="COMPLETED",
|
|
94
|
+
cache_hit=True,
|
|
95
|
+
)
|
|
96
|
+
return LlmCompletion(
|
|
97
|
+
provider_id=self.provider_id,
|
|
98
|
+
model=self.model,
|
|
99
|
+
content=cached,
|
|
100
|
+
attempts=0,
|
|
101
|
+
input_chars=0,
|
|
102
|
+
output_chars=len(json.dumps(cached, ensure_ascii=False)),
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
started = perf_counter()
|
|
106
|
+
try:
|
|
107
|
+
completion = self._delegate.complete(task)
|
|
108
|
+
except LlmProviderError as exc:
|
|
109
|
+
self._record(
|
|
110
|
+
task,
|
|
111
|
+
request_hash=request_hash,
|
|
112
|
+
attempts=exc.attempts,
|
|
113
|
+
latency_ms=_elapsed_ms(started),
|
|
114
|
+
status="FAILED",
|
|
115
|
+
error_code=exc.code,
|
|
116
|
+
error_message=str(exc),
|
|
117
|
+
)
|
|
118
|
+
raise
|
|
119
|
+
self._store.put_cached(
|
|
120
|
+
request_hash=request_hash,
|
|
121
|
+
provider_id=self.provider_id,
|
|
122
|
+
model=self.model,
|
|
123
|
+
prompt_version=task.prompt_version,
|
|
124
|
+
schema_version=task.schema_version,
|
|
125
|
+
response=completion.content,
|
|
126
|
+
)
|
|
127
|
+
self._record(
|
|
128
|
+
task,
|
|
129
|
+
request_hash=request_hash,
|
|
130
|
+
attempts=completion.attempts,
|
|
131
|
+
latency_ms=_elapsed_ms(started),
|
|
132
|
+
status="COMPLETED",
|
|
133
|
+
)
|
|
134
|
+
return completion
|
|
135
|
+
|
|
136
|
+
def _record(self, task: LlmTask, **values: Any) -> None:
|
|
137
|
+
self._store.record_invocation(
|
|
138
|
+
run_id=self._run_id,
|
|
139
|
+
provider_id=self.provider_id,
|
|
140
|
+
model=self.model,
|
|
141
|
+
prompt_version=task.prompt_version,
|
|
142
|
+
schema_version=task.schema_version,
|
|
143
|
+
**values,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _elapsed_ms(started: float) -> int:
|
|
148
|
+
return max(0, round((perf_counter() - started) * 1000))
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import subprocess
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from git_contribution_analyzer.adapters.llm.command_base import CommandLlmProvider
|
|
9
|
+
from git_contribution_analyzer.application.ports.llm import LlmTask
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ClaudeCliProvider(CommandLlmProvider):
|
|
13
|
+
provider_id = "claude-cli"
|
|
14
|
+
|
|
15
|
+
def _build_command(self, task: LlmTask, _working_directory: Path) -> tuple[str, ...]:
|
|
16
|
+
return (
|
|
17
|
+
self.executable,
|
|
18
|
+
"--print",
|
|
19
|
+
"--output-format",
|
|
20
|
+
"json",
|
|
21
|
+
"--json-schema",
|
|
22
|
+
json.dumps(task.output_schema, ensure_ascii=False, sort_keys=True),
|
|
23
|
+
"--no-session-persistence",
|
|
24
|
+
"--permission-mode",
|
|
25
|
+
"dontAsk",
|
|
26
|
+
"--tools",
|
|
27
|
+
"",
|
|
28
|
+
"--disable-slash-commands",
|
|
29
|
+
"--strict-mcp-config",
|
|
30
|
+
"--no-chrome",
|
|
31
|
+
"--system-prompt",
|
|
32
|
+
task.system_prompt,
|
|
33
|
+
*self._model_arguments(),
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
def _extract_output(
|
|
37
|
+
self, result: subprocess.CompletedProcess[str], _working_directory: Path
|
|
38
|
+
) -> str:
|
|
39
|
+
try:
|
|
40
|
+
payload: Any = json.loads(result.stdout)
|
|
41
|
+
except (TypeError, ValueError):
|
|
42
|
+
return result.stdout
|
|
43
|
+
if isinstance(payload, dict):
|
|
44
|
+
structured = payload.get("structured_output") or payload.get("structuredOutput")
|
|
45
|
+
if isinstance(structured, dict):
|
|
46
|
+
return json.dumps(structured, ensure_ascii=False)
|
|
47
|
+
value = payload.get("result")
|
|
48
|
+
if isinstance(value, dict):
|
|
49
|
+
return json.dumps(value, ensure_ascii=False)
|
|
50
|
+
if isinstance(value, str):
|
|
51
|
+
return value
|
|
52
|
+
return result.stdout
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import subprocess
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from git_contribution_analyzer.adapters.llm.command_base import CommandLlmProvider
|
|
8
|
+
from git_contribution_analyzer.application.ports.llm import LlmTask
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class CodexCliProvider(CommandLlmProvider):
|
|
12
|
+
provider_id = "codex-cli"
|
|
13
|
+
|
|
14
|
+
def _input_text(self, task: LlmTask) -> str:
|
|
15
|
+
return f"{task.system_prompt}\n\nInput context:\n{task.user_prompt}"
|
|
16
|
+
|
|
17
|
+
def _build_command(self, task: LlmTask, working_directory: Path) -> tuple[str, ...]:
|
|
18
|
+
schema_path = working_directory / "output-schema.json"
|
|
19
|
+
schema_path.write_text(
|
|
20
|
+
json.dumps(task.output_schema, ensure_ascii=False, sort_keys=True),
|
|
21
|
+
encoding="utf-8",
|
|
22
|
+
)
|
|
23
|
+
output_path = working_directory / "last-message.json"
|
|
24
|
+
return (
|
|
25
|
+
self.executable,
|
|
26
|
+
"exec",
|
|
27
|
+
"--ephemeral",
|
|
28
|
+
"--skip-git-repo-check",
|
|
29
|
+
"--ignore-rules",
|
|
30
|
+
"--config",
|
|
31
|
+
"mcp_servers={}",
|
|
32
|
+
"--sandbox",
|
|
33
|
+
"read-only",
|
|
34
|
+
"--color",
|
|
35
|
+
"never",
|
|
36
|
+
"--output-schema",
|
|
37
|
+
str(schema_path),
|
|
38
|
+
"--output-last-message",
|
|
39
|
+
str(output_path),
|
|
40
|
+
"-C",
|
|
41
|
+
str(working_directory),
|
|
42
|
+
*self._model_arguments(),
|
|
43
|
+
"-",
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
def _extract_output(
|
|
47
|
+
self, _result: subprocess.CompletedProcess[str], working_directory: Path
|
|
48
|
+
) -> str:
|
|
49
|
+
try:
|
|
50
|
+
return (working_directory / "last-message.json").read_text(encoding="utf-8")
|
|
51
|
+
except OSError:
|
|
52
|
+
return ""
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import subprocess
|
|
4
|
+
import tempfile
|
|
5
|
+
from abc import ABC, abstractmethod
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Protocol
|
|
8
|
+
|
|
9
|
+
from git_contribution_analyzer.adapters.llm.base import _parse_json
|
|
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
|
+
LlmOutputError,
|
|
17
|
+
LlmProviderError,
|
|
18
|
+
LlmTimeoutError,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
MAX_OUTPUT_CHARS = 2_000_000
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class CommandExecutor(Protocol):
|
|
25
|
+
def __call__(
|
|
26
|
+
self,
|
|
27
|
+
command: tuple[str, ...],
|
|
28
|
+
*,
|
|
29
|
+
input_text: str | None,
|
|
30
|
+
cwd: Path,
|
|
31
|
+
timeout_seconds: float,
|
|
32
|
+
) -> subprocess.CompletedProcess[str]: ...
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def execute_command(
|
|
36
|
+
command: tuple[str, ...],
|
|
37
|
+
*,
|
|
38
|
+
input_text: str | None,
|
|
39
|
+
cwd: Path,
|
|
40
|
+
timeout_seconds: float,
|
|
41
|
+
) -> subprocess.CompletedProcess[str]:
|
|
42
|
+
return subprocess.run(
|
|
43
|
+
command,
|
|
44
|
+
input=input_text,
|
|
45
|
+
cwd=cwd,
|
|
46
|
+
capture_output=True,
|
|
47
|
+
text=True,
|
|
48
|
+
encoding="utf-8",
|
|
49
|
+
errors="replace",
|
|
50
|
+
timeout=timeout_seconds,
|
|
51
|
+
check=False,
|
|
52
|
+
shell=False,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class CommandLlmProvider(ABC):
|
|
57
|
+
provider_id: str
|
|
58
|
+
|
|
59
|
+
def __init__(
|
|
60
|
+
self,
|
|
61
|
+
*,
|
|
62
|
+
executable: str,
|
|
63
|
+
model: str,
|
|
64
|
+
timeout_seconds: float = 120.0,
|
|
65
|
+
executor: CommandExecutor = execute_command,
|
|
66
|
+
) -> None:
|
|
67
|
+
self.executable = executable
|
|
68
|
+
self.model = model or "configured-default"
|
|
69
|
+
self.timeout_seconds = timeout_seconds
|
|
70
|
+
self._executor = executor
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def capabilities(self) -> ProviderCapabilities:
|
|
74
|
+
return ProviderCapabilities(structured_output=True, local_execution=True)
|
|
75
|
+
|
|
76
|
+
def health_check(self) -> bool:
|
|
77
|
+
try:
|
|
78
|
+
with tempfile.TemporaryDirectory(prefix="gca-llm-health-") as directory:
|
|
79
|
+
result = self._executor(
|
|
80
|
+
(self.executable, "--version"),
|
|
81
|
+
input_text=None,
|
|
82
|
+
cwd=Path(directory),
|
|
83
|
+
timeout_seconds=min(self.timeout_seconds, 10.0),
|
|
84
|
+
)
|
|
85
|
+
return result.returncode == 0
|
|
86
|
+
except (OSError, subprocess.SubprocessError):
|
|
87
|
+
return False
|
|
88
|
+
|
|
89
|
+
def complete(self, task: LlmTask) -> LlmCompletion:
|
|
90
|
+
try:
|
|
91
|
+
with tempfile.TemporaryDirectory(prefix="gca-llm-") as directory:
|
|
92
|
+
working_directory = Path(directory)
|
|
93
|
+
command = self._build_command(task, working_directory)
|
|
94
|
+
result = self._executor(
|
|
95
|
+
command,
|
|
96
|
+
input_text=self._input_text(task),
|
|
97
|
+
cwd=working_directory,
|
|
98
|
+
timeout_seconds=self.timeout_seconds,
|
|
99
|
+
)
|
|
100
|
+
if result.returncode != 0:
|
|
101
|
+
error = LlmProviderError(
|
|
102
|
+
f"{self.provider_id} process exited with code {result.returncode}",
|
|
103
|
+
code="CLI_ERROR",
|
|
104
|
+
)
|
|
105
|
+
error.attempts = 1
|
|
106
|
+
raise error
|
|
107
|
+
raw_text = self._extract_output(result, working_directory)
|
|
108
|
+
except subprocess.TimeoutExpired as exc:
|
|
109
|
+
error = LlmTimeoutError(f"{self.provider_id} process timed out")
|
|
110
|
+
error.attempts = 1
|
|
111
|
+
raise error from exc
|
|
112
|
+
except (FileNotFoundError, PermissionError, OSError) as exc:
|
|
113
|
+
error = LlmProviderError(
|
|
114
|
+
f"{self.provider_id} executable is not available",
|
|
115
|
+
code="CLI_NOT_AVAILABLE",
|
|
116
|
+
)
|
|
117
|
+
error.attempts = 1
|
|
118
|
+
raise error from exc
|
|
119
|
+
|
|
120
|
+
if len(raw_text) > MAX_OUTPUT_CHARS:
|
|
121
|
+
error = LlmOutputError(f"{self.provider_id} output exceeds the size limit")
|
|
122
|
+
error.attempts = 1
|
|
123
|
+
raise error
|
|
124
|
+
try:
|
|
125
|
+
content = _parse_json(raw_text)
|
|
126
|
+
except (TypeError, ValueError) as exc:
|
|
127
|
+
error = LlmOutputError(f"{self.provider_id} returned invalid structured output")
|
|
128
|
+
error.attempts = 1
|
|
129
|
+
raise error from exc
|
|
130
|
+
return LlmCompletion(
|
|
131
|
+
provider_id=self.provider_id,
|
|
132
|
+
model=self.model,
|
|
133
|
+
content=content,
|
|
134
|
+
attempts=1,
|
|
135
|
+
input_chars=len(task.system_prompt) + len(task.user_prompt),
|
|
136
|
+
output_chars=len(raw_text),
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
def _input_text(self, task: LlmTask) -> str:
|
|
140
|
+
return task.user_prompt
|
|
141
|
+
|
|
142
|
+
@abstractmethod
|
|
143
|
+
def _build_command(self, task: LlmTask, working_directory: Path) -> tuple[str, ...]: ...
|
|
144
|
+
|
|
145
|
+
@abstractmethod
|
|
146
|
+
def _extract_output(
|
|
147
|
+
self, result: subprocess.CompletedProcess[str], working_directory: Path
|
|
148
|
+
) -> str: ...
|
|
149
|
+
|
|
150
|
+
def _model_arguments(self) -> tuple[str, ...]:
|
|
151
|
+
if self.model in ("", "default", "configured-default"):
|
|
152
|
+
return ()
|
|
153
|
+
return ("--model", self.model)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from git_contribution_analyzer.application.ports.llm import (
|
|
7
|
+
LlmCompletion,
|
|
8
|
+
LlmTask,
|
|
9
|
+
ProviderCapabilities,
|
|
10
|
+
)
|
|
11
|
+
from git_contribution_analyzer.domain.errors import LlmOutputError
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class MockLlmProvider:
|
|
15
|
+
provider_id = "mock"
|
|
16
|
+
model = "deterministic"
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
*,
|
|
21
|
+
response: dict[str, Any] | None = None,
|
|
22
|
+
raw_response: str | None = None,
|
|
23
|
+
) -> None:
|
|
24
|
+
self.response = response
|
|
25
|
+
self.raw_response = raw_response
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def capabilities(self) -> ProviderCapabilities:
|
|
29
|
+
return ProviderCapabilities(structured_output=True, local_execution=True)
|
|
30
|
+
|
|
31
|
+
def complete(self, task: LlmTask) -> LlmCompletion:
|
|
32
|
+
evidence_id = task.allowed_evidence_ids[0] if task.allowed_evidence_ids else "EV-000"
|
|
33
|
+
semantic_default = {
|
|
34
|
+
"overallSummary": [
|
|
35
|
+
{
|
|
36
|
+
"text": "Delivered evidence-backed repository changes.",
|
|
37
|
+
"evidenceIds": [evidence_id],
|
|
38
|
+
"confidence": "MEDIUM",
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
"contributionSummaries": [],
|
|
42
|
+
"capabilityExplanations": [],
|
|
43
|
+
"resumeBullets": [],
|
|
44
|
+
}
|
|
45
|
+
if task.task_id == "assessment-explanation":
|
|
46
|
+
default = {
|
|
47
|
+
"overallExplanation": [
|
|
48
|
+
{
|
|
49
|
+
"text": "The assessment is supported by deterministic evidence.",
|
|
50
|
+
"evidenceIds": [evidence_id],
|
|
51
|
+
"confidence": "MEDIUM",
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
"itemExplanations": [],
|
|
55
|
+
}
|
|
56
|
+
elif task.task_id == "resume-generation":
|
|
57
|
+
context = json.loads(task.user_prompt)
|
|
58
|
+
allowed_claim = context["allowedClaims"][0]
|
|
59
|
+
default = {
|
|
60
|
+
"projectSummaryCandidates": [],
|
|
61
|
+
"experienceBullets": [allowed_claim],
|
|
62
|
+
}
|
|
63
|
+
else:
|
|
64
|
+
default = semantic_default
|
|
65
|
+
raw = self.raw_response or json.dumps(self.response or default)
|
|
66
|
+
try:
|
|
67
|
+
parsed = json.loads(raw)
|
|
68
|
+
except (TypeError, ValueError) as exc:
|
|
69
|
+
raise LlmOutputError() from exc
|
|
70
|
+
if not isinstance(parsed, dict):
|
|
71
|
+
raise LlmOutputError()
|
|
72
|
+
return LlmCompletion(
|
|
73
|
+
provider_id=self.provider_id,
|
|
74
|
+
model=self.model,
|
|
75
|
+
content=parsed,
|
|
76
|
+
attempts=1,
|
|
77
|
+
input_chars=len(task.system_prompt) + len(task.user_prompt),
|
|
78
|
+
output_chars=len(raw),
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
def health_check(self) -> bool:
|
|
82
|
+
return True
|
|
@@ -0,0 +1,53 @@
|
|
|
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, ProviderCapabilities
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class OllamaProvider(JsonHttpProvider):
|
|
12
|
+
provider_id = "ollama"
|
|
13
|
+
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
*,
|
|
17
|
+
model: str,
|
|
18
|
+
base_url: str,
|
|
19
|
+
timeout_seconds: float = 60.0,
|
|
20
|
+
max_retries: int = 2,
|
|
21
|
+
transport: httpx.BaseTransport | None = None,
|
|
22
|
+
) -> None:
|
|
23
|
+
super().__init__(
|
|
24
|
+
model=model,
|
|
25
|
+
base_url=base_url,
|
|
26
|
+
timeout_seconds=timeout_seconds,
|
|
27
|
+
max_retries=max_retries,
|
|
28
|
+
transport=transport,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def capabilities(self) -> ProviderCapabilities:
|
|
33
|
+
return ProviderCapabilities(structured_output=True, local_execution=True)
|
|
34
|
+
|
|
35
|
+
def _request(self, task: LlmTask) -> dict[str, Any]:
|
|
36
|
+
return {
|
|
37
|
+
"url": f"{self.base_url}/api/chat",
|
|
38
|
+
"json": {
|
|
39
|
+
"model": self.model,
|
|
40
|
+
"stream": False,
|
|
41
|
+
"messages": [
|
|
42
|
+
{"role": "system", "content": task.system_prompt},
|
|
43
|
+
{"role": "user", "content": task.user_prompt},
|
|
44
|
+
],
|
|
45
|
+
"format": task.output_schema,
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
def _health_request(self) -> dict[str, Any]:
|
|
50
|
+
return {"url": f"{self.base_url}/api/tags"}
|
|
51
|
+
|
|
52
|
+
def _extract_text(self, payload: dict[str, Any]) -> str:
|
|
53
|
+
return str(payload["message"]["content"])
|
|
@@ -0,0 +1,61 @@
|
|
|
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 OpenAiCompatibleProvider(JsonHttpProvider):
|
|
12
|
+
provider_id = "openai-compatible"
|
|
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}/chat/completions",
|
|
36
|
+
"headers": {"Authorization": f"Bearer {self._api_key}"},
|
|
37
|
+
"json": {
|
|
38
|
+
"model": self.model,
|
|
39
|
+
"messages": [
|
|
40
|
+
{"role": "system", "content": task.system_prompt},
|
|
41
|
+
{"role": "user", "content": task.user_prompt},
|
|
42
|
+
],
|
|
43
|
+
"response_format": {
|
|
44
|
+
"type": "json_schema",
|
|
45
|
+
"json_schema": {
|
|
46
|
+
"name": "gca_semantic_report",
|
|
47
|
+
"strict": True,
|
|
48
|
+
"schema": task.output_schema,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
def _health_request(self) -> dict[str, Any]:
|
|
55
|
+
return {
|
|
56
|
+
"url": f"{self.base_url}/models",
|
|
57
|
+
"headers": {"Authorization": f"Bearer {self._api_key}"},
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
def _extract_text(self, payload: dict[str, Any]) -> str:
|
|
61
|
+
return str(payload["choices"][0]["message"]["content"])
|