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,318 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from collections import Counter
|
|
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.resume import (
|
|
18
|
+
ClaimStrength,
|
|
19
|
+
OmittedClaim,
|
|
20
|
+
ResumeClaim,
|
|
21
|
+
ResumeLanguage,
|
|
22
|
+
ResumeStyle,
|
|
23
|
+
SkillEvidence,
|
|
24
|
+
VerifiedOutcome,
|
|
25
|
+
)
|
|
26
|
+
from git_contribution_analyzer.domain.models.snapshot import EvidenceSnapshot, SnapshotSubject
|
|
27
|
+
from git_contribution_analyzer.domain.models.work_assessment import CompletionBucket
|
|
28
|
+
from git_contribution_analyzer.domain.services.resume_claim_rules import (
|
|
29
|
+
claim_strength_ceiling,
|
|
30
|
+
validate_resume_claim,
|
|
31
|
+
)
|
|
32
|
+
from git_contribution_analyzer.domain.services.workload_rules import classify_completion
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class _ResumeClaimOutput(BaseModel):
|
|
36
|
+
model_config = ConfigDict(extra="forbid", populate_by_name=True)
|
|
37
|
+
|
|
38
|
+
text: str = Field(min_length=1)
|
|
39
|
+
claim_strength: ClaimStrength = Field(alias="claimStrength")
|
|
40
|
+
contribution_item_ids: list[str] = Field(alias="contributionItemIds", min_length=1)
|
|
41
|
+
evidence_ids: list[str] = Field(alias="evidenceIds", min_length=1)
|
|
42
|
+
verified_outcome_ids: list[str] = Field(alias="verifiedOutcomeIds")
|
|
43
|
+
confidence: str
|
|
44
|
+
pending: bool = False
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class ResumeLlmOutput(BaseModel):
|
|
48
|
+
model_config = ConfigDict(extra="forbid", populate_by_name=True)
|
|
49
|
+
|
|
50
|
+
project_summary_candidates: list[_ResumeClaimOutput] = Field(
|
|
51
|
+
alias="projectSummaryCandidates"
|
|
52
|
+
)
|
|
53
|
+
experience_bullets: list[_ResumeClaimOutput] = Field(alias="experienceBullets")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@dataclass(frozen=True, slots=True)
|
|
57
|
+
class ResumeEnhancementResult:
|
|
58
|
+
content: dict[str, Any]
|
|
59
|
+
completion: LlmCompletion
|
|
60
|
+
task: LlmTask
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def enhance_resume(
|
|
64
|
+
*,
|
|
65
|
+
report: dict[str, Any],
|
|
66
|
+
snapshot: EvidenceSnapshot,
|
|
67
|
+
provider: LlmProvider,
|
|
68
|
+
outcomes: tuple[VerifiedOutcome, ...],
|
|
69
|
+
max_bullets: int,
|
|
70
|
+
) -> ResumeEnhancementResult:
|
|
71
|
+
task = build_resume_task(report, snapshot, outcomes, max_bullets)
|
|
72
|
+
completion = provider.complete(task)
|
|
73
|
+
try:
|
|
74
|
+
output = ResumeLlmOutput.model_validate(completion.content)
|
|
75
|
+
except ValidationError as exc:
|
|
76
|
+
raise LlmOutputError("LLM output does not match resume-v1 schema") from exc
|
|
77
|
+
allowed_items = {
|
|
78
|
+
item_id
|
|
79
|
+
for claim in report["experienceBullets"]
|
|
80
|
+
for item_id in claim["contributionItemIds"]
|
|
81
|
+
}
|
|
82
|
+
allowed_evidence = set(task.allowed_evidence_ids)
|
|
83
|
+
strength_ceilings = {
|
|
84
|
+
item_id: ClaimStrength(claim["claimStrength"])
|
|
85
|
+
for claim in report["experienceBullets"]
|
|
86
|
+
for item_id in claim["contributionItemIds"]
|
|
87
|
+
}
|
|
88
|
+
claims = [*output.project_summary_candidates, *output.experience_bullets]
|
|
89
|
+
for value in claims:
|
|
90
|
+
validate_resume_claim(
|
|
91
|
+
_to_domain_claim(value),
|
|
92
|
+
allowed_item_ids=allowed_items,
|
|
93
|
+
allowed_evidence_ids=allowed_evidence,
|
|
94
|
+
strength_ceilings=strength_ceilings,
|
|
95
|
+
outcomes=outcomes,
|
|
96
|
+
)
|
|
97
|
+
content = output.model_dump(by_alias=True, mode="json")
|
|
98
|
+
content["experienceBullets"] = content["experienceBullets"][:max_bullets]
|
|
99
|
+
return ResumeEnhancementResult(content=content, completion=completion, task=task)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def build_resume_task(
|
|
103
|
+
report: dict[str, Any],
|
|
104
|
+
snapshot: EvidenceSnapshot,
|
|
105
|
+
outcomes: tuple[VerifiedOutcome, ...],
|
|
106
|
+
max_bullets: int,
|
|
107
|
+
) -> LlmTask:
|
|
108
|
+
allowed_evidence_ids = tuple(
|
|
109
|
+
sorted(
|
|
110
|
+
{
|
|
111
|
+
evidence_id
|
|
112
|
+
for claim in report["experienceBullets"]
|
|
113
|
+
for evidence_id in claim["evidenceIds"]
|
|
114
|
+
}
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
context = {
|
|
118
|
+
"snapshotId": snapshot.id,
|
|
119
|
+
"person": report.get(
|
|
120
|
+
"person",
|
|
121
|
+
{
|
|
122
|
+
"id": snapshot.subjects[0].person.id,
|
|
123
|
+
"name": snapshot.subjects[0].person.name,
|
|
124
|
+
},
|
|
125
|
+
),
|
|
126
|
+
"targetRole": report.get("targetRole", ""),
|
|
127
|
+
"language": report.get("language", "zh-CN"),
|
|
128
|
+
"style": report.get("style", "concise"),
|
|
129
|
+
"maxBullets": max_bullets,
|
|
130
|
+
"allowedClaims": report["experienceBullets"],
|
|
131
|
+
"verifiedOutcomes": [
|
|
132
|
+
{
|
|
133
|
+
"id": outcome.id,
|
|
134
|
+
"text": outcome.text,
|
|
135
|
+
"source": outcome.source,
|
|
136
|
+
"verifiedBy": outcome.verified_by,
|
|
137
|
+
"verifiedAt": outcome.verified_at.isoformat(),
|
|
138
|
+
"kind": outcome.kind,
|
|
139
|
+
}
|
|
140
|
+
for outcome in outcomes
|
|
141
|
+
],
|
|
142
|
+
}
|
|
143
|
+
root = files("git_contribution_analyzer.prompts.resume.v1")
|
|
144
|
+
prompt = "\n\n".join(
|
|
145
|
+
(
|
|
146
|
+
root.joinpath("system.txt").read_text(encoding="utf-8").strip(),
|
|
147
|
+
root.joinpath(f"style-{context['style']}.txt").read_text(encoding="utf-8").strip(),
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
return LlmTask(
|
|
151
|
+
task_id="resume-generation",
|
|
152
|
+
prompt_version="resume-v1",
|
|
153
|
+
schema_version="resume-v1",
|
|
154
|
+
system_prompt=prompt,
|
|
155
|
+
user_prompt=json.dumps(context, ensure_ascii=False, sort_keys=True, separators=(",", ":")),
|
|
156
|
+
output_schema=ResumeLlmOutput.model_json_schema(by_alias=True),
|
|
157
|
+
allowed_evidence_ids=allowed_evidence_ids,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _to_domain_claim(value: _ResumeClaimOutput) -> ResumeClaim:
|
|
162
|
+
return ResumeClaim(
|
|
163
|
+
text=value.text,
|
|
164
|
+
claim_strength=value.claim_strength,
|
|
165
|
+
contribution_item_ids=tuple(value.contribution_item_ids),
|
|
166
|
+
evidence_ids=tuple(value.evidence_ids),
|
|
167
|
+
verified_outcome_ids=tuple(value.verified_outcome_ids),
|
|
168
|
+
confidence=value.confidence,
|
|
169
|
+
pending=value.pending,
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def build_deterministic_resume(
|
|
174
|
+
subject: SnapshotSubject,
|
|
175
|
+
*,
|
|
176
|
+
language: ResumeLanguage,
|
|
177
|
+
style: ResumeStyle,
|
|
178
|
+
max_bullets: int,
|
|
179
|
+
include_pending: bool,
|
|
180
|
+
outcomes: tuple[VerifiedOutcome, ...],
|
|
181
|
+
) -> dict[str, Any]:
|
|
182
|
+
claims: list[ResumeClaim] = []
|
|
183
|
+
omitted: list[OmittedClaim] = []
|
|
184
|
+
ceilings: dict[str, ClaimStrength] = {}
|
|
185
|
+
allowed_evidence_ids = {entry.id for entry in subject.evidence}
|
|
186
|
+
for item in subject.contribution_items:
|
|
187
|
+
completion = classify_completion(item)
|
|
188
|
+
work_types = {commit.commit_type for commit in item.commits}
|
|
189
|
+
ceiling = claim_strength_ceiling(
|
|
190
|
+
confirmed=subject.person.confirmed,
|
|
191
|
+
completion=completion,
|
|
192
|
+
work_types=work_types,
|
|
193
|
+
)
|
|
194
|
+
ceilings[item.id] = ceiling
|
|
195
|
+
if completion not in (CompletionBucket.COMPLETED, CompletionBucket.PENDING):
|
|
196
|
+
omitted.append(
|
|
197
|
+
OmittedClaim(item.title, "NOT_COMPLETED", ("LANDED_OR_RELEASED",))
|
|
198
|
+
)
|
|
199
|
+
continue
|
|
200
|
+
if completion is CompletionBucket.PENDING and not include_pending:
|
|
201
|
+
omitted.append(
|
|
202
|
+
OmittedClaim(item.title, "PENDING_EXCLUDED", ("DELIVERY_EVIDENCE",))
|
|
203
|
+
)
|
|
204
|
+
continue
|
|
205
|
+
claim = ResumeClaim(
|
|
206
|
+
text=_claim_text(item.modules, work_types, ceiling, language, style),
|
|
207
|
+
claim_strength=(
|
|
208
|
+
ClaimStrength.CONTRIBUTED
|
|
209
|
+
if completion is CompletionBucket.PENDING
|
|
210
|
+
else ceiling
|
|
211
|
+
),
|
|
212
|
+
contribution_item_ids=(item.id,),
|
|
213
|
+
evidence_ids=item.evidence_ids,
|
|
214
|
+
verified_outcome_ids=(),
|
|
215
|
+
confidence="HIGH" if item.confidence == "HIGH" else "MEDIUM",
|
|
216
|
+
pending=completion is CompletionBucket.PENDING,
|
|
217
|
+
)
|
|
218
|
+
validate_resume_claim(
|
|
219
|
+
claim,
|
|
220
|
+
allowed_item_ids={value.id for value in subject.contribution_items},
|
|
221
|
+
allowed_evidence_ids=allowed_evidence_ids,
|
|
222
|
+
strength_ceilings=ceilings,
|
|
223
|
+
outcomes=outcomes,
|
|
224
|
+
)
|
|
225
|
+
claims.append(claim)
|
|
226
|
+
claims = claims[:max_bullets]
|
|
227
|
+
item_ids = {item_id for claim in claims for item_id in claim.contribution_item_ids}
|
|
228
|
+
skills = [
|
|
229
|
+
SkillEvidence(
|
|
230
|
+
skill=capability.capability,
|
|
231
|
+
evidence_ids=capability.evidence_ids,
|
|
232
|
+
contribution_item_ids=tuple(
|
|
233
|
+
item.id
|
|
234
|
+
for item in subject.contribution_items
|
|
235
|
+
if item.id in item_ids
|
|
236
|
+
and set(item.evidence_ids).intersection(capability.evidence_ids)
|
|
237
|
+
),
|
|
238
|
+
)
|
|
239
|
+
for capability in subject.capabilities
|
|
240
|
+
if set(capability.evidence_ids) <= allowed_evidence_ids
|
|
241
|
+
]
|
|
242
|
+
modules = Counter(
|
|
243
|
+
module
|
|
244
|
+
for item in subject.contribution_items
|
|
245
|
+
if item.id in item_ids
|
|
246
|
+
for module in item.modules
|
|
247
|
+
)
|
|
248
|
+
domains = sorted(
|
|
249
|
+
{
|
|
250
|
+
item.group_key.split(":", maxsplit=1)[0]
|
|
251
|
+
for item in subject.contribution_items
|
|
252
|
+
if item.id in item_ids
|
|
253
|
+
}
|
|
254
|
+
)
|
|
255
|
+
return {
|
|
256
|
+
"projectSummaryCandidates": [_serialize_claim(claim) for claim in claims[:1]],
|
|
257
|
+
"experienceBullets": [_serialize_claim(claim) for claim in claims],
|
|
258
|
+
"skillEvidence": [_serialize_skill(value) for value in skills],
|
|
259
|
+
"omittedClaims": [_serialize_omitted(value) for value in omitted],
|
|
260
|
+
"technicalSummary": {
|
|
261
|
+
"headline": f"Evidence supports work across {len(modules)} technical modules.",
|
|
262
|
+
"modules": [name for name, _count in modules.most_common()],
|
|
263
|
+
},
|
|
264
|
+
"businessSummary": {
|
|
265
|
+
"headline": f"Evidence supports contributions in {len(domains)} project domains.",
|
|
266
|
+
"domains": domains,
|
|
267
|
+
},
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def _claim_text(
|
|
272
|
+
modules: tuple[str, ...],
|
|
273
|
+
work_types: set[str],
|
|
274
|
+
strength: ClaimStrength,
|
|
275
|
+
language: ResumeLanguage,
|
|
276
|
+
style: ResumeStyle,
|
|
277
|
+
) -> str:
|
|
278
|
+
module_text = ", ".join(modules) or "the project"
|
|
279
|
+
work_text = "/".join(sorted(value.casefold() for value in work_types)) or "engineering"
|
|
280
|
+
if language is ResumeLanguage.ZH_CN:
|
|
281
|
+
verb = "实现并交付" if strength is ClaimStrength.IMPLEMENTED else "参与"
|
|
282
|
+
suffix = ", 覆盖完整交付链路" if style is ResumeStyle.STAR else ""
|
|
283
|
+
return f"{verb}{module_text}模块的{work_text}工作{suffix}"
|
|
284
|
+
verb = (
|
|
285
|
+
"Implemented and delivered"
|
|
286
|
+
if strength is ClaimStrength.IMPLEMENTED
|
|
287
|
+
else "Contributed to"
|
|
288
|
+
)
|
|
289
|
+
suffix = " with supporting delivery evidence" if style is ResumeStyle.STAR else ""
|
|
290
|
+
return f"{verb} {work_text} work across {module_text}{suffix}."
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def _serialize_claim(claim: ResumeClaim) -> dict[str, Any]:
|
|
294
|
+
return {
|
|
295
|
+
"text": claim.text,
|
|
296
|
+
"claimStrength": claim.claim_strength.value,
|
|
297
|
+
"contributionItemIds": list(claim.contribution_item_ids),
|
|
298
|
+
"evidenceIds": list(claim.evidence_ids),
|
|
299
|
+
"verifiedOutcomeIds": list(claim.verified_outcome_ids),
|
|
300
|
+
"confidence": claim.confidence,
|
|
301
|
+
"pending": claim.pending,
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def _serialize_skill(value: SkillEvidence) -> dict[str, Any]:
|
|
306
|
+
return {
|
|
307
|
+
"skill": value.skill,
|
|
308
|
+
"evidenceIds": list(value.evidence_ids),
|
|
309
|
+
"contributionItemIds": list(value.contribution_item_ids),
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def _serialize_omitted(value: OmittedClaim) -> dict[str, Any]:
|
|
314
|
+
return {
|
|
315
|
+
"candidate": value.candidate,
|
|
316
|
+
"reasonCode": value.reason_code,
|
|
317
|
+
"missingEvidence": list(value.missing_evidence),
|
|
318
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
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 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.semantic import SemanticEnhancement
|
|
18
|
+
|
|
19
|
+
PERCENTAGE_PATTERN = re.compile(r"\b\d+(?:\.\d+)?\s*%")
|
|
20
|
+
PROMPT_NAMES = (
|
|
21
|
+
"overall_summary.txt",
|
|
22
|
+
"contribution_summary.txt",
|
|
23
|
+
"capability_explanation.txt",
|
|
24
|
+
"resume_bullet.txt",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True, slots=True)
|
|
29
|
+
class SemanticEnhancementResult:
|
|
30
|
+
semantic: dict[str, Any]
|
|
31
|
+
completion: LlmCompletion
|
|
32
|
+
task: LlmTask
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def enhance_report(
|
|
36
|
+
report: dict[str, Any],
|
|
37
|
+
provider: LlmProvider,
|
|
38
|
+
) -> SemanticEnhancementResult:
|
|
39
|
+
task = build_semantic_task(report)
|
|
40
|
+
completion = provider.complete(task)
|
|
41
|
+
try:
|
|
42
|
+
semantic = SemanticEnhancement.model_validate(completion.content)
|
|
43
|
+
except ValidationError as exc:
|
|
44
|
+
raise LlmOutputError("LLM output does not match semantic-v1 schema") from exc
|
|
45
|
+
_validate_claims(report, semantic, set(task.allowed_evidence_ids))
|
|
46
|
+
return SemanticEnhancementResult(
|
|
47
|
+
semantic=semantic.model_dump(by_alias=True, mode="json"),
|
|
48
|
+
completion=completion,
|
|
49
|
+
task=task,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def build_semantic_task(report: dict[str, Any]) -> LlmTask:
|
|
54
|
+
selected_items = report["contributionItems"][:80]
|
|
55
|
+
requested_evidence = {
|
|
56
|
+
evidence_id
|
|
57
|
+
for item in selected_items
|
|
58
|
+
for evidence_id in item["evidenceIds"]
|
|
59
|
+
}
|
|
60
|
+
requested_evidence.update(
|
|
61
|
+
evidence_id
|
|
62
|
+
for capability in report["capabilities"]
|
|
63
|
+
for evidence_id in capability["evidenceIds"]
|
|
64
|
+
)
|
|
65
|
+
selected_evidence = [
|
|
66
|
+
entry for entry in report["evidence"] if entry["id"] in requested_evidence
|
|
67
|
+
][:200]
|
|
68
|
+
allowed_evidence_ids = tuple(entry["id"] for entry in selected_evidence)
|
|
69
|
+
allowed_set = set(allowed_evidence_ids)
|
|
70
|
+
context = {
|
|
71
|
+
"summary": report["summary"],
|
|
72
|
+
"commitTypes": report["commitTypes"],
|
|
73
|
+
"deliveryStatuses": report["deliveryStatuses"],
|
|
74
|
+
"modules": report["modules"],
|
|
75
|
+
"contributionItems": [
|
|
76
|
+
{
|
|
77
|
+
"id": item["id"],
|
|
78
|
+
"title": item["title"],
|
|
79
|
+
"confidence": item["confidence"],
|
|
80
|
+
"commitTypes": item["commitTypes"],
|
|
81
|
+
"deliveryStatuses": item["deliveryStatuses"],
|
|
82
|
+
"modules": item["modules"],
|
|
83
|
+
"paths": item["paths"][:20],
|
|
84
|
+
"evidenceIds": [
|
|
85
|
+
value for value in item["evidenceIds"] if value in allowed_set
|
|
86
|
+
],
|
|
87
|
+
}
|
|
88
|
+
for item in selected_items
|
|
89
|
+
],
|
|
90
|
+
"capabilities": [
|
|
91
|
+
{
|
|
92
|
+
"capability": capability["capability"],
|
|
93
|
+
"confidence": capability["confidence"],
|
|
94
|
+
"rationale": capability["rationale"],
|
|
95
|
+
"evidenceIds": [
|
|
96
|
+
value for value in capability["evidenceIds"] if value in allowed_set
|
|
97
|
+
],
|
|
98
|
+
"gaps": capability["gaps"],
|
|
99
|
+
}
|
|
100
|
+
for capability in report["capabilities"]
|
|
101
|
+
],
|
|
102
|
+
"evidence": [
|
|
103
|
+
{
|
|
104
|
+
"id": entry["id"],
|
|
105
|
+
"type": entry["type"],
|
|
106
|
+
"summary": entry["summary"],
|
|
107
|
+
"metrics": entry["metrics"],
|
|
108
|
+
}
|
|
109
|
+
for entry in selected_evidence
|
|
110
|
+
],
|
|
111
|
+
}
|
|
112
|
+
prompt_root = files("git_contribution_analyzer.prompts.v1")
|
|
113
|
+
instructions = [
|
|
114
|
+
prompt_root.joinpath(name).read_text(encoding="utf-8").strip()
|
|
115
|
+
for name in PROMPT_NAMES
|
|
116
|
+
]
|
|
117
|
+
system_prompt = (
|
|
118
|
+
"You enhance deterministic Git evidence. Return only JSON matching the supplied schema. "
|
|
119
|
+
"Never invent outcomes, percentages, ownership, or Evidence IDs.\n\n"
|
|
120
|
+
+ "\n\n".join(instructions)
|
|
121
|
+
)
|
|
122
|
+
return LlmTask(
|
|
123
|
+
task_id="semantic-report",
|
|
124
|
+
prompt_version="semantic-v1",
|
|
125
|
+
schema_version="semantic-v1",
|
|
126
|
+
system_prompt=system_prompt,
|
|
127
|
+
user_prompt=json.dumps(context, ensure_ascii=False, sort_keys=True, separators=(",", ":")),
|
|
128
|
+
output_schema=SemanticEnhancement.model_json_schema(by_alias=True),
|
|
129
|
+
allowed_evidence_ids=allowed_evidence_ids,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _validate_claims(
|
|
134
|
+
report: dict[str, Any],
|
|
135
|
+
semantic: SemanticEnhancement,
|
|
136
|
+
allowed_evidence_ids: set[str],
|
|
137
|
+
) -> None:
|
|
138
|
+
item_ids = {item["id"] for item in report["contributionItems"]}
|
|
139
|
+
capabilities = {entry["capability"] for entry in report["capabilities"]}
|
|
140
|
+
claims = [
|
|
141
|
+
*semantic.overall_summary,
|
|
142
|
+
*semantic.contribution_summaries,
|
|
143
|
+
*semantic.capability_explanations,
|
|
144
|
+
*semantic.resume_bullets,
|
|
145
|
+
]
|
|
146
|
+
for claim in claims:
|
|
147
|
+
if not set(claim.evidence_ids) <= allowed_evidence_ids:
|
|
148
|
+
raise LlmOutputError("LLM output references unknown Evidence IDs")
|
|
149
|
+
if PERCENTAGE_PATTERN.search(claim.text):
|
|
150
|
+
raise LlmOutputError("LLM output contains an unsupported percentage claim")
|
|
151
|
+
if any(item.contribution_item_id not in item_ids for item in semantic.contribution_summaries):
|
|
152
|
+
raise LlmOutputError("LLM output references an unknown Contribution Item")
|
|
153
|
+
if any(
|
|
154
|
+
explanation.capability not in capabilities
|
|
155
|
+
for explanation in semantic.capability_explanations
|
|
156
|
+
):
|
|
157
|
+
raise LlmOutputError("LLM output references an unknown capability")
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import datetime, time
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def parse_boundary(value: str | None, *, end_of_day: bool) -> datetime | None:
|
|
7
|
+
if value is None:
|
|
8
|
+
return None
|
|
9
|
+
try:
|
|
10
|
+
if "T" not in value and " " not in value:
|
|
11
|
+
parsed_date = datetime.fromisoformat(value).date()
|
|
12
|
+
parsed = datetime.combine(parsed_date, time.max if end_of_day else time.min)
|
|
13
|
+
else:
|
|
14
|
+
parsed = datetime.fromisoformat(value.replace("Z", "+00:00"))
|
|
15
|
+
except ValueError as exc:
|
|
16
|
+
raise ValueError(f"Invalid ISO date/time: {value}") from exc
|
|
17
|
+
return parsed if parsed.tzinfo is not None else localize_system_time(parsed)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def localize_system_time(value: datetime) -> datetime:
|
|
21
|
+
return value.astimezone()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def uses_system_timezone(*values: str | None) -> bool:
|
|
25
|
+
for value in values:
|
|
26
|
+
if value is None:
|
|
27
|
+
continue
|
|
28
|
+
try:
|
|
29
|
+
parsed = datetime.fromisoformat(value.replace("Z", "+00:00"))
|
|
30
|
+
except ValueError:
|
|
31
|
+
continue
|
|
32
|
+
if parsed.tzinfo is None:
|
|
33
|
+
return True
|
|
34
|
+
return False
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def parse_boundaries(
|
|
38
|
+
since: str | None,
|
|
39
|
+
until: str | None,
|
|
40
|
+
) -> tuple[datetime | None, datetime | None]:
|
|
41
|
+
parsed_since = parse_boundary(since, end_of_day=False)
|
|
42
|
+
parsed_until = parse_boundary(until, end_of_day=True)
|
|
43
|
+
if (
|
|
44
|
+
parsed_since is not None
|
|
45
|
+
and parsed_until is not None
|
|
46
|
+
and parsed_since > parsed_until
|
|
47
|
+
):
|
|
48
|
+
raise ValueError("since must be earlier than or equal to until")
|
|
49
|
+
return parsed_since, parsed_until
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Application use cases."""
|