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,50 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from threading import Event
|
|
4
|
+
from typing import Protocol
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class OperationCancelled(Exception):
|
|
8
|
+
"""Raised at a safe boundary after cooperative cancellation was requested."""
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class CancellationToken(Protocol):
|
|
12
|
+
@property
|
|
13
|
+
def cancellation_requested(self) -> bool: ...
|
|
14
|
+
|
|
15
|
+
def raise_if_cancelled(self) -> None: ...
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class NeverCancelledToken:
|
|
19
|
+
@property
|
|
20
|
+
def cancellation_requested(self) -> bool:
|
|
21
|
+
return False
|
|
22
|
+
|
|
23
|
+
def raise_if_cancelled(self) -> None:
|
|
24
|
+
return
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class _EventCancellationToken:
|
|
28
|
+
def __init__(self, event: Event) -> None:
|
|
29
|
+
self._event = event
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def cancellation_requested(self) -> bool:
|
|
33
|
+
return self._event.is_set()
|
|
34
|
+
|
|
35
|
+
def raise_if_cancelled(self) -> None:
|
|
36
|
+
if self.cancellation_requested:
|
|
37
|
+
raise OperationCancelled("Operation cancelled")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class CancellationSource:
|
|
41
|
+
def __init__(self) -> None:
|
|
42
|
+
self._event = Event()
|
|
43
|
+
self._token = _EventCancellationToken(self._event)
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def token(self) -> CancellationToken:
|
|
47
|
+
return self._token
|
|
48
|
+
|
|
49
|
+
def cancel(self) -> None:
|
|
50
|
+
self._event.set()
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterable
|
|
4
|
+
from typing import Protocol
|
|
5
|
+
|
|
6
|
+
from git_contribution_analyzer.domain.models.git_history import GitCommit, GitRef
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class GitHistoryPort(Protocol):
|
|
10
|
+
def list_refs(self) -> tuple[GitRef, ...]: ...
|
|
11
|
+
|
|
12
|
+
def list_commit_hashes(self) -> tuple[str, ...]: ...
|
|
13
|
+
|
|
14
|
+
def read_commits(self, commit_hashes: Iterable[str]) -> tuple[GitCommit, ...]: ...
|
|
15
|
+
|
|
16
|
+
def reachable_commits(self, ref_name: str) -> frozenset[str]: ...
|
|
17
|
+
|
|
18
|
+
def first_release_tags(self, commit_hashes: Iterable[str]) -> dict[str, str]: ...
|
|
19
|
+
|
|
20
|
+
def is_ancestor(self, commit_hash: str, ref_name: str) -> bool: ...
|
|
21
|
+
|
|
22
|
+
def tags_containing(self, commit_hash: str) -> tuple[str, ...]: ...
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any, Protocol
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass(frozen=True, slots=True)
|
|
8
|
+
class ProviderCapabilities:
|
|
9
|
+
structured_output: bool
|
|
10
|
+
local_execution: bool
|
|
11
|
+
health_check: bool = True
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass(frozen=True, slots=True)
|
|
15
|
+
class LlmTask:
|
|
16
|
+
task_id: str
|
|
17
|
+
prompt_version: str
|
|
18
|
+
schema_version: str
|
|
19
|
+
system_prompt: str
|
|
20
|
+
user_prompt: str
|
|
21
|
+
output_schema: dict[str, Any]
|
|
22
|
+
allowed_evidence_ids: tuple[str, ...]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass(frozen=True, slots=True)
|
|
26
|
+
class LlmCompletion:
|
|
27
|
+
provider_id: str
|
|
28
|
+
model: str
|
|
29
|
+
content: dict[str, Any]
|
|
30
|
+
attempts: int
|
|
31
|
+
input_chars: int
|
|
32
|
+
output_chars: int
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class LlmProvider(Protocol):
|
|
36
|
+
provider_id: str
|
|
37
|
+
model: str
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def capabilities(self) -> ProviderCapabilities: ...
|
|
41
|
+
|
|
42
|
+
def complete(self, task: LlmTask) -> LlmCompletion: ...
|
|
43
|
+
|
|
44
|
+
def health_check(self) -> bool: ...
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from contextlib import AbstractContextManager
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any, Protocol
|
|
6
|
+
|
|
7
|
+
from git_contribution_analyzer.domain.models.portfolio import (
|
|
8
|
+
PortfolioManifest,
|
|
9
|
+
PortfolioRepoSpec,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class PortfolioStore(Protocol):
|
|
14
|
+
portfolio_root: Path
|
|
15
|
+
|
|
16
|
+
def exists(self) -> bool: ...
|
|
17
|
+
|
|
18
|
+
def initialize(self, manifest: PortfolioManifest) -> None: ...
|
|
19
|
+
|
|
20
|
+
def load_manifest(self) -> PortfolioManifest: ...
|
|
21
|
+
|
|
22
|
+
def save_manifest(self, manifest: PortfolioManifest) -> None: ...
|
|
23
|
+
|
|
24
|
+
def resolve_repo_path(self, repo: PortfolioRepoSpec) -> Path: ...
|
|
25
|
+
|
|
26
|
+
def save_run(self, run_id: str, run_type: str, payload: dict[str, Any]) -> Path: ...
|
|
27
|
+
|
|
28
|
+
def load_run(self, run_id: str) -> dict[str, Any]: ...
|
|
29
|
+
|
|
30
|
+
def list_runs(self) -> list[dict[str, Any]]: ...
|
|
31
|
+
|
|
32
|
+
def save_report(self, filename: str, content: str) -> Path: ...
|
|
33
|
+
|
|
34
|
+
def lock(self) -> AbstractContextManager[None]: ...
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Protocol
|
|
8
|
+
|
|
9
|
+
_STAGE_PATTERN = re.compile(r"^[a-z][a-z0-9_]*$")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
13
|
+
class ProgressEvent:
|
|
14
|
+
task_id: str
|
|
15
|
+
operation: str
|
|
16
|
+
stage: str
|
|
17
|
+
repository: Path
|
|
18
|
+
current: int | None = None
|
|
19
|
+
total: int | None = None
|
|
20
|
+
message: str = ""
|
|
21
|
+
occurred_at: datetime
|
|
22
|
+
schema_version: str = "1.0"
|
|
23
|
+
|
|
24
|
+
def __post_init__(self) -> None:
|
|
25
|
+
if not _STAGE_PATTERN.fullmatch(self.stage):
|
|
26
|
+
raise ValueError("Progress stage must be a stable lower_snake_case identifier")
|
|
27
|
+
if (self.current is None) != (self.total is None):
|
|
28
|
+
raise ValueError("Progress current and total must be provided together")
|
|
29
|
+
if (
|
|
30
|
+
self.current is not None
|
|
31
|
+
and self.total is not None
|
|
32
|
+
and (self.current < 0 or self.total < 0 or self.current > self.total)
|
|
33
|
+
):
|
|
34
|
+
raise ValueError("Progress counts must satisfy 0 <= current <= total")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ProgressReporter(Protocol):
|
|
38
|
+
def report(self, event: ProgressEvent) -> None: ...
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class NullProgressReporter:
|
|
42
|
+
def report(self, event: ProgressEvent) -> None:
|
|
43
|
+
del event
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterable
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
from typing import Any, Protocol, runtime_checkable
|
|
6
|
+
|
|
7
|
+
from git_contribution_analyzer.domain.models.contribution import ContributionCommit
|
|
8
|
+
from git_contribution_analyzer.domain.models.git_history import GitCommit
|
|
9
|
+
from git_contribution_analyzer.domain.models.structural_baseline import (
|
|
10
|
+
StructuralBaseline,
|
|
11
|
+
StructuralRuleConfig,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@runtime_checkable
|
|
16
|
+
class StructuralBaselineStore(Protocol):
|
|
17
|
+
def repository_id(self) -> str: ...
|
|
18
|
+
|
|
19
|
+
def sync_commit_facts(
|
|
20
|
+
self,
|
|
21
|
+
git_commits: Iterable[GitCommit],
|
|
22
|
+
*,
|
|
23
|
+
clear_existing: bool,
|
|
24
|
+
maximum_context_paths: int = 200,
|
|
25
|
+
) -> dict[str, int]: ...
|
|
26
|
+
|
|
27
|
+
def begin_baseline(
|
|
28
|
+
self,
|
|
29
|
+
build_id: str,
|
|
30
|
+
*,
|
|
31
|
+
branch: str,
|
|
32
|
+
scope: str | None,
|
|
33
|
+
cutoff: datetime,
|
|
34
|
+
baseline_commit: str | None,
|
|
35
|
+
filter_fingerprint: str,
|
|
36
|
+
config: StructuralRuleConfig,
|
|
37
|
+
) -> None: ...
|
|
38
|
+
|
|
39
|
+
def finish_baseline(
|
|
40
|
+
self,
|
|
41
|
+
build_id: str,
|
|
42
|
+
*,
|
|
43
|
+
status: str,
|
|
44
|
+
error_message: str,
|
|
45
|
+
) -> None: ...
|
|
46
|
+
|
|
47
|
+
def load_commits(
|
|
48
|
+
self,
|
|
49
|
+
*,
|
|
50
|
+
allowed_hashes: set[str],
|
|
51
|
+
cutoff: datetime,
|
|
52
|
+
scope: str | None,
|
|
53
|
+
) -> tuple[ContributionCommit, ...]: ...
|
|
54
|
+
|
|
55
|
+
def latest_fact_commit(
|
|
56
|
+
self,
|
|
57
|
+
*,
|
|
58
|
+
allowed_hashes: set[str],
|
|
59
|
+
cutoff: datetime,
|
|
60
|
+
scope: str | None,
|
|
61
|
+
) -> str | None: ...
|
|
62
|
+
|
|
63
|
+
def save_baseline(
|
|
64
|
+
self,
|
|
65
|
+
baseline: StructuralBaseline,
|
|
66
|
+
*,
|
|
67
|
+
branch: str,
|
|
68
|
+
scope: str | None,
|
|
69
|
+
baseline_commit: str | None,
|
|
70
|
+
filter_fingerprint: str,
|
|
71
|
+
diagnostic_id: str | None = None,
|
|
72
|
+
) -> dict[str, Any]: ...
|
|
73
|
+
|
|
74
|
+
def mark_stale(self, baseline_ids: Iterable[str]) -> int: ...
|
|
75
|
+
|
|
76
|
+
def find_completed(
|
|
77
|
+
self,
|
|
78
|
+
*,
|
|
79
|
+
branch: str,
|
|
80
|
+
scope: str | None,
|
|
81
|
+
cutoff: datetime,
|
|
82
|
+
baseline_commit: str | None,
|
|
83
|
+
filter_fingerprint: str,
|
|
84
|
+
time_strategy: str,
|
|
85
|
+
) -> dict[str, Any] | None: ...
|
|
86
|
+
|
|
87
|
+
def show(self, baseline_id: str) -> dict[str, Any] | None: ...
|
|
88
|
+
|
|
89
|
+
def status(self) -> dict[str, Any]: ...
|
|
90
|
+
|
|
91
|
+
def completed_baseline_refs(self) -> tuple[dict[str, str | None], ...]: ...
|
|
92
|
+
|
|
93
|
+
def prune(self, keep: int) -> dict[str, int]: ...
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Application services composed from abstract ports."""
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from importlib.resources import files
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from pydantic import BaseModel, ConfigDict, Field, ValidationError
|
|
10
|
+
|
|
11
|
+
from git_contribution_analyzer.application.ports.llm import (
|
|
12
|
+
LlmCompletion,
|
|
13
|
+
LlmProvider,
|
|
14
|
+
LlmTask,
|
|
15
|
+
)
|
|
16
|
+
from git_contribution_analyzer.domain.errors import LlmOutputError
|
|
17
|
+
from git_contribution_analyzer.domain.models.snapshot import EvidenceSnapshot
|
|
18
|
+
|
|
19
|
+
PERCENTAGE_PATTERN = re.compile(r"\b\d+(?:\.\d+)?\s*%")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class _ExplanationClaim(BaseModel):
|
|
23
|
+
model_config = ConfigDict(extra="forbid", populate_by_name=True)
|
|
24
|
+
|
|
25
|
+
text: str = Field(min_length=1)
|
|
26
|
+
evidence_ids: list[str] = Field(alias="evidenceIds", min_length=1)
|
|
27
|
+
confidence: str
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class _ItemExplanation(_ExplanationClaim):
|
|
31
|
+
contribution_item_id: str = Field(alias="contributionItemId")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class AssessmentExplanation(BaseModel):
|
|
35
|
+
model_config = ConfigDict(extra="forbid", populate_by_name=True)
|
|
36
|
+
|
|
37
|
+
overall_explanation: list[_ExplanationClaim] = Field(alias="overallExplanation")
|
|
38
|
+
item_explanations: list[_ItemExplanation] = Field(alias="itemExplanations")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass(frozen=True, slots=True)
|
|
42
|
+
class AssessmentExplanationResult:
|
|
43
|
+
explanation: dict[str, Any]
|
|
44
|
+
completion: LlmCompletion
|
|
45
|
+
task: LlmTask
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def explain_assessment(
|
|
49
|
+
report: dict[str, Any],
|
|
50
|
+
snapshot: EvidenceSnapshot,
|
|
51
|
+
provider: LlmProvider,
|
|
52
|
+
) -> AssessmentExplanationResult:
|
|
53
|
+
task = build_assessment_explanation_task(report, snapshot)
|
|
54
|
+
completion = provider.complete(task)
|
|
55
|
+
try:
|
|
56
|
+
explanation = AssessmentExplanation.model_validate(completion.content)
|
|
57
|
+
except ValidationError as exc:
|
|
58
|
+
raise LlmOutputError(
|
|
59
|
+
"LLM output does not match assessment-explanation-v1 schema"
|
|
60
|
+
) from exc
|
|
61
|
+
allowed_evidence = set(task.allowed_evidence_ids)
|
|
62
|
+
allowed_items = {
|
|
63
|
+
item["contributionItemId"]
|
|
64
|
+
for subject in report["subjects"]
|
|
65
|
+
for item in subject["itemAssessments"]
|
|
66
|
+
}
|
|
67
|
+
claims = [*explanation.overall_explanation, *explanation.item_explanations]
|
|
68
|
+
if any(not set(claim.evidence_ids) <= allowed_evidence for claim in claims):
|
|
69
|
+
raise LlmOutputError("Assessment explanation references unknown Evidence IDs")
|
|
70
|
+
if any(PERCENTAGE_PATTERN.search(claim.text) for claim in claims):
|
|
71
|
+
raise LlmOutputError("Assessment explanation contains an unsupported percentage")
|
|
72
|
+
if any(
|
|
73
|
+
claim.contribution_item_id not in allowed_items
|
|
74
|
+
for claim in explanation.item_explanations
|
|
75
|
+
):
|
|
76
|
+
raise LlmOutputError("Assessment explanation references an unknown item")
|
|
77
|
+
return AssessmentExplanationResult(
|
|
78
|
+
explanation=explanation.model_dump(by_alias=True, mode="json"),
|
|
79
|
+
completion=completion,
|
|
80
|
+
task=task,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def build_assessment_explanation_task(
|
|
85
|
+
report: dict[str, Any], snapshot: EvidenceSnapshot
|
|
86
|
+
) -> LlmTask:
|
|
87
|
+
allowed_evidence_ids = tuple(
|
|
88
|
+
sorted(
|
|
89
|
+
{
|
|
90
|
+
evidence_id
|
|
91
|
+
for subject in report["subjects"]
|
|
92
|
+
for item in subject["itemAssessments"]
|
|
93
|
+
for evidence_id in item["evidenceIds"]
|
|
94
|
+
}
|
|
95
|
+
)
|
|
96
|
+
)
|
|
97
|
+
context = {
|
|
98
|
+
"snapshotId": snapshot.id,
|
|
99
|
+
"scopeType": report["scopeType"],
|
|
100
|
+
"workloadSummary": report["workloadSummary"],
|
|
101
|
+
"difficultyDistribution": report["difficultyDistribution"],
|
|
102
|
+
"technicalSummary": report["technicalSummary"],
|
|
103
|
+
"businessSummary": report["businessSummary"],
|
|
104
|
+
"items": [
|
|
105
|
+
{
|
|
106
|
+
"contributionItemId": item["contributionItemId"],
|
|
107
|
+
"completionBucket": item["completionBucket"],
|
|
108
|
+
"size": item["size"],
|
|
109
|
+
"difficulty": item["difficulty"],
|
|
110
|
+
"evidenceIds": item["evidenceIds"],
|
|
111
|
+
}
|
|
112
|
+
for subject in report["subjects"]
|
|
113
|
+
for item in subject["itemAssessments"]
|
|
114
|
+
],
|
|
115
|
+
}
|
|
116
|
+
prompt = files("git_contribution_analyzer.prompts.assessment.v1").joinpath(
|
|
117
|
+
"explanation.txt"
|
|
118
|
+
).read_text(encoding="utf-8")
|
|
119
|
+
return LlmTask(
|
|
120
|
+
task_id="assessment-explanation",
|
|
121
|
+
prompt_version="assessment-explanation-v1",
|
|
122
|
+
schema_version="assessment-explanation-v1",
|
|
123
|
+
system_prompt=prompt,
|
|
124
|
+
user_prompt=json.dumps(context, ensure_ascii=False, sort_keys=True, separators=(",", ":")),
|
|
125
|
+
output_schema=AssessmentExplanation.model_json_schema(by_alias=True),
|
|
126
|
+
allowed_evidence_ids=allowed_evidence_ids,
|
|
127
|
+
)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from git_contribution_analyzer.adapters.git.local_identity import read_local_git_identity
|
|
6
|
+
from git_contribution_analyzer.adapters.workspace.portfolio_workspace import FilePortfolioStore
|
|
7
|
+
from git_contribution_analyzer.domain.errors import ConfigurationError
|
|
8
|
+
from git_contribution_analyzer.domain.models.portfolio import PortfolioIdentityRule
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def resolve_repo_default_person(repo_path: Path) -> str:
|
|
12
|
+
"""在未显式传 --person 时, 只读推断当前仓库本地 Git 身份."""
|
|
13
|
+
identity = read_local_git_identity(repo_path)
|
|
14
|
+
selector = identity.preferred_selector
|
|
15
|
+
if not selector:
|
|
16
|
+
raise ConfigurationError(
|
|
17
|
+
"Unable to detect local Git identity; pass --person <email|name> "
|
|
18
|
+
"or configure git user.email"
|
|
19
|
+
)
|
|
20
|
+
return selector
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _match_identity_rule(
|
|
24
|
+
selector: str,
|
|
25
|
+
identities: tuple[PortfolioIdentityRule, ...],
|
|
26
|
+
) -> PortfolioIdentityRule | None:
|
|
27
|
+
target = selector.strip().lower()
|
|
28
|
+
if not target:
|
|
29
|
+
return None
|
|
30
|
+
for rule in identities:
|
|
31
|
+
if (
|
|
32
|
+
rule.canonical_email.lower() == target
|
|
33
|
+
or rule.canonical_name.lower() == target
|
|
34
|
+
or any(
|
|
35
|
+
(alias.email and alias.email.lower() == target)
|
|
36
|
+
or (alias.name and alias.name.lower() == target)
|
|
37
|
+
for alias in rule.aliases
|
|
38
|
+
)
|
|
39
|
+
):
|
|
40
|
+
return rule
|
|
41
|
+
return None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def resolve_portfolio_default_person(portfolio_dir: Path) -> str:
|
|
45
|
+
"""在 Portfolio 场景未显式传 --person 时, 确定性推断目标身份."""
|
|
46
|
+
store = FilePortfolioStore(portfolio_dir)
|
|
47
|
+
manifest = store.load_manifest()
|
|
48
|
+
if len(manifest.identities) == 1:
|
|
49
|
+
return manifest.identities[0].canonical_email
|
|
50
|
+
|
|
51
|
+
local_identity = read_local_git_identity(None)
|
|
52
|
+
for candidate in (local_identity.email, local_identity.name):
|
|
53
|
+
if candidate:
|
|
54
|
+
matched = _match_identity_rule(candidate, manifest.identities)
|
|
55
|
+
if matched is not None:
|
|
56
|
+
return matched.canonical_email
|
|
57
|
+
|
|
58
|
+
raise ConfigurationError(
|
|
59
|
+
"Unable to infer a unique portfolio identity; pass --person <name|email> "
|
|
60
|
+
"or configure a single identity in portfolio.yml"
|
|
61
|
+
)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from uuid import NAMESPACE_URL, uuid5
|
|
6
|
+
|
|
7
|
+
from git_contribution_analyzer.domain.models.analysis import AnalysisFilters
|
|
8
|
+
from git_contribution_analyzer.domain.models.contribution import ContributionCommit
|
|
9
|
+
from git_contribution_analyzer.domain.models.snapshot import (
|
|
10
|
+
EvidenceSnapshot,
|
|
11
|
+
SnapshotPerson,
|
|
12
|
+
SnapshotSubject,
|
|
13
|
+
)
|
|
14
|
+
from git_contribution_analyzer.domain.services.capability_rules import assess_capabilities
|
|
15
|
+
from git_contribution_analyzer.domain.services.contribution_clustering import (
|
|
16
|
+
cluster_contributions,
|
|
17
|
+
)
|
|
18
|
+
from git_contribution_analyzer.domain.services.contribution_rules import build_evidence
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def build_snapshot_subject(
|
|
22
|
+
person: dict[str, object],
|
|
23
|
+
commits: tuple[ContributionCommit, ...],
|
|
24
|
+
) -> SnapshotSubject:
|
|
25
|
+
items = cluster_contributions(tuple(commit for commit in commits if not commit.merge))
|
|
26
|
+
evidence = build_evidence(items)
|
|
27
|
+
capabilities = assess_capabilities(items, evidence)
|
|
28
|
+
return SnapshotSubject(
|
|
29
|
+
person=SnapshotPerson(
|
|
30
|
+
id=str(person["id"]),
|
|
31
|
+
name=str(person["name"]),
|
|
32
|
+
email=str(person["email"]),
|
|
33
|
+
kind=str(person["kind"]),
|
|
34
|
+
confirmed=bool(person["confirmed"]),
|
|
35
|
+
),
|
|
36
|
+
commits=commits,
|
|
37
|
+
contribution_items=items,
|
|
38
|
+
evidence=evidence,
|
|
39
|
+
capabilities=capabilities,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def build_evidence_snapshot(
|
|
44
|
+
*,
|
|
45
|
+
repository_root: Path,
|
|
46
|
+
baseline_commit: str | None,
|
|
47
|
+
filters: AnalysisFilters,
|
|
48
|
+
scope_type: str,
|
|
49
|
+
subjects: tuple[SnapshotSubject, ...],
|
|
50
|
+
identity_warnings: tuple[str, ...],
|
|
51
|
+
created_at: datetime,
|
|
52
|
+
) -> EvidenceSnapshot:
|
|
53
|
+
resolved_root = repository_root.resolve()
|
|
54
|
+
return EvidenceSnapshot.create(
|
|
55
|
+
repository_id=str(uuid5(NAMESPACE_URL, resolved_root.as_uri())),
|
|
56
|
+
repository_root=str(resolved_root),
|
|
57
|
+
baseline_commit=baseline_commit,
|
|
58
|
+
filters=filters,
|
|
59
|
+
scope_type=scope_type,
|
|
60
|
+
subjects=subjects,
|
|
61
|
+
identity_warnings=identity_warnings,
|
|
62
|
+
rule_versions=(("evidence", "rules-v1"),),
|
|
63
|
+
created_at=created_at,
|
|
64
|
+
)
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, Protocol
|
|
4
|
+
|
|
5
|
+
from git_contribution_analyzer.domain.errors import IdentityResolutionError
|
|
6
|
+
from git_contribution_analyzer.domain.models.person_selection import (
|
|
7
|
+
PersonExclusion,
|
|
8
|
+
PersonSelection,
|
|
9
|
+
SelectionMode,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class PersonSelectionStore(Protocol):
|
|
14
|
+
def resolve_people(
|
|
15
|
+
self, selectors: tuple[str, ...], *, require_confirmed: bool
|
|
16
|
+
) -> list[dict[str, Any]]: ...
|
|
17
|
+
|
|
18
|
+
def list_people_for_analysis(self) -> list[dict[str, Any]]: ...
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def select_people(
|
|
22
|
+
store: PersonSelectionStore,
|
|
23
|
+
*,
|
|
24
|
+
person_selectors: tuple[str, ...],
|
|
25
|
+
all_people: bool,
|
|
26
|
+
exclude_selectors: tuple[str, ...],
|
|
27
|
+
) -> tuple[tuple[dict[str, Any], ...], PersonSelection]:
|
|
28
|
+
if all_people:
|
|
29
|
+
return _select_all(store, exclude_selectors)
|
|
30
|
+
people = store.resolve_people(person_selectors, require_confirmed=True)
|
|
31
|
+
_reject_duplicate_people(people)
|
|
32
|
+
for person in people:
|
|
33
|
+
if str(person["kind"]) != "HUMAN":
|
|
34
|
+
raise IdentityResolutionError(
|
|
35
|
+
f"Person is not eligible for assessment: {person['name']} ({person['kind']})"
|
|
36
|
+
)
|
|
37
|
+
ordered = tuple(sorted(people, key=lambda value: str(value["id"])))
|
|
38
|
+
return ordered, PersonSelection(
|
|
39
|
+
mode=SelectionMode.EXPLICIT,
|
|
40
|
+
requested_selectors=person_selectors,
|
|
41
|
+
included_person_ids=tuple(str(person["id"]) for person in ordered),
|
|
42
|
+
exclusions=(),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _select_all(
|
|
47
|
+
store: PersonSelectionStore,
|
|
48
|
+
exclude_selectors: tuple[str, ...],
|
|
49
|
+
) -> tuple[tuple[dict[str, Any], ...], PersonSelection]:
|
|
50
|
+
all_people = store.list_people_for_analysis()
|
|
51
|
+
exclusions: list[PersonExclusion] = []
|
|
52
|
+
eligible: dict[str, dict[str, Any]] = {}
|
|
53
|
+
for person in sorted(all_people, key=lambda value: str(value["id"])):
|
|
54
|
+
person_id = str(person["id"])
|
|
55
|
+
if not bool(person["confirmed"]):
|
|
56
|
+
exclusions.append(PersonExclusion(None, person_id, "UNCONFIRMED"))
|
|
57
|
+
elif str(person["kind"]) != "HUMAN":
|
|
58
|
+
exclusions.append(PersonExclusion(None, person_id, "KIND_NOT_ALLOWED"))
|
|
59
|
+
else:
|
|
60
|
+
eligible[person_id] = person
|
|
61
|
+
|
|
62
|
+
explicitly_excluded = store.resolve_people(
|
|
63
|
+
exclude_selectors, require_confirmed=False
|
|
64
|
+
)
|
|
65
|
+
_reject_duplicate_people(explicitly_excluded)
|
|
66
|
+
for selector, person in zip(exclude_selectors, explicitly_excluded, strict=True):
|
|
67
|
+
person_id = str(person["id"])
|
|
68
|
+
if person_id in eligible:
|
|
69
|
+
eligible.pop(person_id)
|
|
70
|
+
exclusions.append(
|
|
71
|
+
PersonExclusion(selector, person_id, "EXPLICITLY_EXCLUDED")
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
if not eligible:
|
|
75
|
+
raise IdentityResolutionError("Selection contains no people eligible for assessment")
|
|
76
|
+
ordered = tuple(eligible[person_id] for person_id in sorted(eligible))
|
|
77
|
+
return ordered, PersonSelection(
|
|
78
|
+
mode=SelectionMode.ALL,
|
|
79
|
+
requested_selectors=(),
|
|
80
|
+
included_person_ids=tuple(str(person["id"]) for person in ordered),
|
|
81
|
+
exclusions=tuple(exclusions),
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _reject_duplicate_people(people: list[dict[str, Any]]) -> None:
|
|
86
|
+
person_ids = [str(person["id"]) for person in people]
|
|
87
|
+
if len(person_ids) != len(set(person_ids)):
|
|
88
|
+
raise IdentityResolutionError("Multiple selectors resolve to the same person")
|