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,602 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections import Counter
|
|
4
|
+
from collections.abc import Callable
|
|
5
|
+
from datetime import UTC, datetime
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
from uuid import uuid4
|
|
9
|
+
|
|
10
|
+
from git_contribution_analyzer.adapters.git.native_git import NativeGitHistory
|
|
11
|
+
from git_contribution_analyzer.adapters.git.repository_discovery import discover_repository
|
|
12
|
+
from git_contribution_analyzer.adapters.llm.cache import CachedAuditedProvider
|
|
13
|
+
from git_contribution_analyzer.adapters.storage.sqlite.analysis import SqliteAnalysisStore
|
|
14
|
+
from git_contribution_analyzer.adapters.storage.sqlite.database import initialize_database
|
|
15
|
+
from git_contribution_analyzer.adapters.storage.sqlite.llm_audit import SqliteLlmAuditStore
|
|
16
|
+
from git_contribution_analyzer.adapters.workspace.config import load_config
|
|
17
|
+
from git_contribution_analyzer.adapters.workspace.layout import WorkspaceLayout
|
|
18
|
+
from git_contribution_analyzer.adapters.workspace.locks import workspace_lock
|
|
19
|
+
from git_contribution_analyzer.application.ports.cancellation import (
|
|
20
|
+
CancellationToken,
|
|
21
|
+
NeverCancelledToken,
|
|
22
|
+
OperationCancelled,
|
|
23
|
+
)
|
|
24
|
+
from git_contribution_analyzer.application.ports.llm import LlmProvider
|
|
25
|
+
from git_contribution_analyzer.application.ports.progress import (
|
|
26
|
+
NullProgressReporter,
|
|
27
|
+
ProgressEvent,
|
|
28
|
+
ProgressReporter,
|
|
29
|
+
)
|
|
30
|
+
from git_contribution_analyzer.application.services.assessment_explanation import (
|
|
31
|
+
explain_assessment,
|
|
32
|
+
)
|
|
33
|
+
from git_contribution_analyzer.application.services.evidence_snapshot import (
|
|
34
|
+
build_evidence_snapshot,
|
|
35
|
+
build_snapshot_subject,
|
|
36
|
+
)
|
|
37
|
+
from git_contribution_analyzer.application.services.person_selection import select_people
|
|
38
|
+
from git_contribution_analyzer.application.use_cases.analyze_contributions import _branch_hashes
|
|
39
|
+
from git_contribution_analyzer.domain.errors import LlmProviderError
|
|
40
|
+
from git_contribution_analyzer.domain.models.analysis import AnalysisFilters
|
|
41
|
+
from git_contribution_analyzer.domain.models.person_selection import PersonSelection
|
|
42
|
+
from git_contribution_analyzer.domain.models.ranking import RankingConfig
|
|
43
|
+
from git_contribution_analyzer.domain.models.run import RunType
|
|
44
|
+
from git_contribution_analyzer.domain.models.snapshot import EvidenceSnapshot, SnapshotSubject
|
|
45
|
+
from git_contribution_analyzer.domain.models.work_assessment import (
|
|
46
|
+
CompletionBucket,
|
|
47
|
+
DifficultyLevel,
|
|
48
|
+
SizeBand,
|
|
49
|
+
WorkItemAssessment,
|
|
50
|
+
WorkloadBaseline,
|
|
51
|
+
)
|
|
52
|
+
from git_contribution_analyzer.domain.services.difficulty_rules import assess_difficulty
|
|
53
|
+
from git_contribution_analyzer.domain.services.ranking_rules import build_ranking
|
|
54
|
+
from git_contribution_analyzer.domain.services.workload_rules import (
|
|
55
|
+
assess_item_size,
|
|
56
|
+
build_workload_baseline,
|
|
57
|
+
classify_completion,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
Clock = Callable[[], datetime]
|
|
61
|
+
IdGenerator = Callable[[], str]
|
|
62
|
+
SUPPORTED_TIME_BASES = ("AUTHORED", "COMMITTED", "MERGED", "LANDED", "RELEASED")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def assess_work(
|
|
66
|
+
path: Path,
|
|
67
|
+
*,
|
|
68
|
+
person_selectors: tuple[str, ...] = (),
|
|
69
|
+
all_people: bool = False,
|
|
70
|
+
exclude_selectors: tuple[str, ...] = (),
|
|
71
|
+
rank_by: tuple[str, ...] = (),
|
|
72
|
+
ranking_config: RankingConfig | None = None,
|
|
73
|
+
filters: AnalysisFilters | None = None,
|
|
74
|
+
clock: Clock | None = None,
|
|
75
|
+
id_generator: IdGenerator | None = None,
|
|
76
|
+
llm_provider: LlmProvider | None = None,
|
|
77
|
+
allow_llm_fallback: bool = True,
|
|
78
|
+
workload_baseline: WorkloadBaseline | None = None,
|
|
79
|
+
integration_times: dict[str, tuple[datetime, datetime | None]] | None = None,
|
|
80
|
+
release_times: dict[str, datetime] | None = None,
|
|
81
|
+
progress: ProgressReporter | None = None,
|
|
82
|
+
cancellation: CancellationToken | None = None,
|
|
83
|
+
) -> dict[str, Any]:
|
|
84
|
+
active_progress = progress or NullProgressReporter()
|
|
85
|
+
active_cancellation = cancellation or NeverCancelledToken()
|
|
86
|
+
active_cancellation.raise_if_cancelled()
|
|
87
|
+
repository = discover_repository(path)
|
|
88
|
+
layout = WorkspaceLayout.for_repository(repository.root)
|
|
89
|
+
initialize_database(layout.database)
|
|
90
|
+
store = SqliteAnalysisStore(layout.database, str(repository.root))
|
|
91
|
+
active_filters = filters or AnalysisFilters()
|
|
92
|
+
if active_filters.time_basis not in SUPPORTED_TIME_BASES:
|
|
93
|
+
raise ValueError(f"Unsupported assessment time basis: {active_filters.time_basis}")
|
|
94
|
+
now = clock or (lambda: datetime.now(UTC))
|
|
95
|
+
next_id = id_generator or (lambda: str(uuid4()))
|
|
96
|
+
run_id = next_id()
|
|
97
|
+
started_at = now()
|
|
98
|
+
active_progress.report(
|
|
99
|
+
ProgressEvent(
|
|
100
|
+
task_id=run_id,
|
|
101
|
+
operation="assess",
|
|
102
|
+
stage="discovering_repository",
|
|
103
|
+
repository=repository.root,
|
|
104
|
+
message="Repository discovered",
|
|
105
|
+
occurred_at=started_at,
|
|
106
|
+
)
|
|
107
|
+
)
|
|
108
|
+
baseline = store.baseline_commit()
|
|
109
|
+
allowed_hashes = _branch_hashes(repository.root, active_filters.branch)
|
|
110
|
+
history = NativeGitHistory(repository.root)
|
|
111
|
+
config = load_config(layout.config)
|
|
112
|
+
active_integration_times = (
|
|
113
|
+
integration_times
|
|
114
|
+
if integration_times is not None
|
|
115
|
+
else (
|
|
116
|
+
history.integration_times(f"refs/heads/{config.default_branch}")
|
|
117
|
+
if active_filters.time_basis in {"MERGED", "LANDED"}
|
|
118
|
+
else {}
|
|
119
|
+
)
|
|
120
|
+
)
|
|
121
|
+
active_release_times = (
|
|
122
|
+
release_times
|
|
123
|
+
if release_times is not None
|
|
124
|
+
else (history.release_times() if active_filters.time_basis == "RELEASED" else {})
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
with workspace_lock(layout.locks / "workspace.lock"):
|
|
128
|
+
active_cancellation.raise_if_cancelled()
|
|
129
|
+
active_progress.report(
|
|
130
|
+
ProgressEvent(
|
|
131
|
+
task_id=run_id,
|
|
132
|
+
operation="assess",
|
|
133
|
+
stage="selecting_people",
|
|
134
|
+
repository=repository.root,
|
|
135
|
+
message="Selecting people",
|
|
136
|
+
occurred_at=now(),
|
|
137
|
+
)
|
|
138
|
+
)
|
|
139
|
+
people, selection = select_people(
|
|
140
|
+
store,
|
|
141
|
+
person_selectors=person_selectors,
|
|
142
|
+
all_people=all_people,
|
|
143
|
+
exclude_selectors=exclude_selectors,
|
|
144
|
+
)
|
|
145
|
+
subjects, identity_warnings = _load_subjects(
|
|
146
|
+
store,
|
|
147
|
+
active_filters,
|
|
148
|
+
allowed_hashes,
|
|
149
|
+
people=people,
|
|
150
|
+
integration_times=active_integration_times,
|
|
151
|
+
release_times=active_release_times,
|
|
152
|
+
)
|
|
153
|
+
scope_type = "PROJECT" if all_people or len(subjects) > 1 else "PERSON"
|
|
154
|
+
snapshot = build_evidence_snapshot(
|
|
155
|
+
repository_root=repository.root,
|
|
156
|
+
baseline_commit=baseline,
|
|
157
|
+
filters=active_filters,
|
|
158
|
+
scope_type=scope_type,
|
|
159
|
+
subjects=subjects,
|
|
160
|
+
identity_warnings=identity_warnings,
|
|
161
|
+
created_at=started_at,
|
|
162
|
+
)
|
|
163
|
+
person_id = snapshot.subjects[0].person.id if scope_type == "PERSON" else None
|
|
164
|
+
store.start_run(
|
|
165
|
+
run_id=run_id,
|
|
166
|
+
person_id=person_id,
|
|
167
|
+
parameters={
|
|
168
|
+
"persons": list(person_selectors),
|
|
169
|
+
"all": all_people,
|
|
170
|
+
"excludePersons": list(exclude_selectors),
|
|
171
|
+
"selection": selection.as_dict(),
|
|
172
|
+
"rankBy": list(rank_by),
|
|
173
|
+
"rankingConfig": (ranking_config.as_dict() if ranking_config is not None else None),
|
|
174
|
+
"filters": active_filters.as_dict(),
|
|
175
|
+
"llm": llm_provider is not None,
|
|
176
|
+
},
|
|
177
|
+
baseline_commit=baseline,
|
|
178
|
+
started_at=started_at,
|
|
179
|
+
run_type=RunType.WORK_ASSESSMENT,
|
|
180
|
+
)
|
|
181
|
+
try:
|
|
182
|
+
active_cancellation.raise_if_cancelled()
|
|
183
|
+
active_progress.report(
|
|
184
|
+
ProgressEvent(
|
|
185
|
+
task_id=run_id,
|
|
186
|
+
operation="assess",
|
|
187
|
+
stage="building_snapshot",
|
|
188
|
+
repository=repository.root,
|
|
189
|
+
message="Building assessment",
|
|
190
|
+
occurred_at=now(),
|
|
191
|
+
)
|
|
192
|
+
)
|
|
193
|
+
report = _build_assessment_report(
|
|
194
|
+
run_id,
|
|
195
|
+
started_at,
|
|
196
|
+
snapshot,
|
|
197
|
+
selection=selection,
|
|
198
|
+
rank_by=rank_by,
|
|
199
|
+
ranking_config=ranking_config,
|
|
200
|
+
workload_baseline=workload_baseline,
|
|
201
|
+
)
|
|
202
|
+
status = "COMPLETED"
|
|
203
|
+
provider_id = "none"
|
|
204
|
+
if llm_provider is not None:
|
|
205
|
+
active_cancellation.raise_if_cancelled()
|
|
206
|
+
active_progress.report(
|
|
207
|
+
ProgressEvent(
|
|
208
|
+
task_id=run_id,
|
|
209
|
+
operation="assess",
|
|
210
|
+
stage="calling_provider",
|
|
211
|
+
repository=repository.root,
|
|
212
|
+
message="Requesting optional explanation",
|
|
213
|
+
occurred_at=now(),
|
|
214
|
+
)
|
|
215
|
+
)
|
|
216
|
+
provider_id = llm_provider.provider_id
|
|
217
|
+
if not any(subject.evidence for subject in snapshot.subjects):
|
|
218
|
+
report["warnings"].append(
|
|
219
|
+
"LLM assessment explanation skipped: no Evidence available."
|
|
220
|
+
)
|
|
221
|
+
else:
|
|
222
|
+
audited_provider = CachedAuditedProvider(
|
|
223
|
+
llm_provider,
|
|
224
|
+
SqliteLlmAuditStore(layout.database),
|
|
225
|
+
run_id=run_id,
|
|
226
|
+
)
|
|
227
|
+
try:
|
|
228
|
+
enhancement = explain_assessment(report, snapshot, audited_provider)
|
|
229
|
+
report["explanation"] = enhancement.explanation
|
|
230
|
+
report["run"].update(
|
|
231
|
+
{
|
|
232
|
+
"providerId": enhancement.completion.provider_id,
|
|
233
|
+
"model": enhancement.completion.model,
|
|
234
|
+
"promptVersion": enhancement.task.prompt_version,
|
|
235
|
+
"semanticSchemaVersion": enhancement.task.schema_version,
|
|
236
|
+
}
|
|
237
|
+
)
|
|
238
|
+
except LlmProviderError as exc:
|
|
239
|
+
if not allow_llm_fallback:
|
|
240
|
+
raise
|
|
241
|
+
status = "PARTIAL"
|
|
242
|
+
report["warnings"].append(
|
|
243
|
+
f"LLM assessment explanation unavailable ({exc.code}); "
|
|
244
|
+
"deterministic assessment retained."
|
|
245
|
+
)
|
|
246
|
+
report["run"]["providerId"] = provider_id
|
|
247
|
+
report["run"]["status"] = status
|
|
248
|
+
active_cancellation.raise_if_cancelled()
|
|
249
|
+
completed_at = now()
|
|
250
|
+
report["run"]["completedAt"] = completed_at.isoformat()
|
|
251
|
+
store.complete_run(
|
|
252
|
+
run_id=run_id,
|
|
253
|
+
completed_at=completed_at,
|
|
254
|
+
report=report,
|
|
255
|
+
status=status,
|
|
256
|
+
provider_id=provider_id,
|
|
257
|
+
persist_details=False,
|
|
258
|
+
)
|
|
259
|
+
active_progress.report(
|
|
260
|
+
ProgressEvent(
|
|
261
|
+
task_id=run_id,
|
|
262
|
+
operation="assess",
|
|
263
|
+
stage="completed",
|
|
264
|
+
repository=repository.root,
|
|
265
|
+
current=1,
|
|
266
|
+
total=1,
|
|
267
|
+
message="Assessment completed",
|
|
268
|
+
occurred_at=completed_at,
|
|
269
|
+
)
|
|
270
|
+
)
|
|
271
|
+
return report
|
|
272
|
+
except OperationCancelled:
|
|
273
|
+
store.cancel_run(run_id, now())
|
|
274
|
+
raise
|
|
275
|
+
except Exception as exc:
|
|
276
|
+
store.fail_run(run_id, now(), str(exc))
|
|
277
|
+
raise
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def _load_subjects(
|
|
281
|
+
store: SqliteAnalysisStore,
|
|
282
|
+
filters: AnalysisFilters,
|
|
283
|
+
allowed_hashes: set[str] | None,
|
|
284
|
+
*,
|
|
285
|
+
people: tuple[dict[str, Any], ...],
|
|
286
|
+
integration_times: dict[str, tuple[datetime, datetime | None]],
|
|
287
|
+
release_times: dict[str, datetime],
|
|
288
|
+
) -> tuple[tuple[SnapshotSubject, ...], tuple[str, ...]]:
|
|
289
|
+
subjects: list[SnapshotSubject] = []
|
|
290
|
+
warnings: list[str] = []
|
|
291
|
+
for person in people:
|
|
292
|
+
commits = store.load_commits(
|
|
293
|
+
str(person["id"]),
|
|
294
|
+
filters,
|
|
295
|
+
allowed_hashes=allowed_hashes,
|
|
296
|
+
integration_times=integration_times,
|
|
297
|
+
release_times=release_times,
|
|
298
|
+
)
|
|
299
|
+
subjects.append(build_snapshot_subject(person, commits))
|
|
300
|
+
if not bool(person["confirmed"]):
|
|
301
|
+
warnings.append(f"Unconfirmed identity: {person['name']} ({person['id']}).")
|
|
302
|
+
return tuple(subjects), tuple(warnings)
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def _build_assessment_report(
|
|
306
|
+
run_id: str,
|
|
307
|
+
started_at: datetime,
|
|
308
|
+
snapshot: EvidenceSnapshot,
|
|
309
|
+
*,
|
|
310
|
+
selection: PersonSelection,
|
|
311
|
+
rank_by: tuple[str, ...],
|
|
312
|
+
ranking_config: RankingConfig | None,
|
|
313
|
+
workload_baseline: WorkloadBaseline | None = None,
|
|
314
|
+
) -> dict[str, Any]:
|
|
315
|
+
completed_items = tuple(
|
|
316
|
+
item
|
|
317
|
+
for subject in snapshot.subjects
|
|
318
|
+
for item in subject.contribution_items
|
|
319
|
+
if classify_completion(item) is CompletionBucket.COMPLETED
|
|
320
|
+
)
|
|
321
|
+
active_workload_baseline = workload_baseline or build_workload_baseline(completed_items)
|
|
322
|
+
serialized_subjects = [
|
|
323
|
+
_serialize_subject(subject, active_workload_baseline) for subject in snapshot.subjects
|
|
324
|
+
]
|
|
325
|
+
assessments = [
|
|
326
|
+
assessment for subject in serialized_subjects for assessment in subject["itemAssessments"]
|
|
327
|
+
]
|
|
328
|
+
completed = [
|
|
329
|
+
assessment
|
|
330
|
+
for assessment in assessments
|
|
331
|
+
if assessment["completionBucket"] == CompletionBucket.COMPLETED.value
|
|
332
|
+
]
|
|
333
|
+
modules = Counter(
|
|
334
|
+
module
|
|
335
|
+
for subject in snapshot.subjects
|
|
336
|
+
for item in subject.contribution_items
|
|
337
|
+
if classify_completion(item) is CompletionBucket.COMPLETED
|
|
338
|
+
for module in item.modules
|
|
339
|
+
)
|
|
340
|
+
work_types = Counter(entry["workType"] for entry in completed)
|
|
341
|
+
domains = Counter(
|
|
342
|
+
item.group_key.split(":", maxsplit=1)[0]
|
|
343
|
+
for subject in snapshot.subjects
|
|
344
|
+
for item in subject.contribution_items
|
|
345
|
+
if classify_completion(item) is CompletionBucket.COMPLETED
|
|
346
|
+
)
|
|
347
|
+
return {
|
|
348
|
+
"schemaVersion": "2.0",
|
|
349
|
+
"reportType": "WORK_ASSESSMENT",
|
|
350
|
+
"scopeType": snapshot.scope_type,
|
|
351
|
+
"run": {
|
|
352
|
+
"id": run_id,
|
|
353
|
+
"runType": RunType.WORK_ASSESSMENT.value,
|
|
354
|
+
"parentRunId": None,
|
|
355
|
+
"status": "COMPLETED",
|
|
356
|
+
"startedAt": started_at.isoformat(),
|
|
357
|
+
"completedAt": started_at.isoformat(),
|
|
358
|
+
"ruleVersion": "work-assessment-v2",
|
|
359
|
+
"providerId": "none",
|
|
360
|
+
"model": None,
|
|
361
|
+
"promptVersion": None,
|
|
362
|
+
"semanticSchemaVersion": None,
|
|
363
|
+
},
|
|
364
|
+
"snapshot": snapshot.as_reference(),
|
|
365
|
+
"selection": selection.as_dict(),
|
|
366
|
+
"ranking": build_ranking(
|
|
367
|
+
serialized_subjects,
|
|
368
|
+
rank_by,
|
|
369
|
+
snapshot_id=snapshot.id,
|
|
370
|
+
config=ranking_config,
|
|
371
|
+
),
|
|
372
|
+
"subjects": serialized_subjects,
|
|
373
|
+
"workloadSummary": {
|
|
374
|
+
"completedItems": len(completed),
|
|
375
|
+
"pendingItems": sum(
|
|
376
|
+
entry["completionBucket"] == CompletionBucket.PENDING.value for entry in assessments
|
|
377
|
+
),
|
|
378
|
+
"reworkItems": sum(
|
|
379
|
+
entry["completionBucket"] == CompletionBucket.REWORK.value for entry in assessments
|
|
380
|
+
),
|
|
381
|
+
"integrationItems": sum(
|
|
382
|
+
len(subject["integrationWork"]) for subject in serialized_subjects
|
|
383
|
+
),
|
|
384
|
+
"sizeDistribution": _distribution(completed, "size", "band", SizeBand),
|
|
385
|
+
},
|
|
386
|
+
"difficultyDistribution": _distribution(completed, "difficulty", "level", DifficultyLevel),
|
|
387
|
+
"technicalSummary": {
|
|
388
|
+
"headline": (
|
|
389
|
+
f"Completed work spans {len(modules)} technical modules and "
|
|
390
|
+
f"{len(work_types)} change types."
|
|
391
|
+
),
|
|
392
|
+
"modules": [
|
|
393
|
+
{"name": name, "items": count}
|
|
394
|
+
for name, count in sorted(modules.items(), key=lambda value: (-value[1], value[0]))
|
|
395
|
+
],
|
|
396
|
+
"workTypes": dict(sorted(work_types.items())),
|
|
397
|
+
},
|
|
398
|
+
"businessSummary": {
|
|
399
|
+
"headline": f"Completed work covers {len(domains)} evidence-derived domains.",
|
|
400
|
+
"domains": [
|
|
401
|
+
{"name": name, "items": count}
|
|
402
|
+
for name, count in sorted(domains.items(), key=lambda value: (-value[1], value[0]))
|
|
403
|
+
],
|
|
404
|
+
},
|
|
405
|
+
"evidence": [
|
|
406
|
+
{
|
|
407
|
+
"personId": subject.person.id,
|
|
408
|
+
"id": entry.id,
|
|
409
|
+
"type": entry.evidence_type,
|
|
410
|
+
"summary": entry.summary,
|
|
411
|
+
"commitHashes": list(entry.commit_hashes),
|
|
412
|
+
"paths": list(entry.paths),
|
|
413
|
+
"metrics": dict(entry.metrics),
|
|
414
|
+
}
|
|
415
|
+
for subject in snapshot.subjects
|
|
416
|
+
for entry in subject.evidence
|
|
417
|
+
],
|
|
418
|
+
"explanation": None,
|
|
419
|
+
"identityWarnings": list(snapshot.identity_warnings),
|
|
420
|
+
"warnings": [],
|
|
421
|
+
"limitations": [
|
|
422
|
+
"Work size describes effective change scope, not time spent or employee value.",
|
|
423
|
+
"Difficulty is a versioned rules inference and must be reviewed with "
|
|
424
|
+
"its evidence gaps.",
|
|
425
|
+
"Git evidence does not prove business outcomes, sole ownership, or working hours.",
|
|
426
|
+
],
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
def build_assessment_workload_baseline(
|
|
431
|
+
path: Path,
|
|
432
|
+
*,
|
|
433
|
+
person_selectors: tuple[str, ...] = (),
|
|
434
|
+
all_people: bool = False,
|
|
435
|
+
exclude_selectors: tuple[str, ...] = (),
|
|
436
|
+
filters: AnalysisFilters,
|
|
437
|
+
integration_times: dict[str, tuple[datetime, datetime | None]] | None = None,
|
|
438
|
+
release_times: dict[str, datetime] | None = None,
|
|
439
|
+
) -> WorkloadBaseline:
|
|
440
|
+
repository = discover_repository(path)
|
|
441
|
+
layout = WorkspaceLayout.for_repository(repository.root)
|
|
442
|
+
initialize_database(layout.database)
|
|
443
|
+
store = SqliteAnalysisStore(layout.database, str(repository.root))
|
|
444
|
+
if filters.time_basis not in SUPPORTED_TIME_BASES:
|
|
445
|
+
raise ValueError(f"Unsupported assessment time basis: {filters.time_basis}")
|
|
446
|
+
history = NativeGitHistory(repository.root)
|
|
447
|
+
config = load_config(layout.config)
|
|
448
|
+
active_integration_times = (
|
|
449
|
+
integration_times
|
|
450
|
+
if integration_times is not None
|
|
451
|
+
else (
|
|
452
|
+
history.integration_times(f"refs/heads/{config.default_branch}")
|
|
453
|
+
if filters.time_basis in {"MERGED", "LANDED"}
|
|
454
|
+
else {}
|
|
455
|
+
)
|
|
456
|
+
)
|
|
457
|
+
active_release_times = (
|
|
458
|
+
release_times
|
|
459
|
+
if release_times is not None
|
|
460
|
+
else (history.release_times() if filters.time_basis == "RELEASED" else {})
|
|
461
|
+
)
|
|
462
|
+
people, _selection = select_people(
|
|
463
|
+
store,
|
|
464
|
+
person_selectors=person_selectors,
|
|
465
|
+
all_people=all_people,
|
|
466
|
+
exclude_selectors=exclude_selectors,
|
|
467
|
+
)
|
|
468
|
+
subjects, _warnings = _load_subjects(
|
|
469
|
+
store,
|
|
470
|
+
filters,
|
|
471
|
+
_branch_hashes(repository.root, filters.branch),
|
|
472
|
+
people=people,
|
|
473
|
+
integration_times=active_integration_times,
|
|
474
|
+
release_times=active_release_times,
|
|
475
|
+
)
|
|
476
|
+
completed_items = tuple(
|
|
477
|
+
item
|
|
478
|
+
for subject in subjects
|
|
479
|
+
for item in subject.contribution_items
|
|
480
|
+
if classify_completion(item) is CompletionBucket.COMPLETED
|
|
481
|
+
)
|
|
482
|
+
return build_workload_baseline(completed_items)
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
def _serialize_subject(
|
|
486
|
+
subject: SnapshotSubject, workload_baseline: WorkloadBaseline
|
|
487
|
+
) -> dict[str, Any]:
|
|
488
|
+
item_assessments = [
|
|
489
|
+
_assess_item(subject.person.id, item, workload_baseline)
|
|
490
|
+
for item in subject.contribution_items
|
|
491
|
+
]
|
|
492
|
+
return {
|
|
493
|
+
"person": {
|
|
494
|
+
"id": subject.person.id,
|
|
495
|
+
"name": subject.person.name,
|
|
496
|
+
"email": subject.person.email,
|
|
497
|
+
"kind": subject.person.kind,
|
|
498
|
+
"confirmed": subject.person.confirmed,
|
|
499
|
+
},
|
|
500
|
+
"completedWork": _ids_for_bucket(item_assessments, CompletionBucket.COMPLETED),
|
|
501
|
+
"pendingWork": _ids_for_bucket(item_assessments, CompletionBucket.PENDING),
|
|
502
|
+
"rework": _ids_for_bucket(item_assessments, CompletionBucket.REWORK),
|
|
503
|
+
"integrationWork": [
|
|
504
|
+
{"commitHash": commit.hash, "subject": commit.subject}
|
|
505
|
+
for commit in subject.commits
|
|
506
|
+
if commit.merge
|
|
507
|
+
],
|
|
508
|
+
"itemAssessments": [_serialize_item_assessment(value) for value in item_assessments],
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
def _assess_item(
|
|
513
|
+
person_id: str,
|
|
514
|
+
item: Any,
|
|
515
|
+
workload_baseline: WorkloadBaseline,
|
|
516
|
+
) -> WorkItemAssessment:
|
|
517
|
+
completion = classify_completion(item)
|
|
518
|
+
work_types = sorted({commit.commit_type for commit in item.commits})
|
|
519
|
+
paths = set(item.paths)
|
|
520
|
+
support = tuple(
|
|
521
|
+
name
|
|
522
|
+
for name, present in (
|
|
523
|
+
("TEST", any("test" in path.casefold() for path in paths)),
|
|
524
|
+
("DOCUMENTATION", any(path.casefold().endswith(".md") for path in paths)),
|
|
525
|
+
("MIGRATION", any("migration" in path.casefold() for path in paths)),
|
|
526
|
+
(
|
|
527
|
+
"CONFIGURATION",
|
|
528
|
+
any(path.casefold().endswith((".yml", ".yaml", ".toml")) for path in paths),
|
|
529
|
+
),
|
|
530
|
+
)
|
|
531
|
+
if present
|
|
532
|
+
)
|
|
533
|
+
return WorkItemAssessment(
|
|
534
|
+
contribution_item_id=item.id,
|
|
535
|
+
person_id=person_id,
|
|
536
|
+
completion_bucket=completion,
|
|
537
|
+
delivery_statuses=tuple(sorted({commit.delivery_status for commit in item.commits})),
|
|
538
|
+
work_type=work_types[0] if len(work_types) == 1 else "MIXED",
|
|
539
|
+
size=assess_item_size(item, baseline=workload_baseline),
|
|
540
|
+
difficulty=assess_difficulty(item),
|
|
541
|
+
engineering_support=support,
|
|
542
|
+
evidence_ids=item.evidence_ids,
|
|
543
|
+
)
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
def _serialize_item_assessment(value: WorkItemAssessment) -> dict[str, Any]:
|
|
547
|
+
return {
|
|
548
|
+
"contributionItemId": value.contribution_item_id,
|
|
549
|
+
"personId": value.person_id,
|
|
550
|
+
"completionBucket": value.completion_bucket.value,
|
|
551
|
+
"deliveryStatuses": list(value.delivery_statuses),
|
|
552
|
+
"workType": value.work_type,
|
|
553
|
+
"size": {
|
|
554
|
+
"band": value.size.band.value,
|
|
555
|
+
"effectiveFiles": value.size.effective_files,
|
|
556
|
+
"effectiveChurn": value.size.effective_churn,
|
|
557
|
+
"moduleSpan": value.size.module_span,
|
|
558
|
+
"baselineSampleSize": value.size.baseline_sample_size,
|
|
559
|
+
"baselineMode": value.size.baseline_mode,
|
|
560
|
+
"ruleVersion": value.size.rule_version,
|
|
561
|
+
"evidenceIds": list(value.size.evidence_ids),
|
|
562
|
+
"excludedChanges": list(value.size.excluded_changes),
|
|
563
|
+
"confidence": value.size.confidence,
|
|
564
|
+
"gaps": list(value.size.gaps),
|
|
565
|
+
},
|
|
566
|
+
"difficulty": {
|
|
567
|
+
"level": value.difficulty.level.value,
|
|
568
|
+
"dimensionSignals": [
|
|
569
|
+
{
|
|
570
|
+
"dimension": signal.dimension,
|
|
571
|
+
"code": signal.code,
|
|
572
|
+
"severity": signal.severity,
|
|
573
|
+
"description": signal.description,
|
|
574
|
+
"evidenceIds": list(signal.evidence_ids),
|
|
575
|
+
}
|
|
576
|
+
for signal in value.difficulty.dimension_signals
|
|
577
|
+
],
|
|
578
|
+
"ruleVersion": value.difficulty.rule_version,
|
|
579
|
+
"evidenceIds": list(value.difficulty.evidence_ids),
|
|
580
|
+
"confidence": value.difficulty.confidence,
|
|
581
|
+
"gaps": list(value.difficulty.gaps),
|
|
582
|
+
},
|
|
583
|
+
"engineeringSupport": list(value.engineering_support),
|
|
584
|
+
"evidenceIds": list(value.evidence_ids),
|
|
585
|
+
"warnings": list(value.warnings),
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
def _ids_for_bucket(assessments: list[WorkItemAssessment], bucket: CompletionBucket) -> list[str]:
|
|
590
|
+
return [
|
|
591
|
+
value.contribution_item_id for value in assessments if value.completion_bucket is bucket
|
|
592
|
+
]
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
def _distribution(
|
|
596
|
+
entries: list[dict[str, Any]],
|
|
597
|
+
group: str,
|
|
598
|
+
field: str,
|
|
599
|
+
values: type[SizeBand] | type[DifficultyLevel],
|
|
600
|
+
) -> dict[str, int]:
|
|
601
|
+
counts = Counter(entry[group][field] for entry in entries)
|
|
602
|
+
return {value.value: counts[value.value] for value in values}
|