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,189 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Sequence
|
|
4
|
+
from datetime import date
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from git_contribution_analyzer.adapters.outcomes.yaml_store import (
|
|
9
|
+
default_outcomes_path,
|
|
10
|
+
load_outcomes_if_exists,
|
|
11
|
+
next_outcome_id,
|
|
12
|
+
outcomes_lock_path,
|
|
13
|
+
save_verified_outcomes,
|
|
14
|
+
)
|
|
15
|
+
from git_contribution_analyzer.adapters.storage.sqlite.analysis import SqliteAnalysisStore
|
|
16
|
+
from git_contribution_analyzer.adapters.workspace.layout import WorkspaceLayout
|
|
17
|
+
from git_contribution_analyzer.adapters.workspace.portfolio_workspace import FilePortfolioStore
|
|
18
|
+
from git_contribution_analyzer.domain.errors import ConfigurationError, ReportError
|
|
19
|
+
from git_contribution_analyzer.domain.models.resume import VerifiedOutcome
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _is_portfolio(target_dir: Path) -> bool:
|
|
23
|
+
return (target_dir.expanduser().resolve() / "portfolio.yml").is_file()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _collect_known_evidence_ids(target_dir: Path) -> set[str]:
|
|
27
|
+
resolved = target_dir.expanduser().resolve()
|
|
28
|
+
known: set[str] = set()
|
|
29
|
+
if _is_portfolio(resolved):
|
|
30
|
+
store = FilePortfolioStore(resolved)
|
|
31
|
+
manifest = store.load_manifest()
|
|
32
|
+
for repo in manifest.repositories:
|
|
33
|
+
repo_path = store.resolve_repo_path(repo)
|
|
34
|
+
layout = WorkspaceLayout.for_repository(repo_path)
|
|
35
|
+
if not layout.database.is_file():
|
|
36
|
+
continue
|
|
37
|
+
analysis_store = SqliteAnalysisStore(layout.database, str(repo_path.resolve()))
|
|
38
|
+
for run in analysis_store.list_runs():
|
|
39
|
+
try:
|
|
40
|
+
payload = analysis_store.get_report(str(run["id"]))
|
|
41
|
+
except ReportError:
|
|
42
|
+
continue
|
|
43
|
+
for entry in payload.get("evidence", []):
|
|
44
|
+
raw_id = str(entry.get("id") or "").strip()
|
|
45
|
+
if raw_id:
|
|
46
|
+
bare = raw_id.split(":")[-1]
|
|
47
|
+
known.add(f"{repo.repo_key}:{bare}")
|
|
48
|
+
known.add(bare)
|
|
49
|
+
return known
|
|
50
|
+
|
|
51
|
+
layout = WorkspaceLayout.for_repository(resolved)
|
|
52
|
+
if not layout.database.is_file():
|
|
53
|
+
return known
|
|
54
|
+
analysis_store = SqliteAnalysisStore(layout.database, str(resolved))
|
|
55
|
+
for run in analysis_store.list_runs():
|
|
56
|
+
try:
|
|
57
|
+
payload = analysis_store.get_report(str(run["id"]))
|
|
58
|
+
except ReportError:
|
|
59
|
+
continue
|
|
60
|
+
for entry in payload.get("evidence", []):
|
|
61
|
+
raw_id = str(entry.get("id") or "").strip()
|
|
62
|
+
if raw_id:
|
|
63
|
+
known.add(raw_id)
|
|
64
|
+
known.add(raw_id.split(":")[-1])
|
|
65
|
+
return known
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _outcome_to_dict(outcome: VerifiedOutcome) -> dict[str, Any]:
|
|
69
|
+
return {
|
|
70
|
+
"id": outcome.id,
|
|
71
|
+
"text": outcome.text,
|
|
72
|
+
"source": outcome.source,
|
|
73
|
+
"verifiedBy": outcome.verified_by,
|
|
74
|
+
"verifiedAt": outcome.verified_at.isoformat(),
|
|
75
|
+
"kind": outcome.kind,
|
|
76
|
+
"evidenceIds": list(outcome.evidence_ids),
|
|
77
|
+
"tags": list(outcome.tags),
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _resolve_outcomes_file(target_dir: Path, outcomes_file: Path | None) -> Path:
|
|
82
|
+
if outcomes_file is not None:
|
|
83
|
+
return outcomes_file.expanduser().resolve()
|
|
84
|
+
return default_outcomes_path(target_dir)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def list_outcomes(
|
|
88
|
+
target_dir: Path,
|
|
89
|
+
*,
|
|
90
|
+
outcomes_file: Path | None = None,
|
|
91
|
+
) -> dict[str, Any]:
|
|
92
|
+
"""列出本地仓库或 Portfolio 成果簿中的已核验 Outcomes."""
|
|
93
|
+
path = _resolve_outcomes_file(target_dir, outcomes_file)
|
|
94
|
+
outcomes = load_outcomes_if_exists(path)
|
|
95
|
+
return {
|
|
96
|
+
"file": str(path),
|
|
97
|
+
"exists": path.is_file(),
|
|
98
|
+
"count": len(outcomes),
|
|
99
|
+
"outcomes": [_outcome_to_dict(item) for item in outcomes],
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def add_outcome(
|
|
104
|
+
target_dir: Path,
|
|
105
|
+
*,
|
|
106
|
+
text: str,
|
|
107
|
+
source: str,
|
|
108
|
+
verified_by: str,
|
|
109
|
+
verified_at: date | None = None,
|
|
110
|
+
kind: str = "OUTCOME",
|
|
111
|
+
outcome_id: str | None = None,
|
|
112
|
+
evidence_ids: Sequence[str] = (),
|
|
113
|
+
tags: Sequence[str] = (),
|
|
114
|
+
verify_evidence: bool = True,
|
|
115
|
+
outcomes_file: Path | None = None,
|
|
116
|
+
) -> dict[str, Any]:
|
|
117
|
+
"""向本地成果簿新增一条已核验 Outcome, 可选离线校验关联的 EV-xxx 证据存在性."""
|
|
118
|
+
clean_text = text.strip()
|
|
119
|
+
clean_source = source.strip()
|
|
120
|
+
clean_verifier = verified_by.strip()
|
|
121
|
+
if not clean_text or not clean_source or not clean_verifier:
|
|
122
|
+
raise ConfigurationError("text, source, and verifiedBy must be non-empty")
|
|
123
|
+
|
|
124
|
+
clean_evs = tuple(dict.fromkeys(ev.strip() for ev in evidence_ids if ev and ev.strip()))
|
|
125
|
+
clean_tags = tuple(dict.fromkeys(tag.strip() for tag in tags if tag and tag.strip()))
|
|
126
|
+
|
|
127
|
+
if verify_evidence and clean_evs:
|
|
128
|
+
known = _collect_known_evidence_ids(target_dir)
|
|
129
|
+
if not known:
|
|
130
|
+
raise ConfigurationError(
|
|
131
|
+
"No persisted evidence found to verify --evidence; run analyze/assess/recap first "
|
|
132
|
+
"or pass --no-verify-evidence"
|
|
133
|
+
)
|
|
134
|
+
missing = [ev for ev in clean_evs if ev not in known]
|
|
135
|
+
if missing:
|
|
136
|
+
raise ConfigurationError(
|
|
137
|
+
f"Unknown evidence ID(s) not found in persisted runs: {', '.join(missing)}"
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
path = _resolve_outcomes_file(target_dir, outcomes_file)
|
|
141
|
+
existing = list(load_outcomes_if_exists(path))
|
|
142
|
+
assigned_id = (
|
|
143
|
+
outcome_id.strip() if outcome_id and outcome_id.strip() else next_outcome_id(existing)
|
|
144
|
+
)
|
|
145
|
+
if any(item.id.lower() == assigned_id.lower() for item in existing):
|
|
146
|
+
raise ConfigurationError(f"Outcome ID already exists: {assigned_id}")
|
|
147
|
+
|
|
148
|
+
entry = VerifiedOutcome(
|
|
149
|
+
id=assigned_id,
|
|
150
|
+
text=clean_text,
|
|
151
|
+
source=clean_source,
|
|
152
|
+
verified_by=clean_verifier,
|
|
153
|
+
verified_at=verified_at or date.today(),
|
|
154
|
+
kind=kind.strip().upper() or "OUTCOME",
|
|
155
|
+
evidence_ids=clean_evs,
|
|
156
|
+
tags=clean_tags,
|
|
157
|
+
)
|
|
158
|
+
existing.append(entry)
|
|
159
|
+
lock_file = outcomes_lock_path(target_dir, path)
|
|
160
|
+
save_verified_outcomes(path, existing, lock_file=lock_file)
|
|
161
|
+
return {
|
|
162
|
+
"file": str(path),
|
|
163
|
+
"outcome": _outcome_to_dict(entry),
|
|
164
|
+
"totalOutcomes": len(existing),
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def remove_outcome(
|
|
169
|
+
target_dir: Path,
|
|
170
|
+
*,
|
|
171
|
+
outcome_id: str,
|
|
172
|
+
outcomes_file: Path | None = None,
|
|
173
|
+
) -> dict[str, Any]:
|
|
174
|
+
"""按 ID 从成果簿移除指定 Outcome."""
|
|
175
|
+
target_id = outcome_id.strip()
|
|
176
|
+
if not target_id:
|
|
177
|
+
raise ConfigurationError("outcome_id must be non-empty")
|
|
178
|
+
path = _resolve_outcomes_file(target_dir, outcomes_file)
|
|
179
|
+
existing = list(load_outcomes_if_exists(path))
|
|
180
|
+
remaining = [item for item in existing if item.id.lower() != target_id.lower()]
|
|
181
|
+
if len(remaining) == len(existing):
|
|
182
|
+
raise ConfigurationError(f"Outcome ID not found: {target_id}")
|
|
183
|
+
lock_file = outcomes_lock_path(target_dir, path)
|
|
184
|
+
save_verified_outcomes(path, remaining, lock_file=lock_file)
|
|
185
|
+
return {
|
|
186
|
+
"file": str(path),
|
|
187
|
+
"removedId": target_id,
|
|
188
|
+
"remainingOutcomes": len(remaining),
|
|
189
|
+
}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
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.storage.sqlite.database import initialize_database
|
|
13
|
+
from git_contribution_analyzer.adapters.storage.sqlite.structural_baseline import (
|
|
14
|
+
SqliteStructuralBaselineStore,
|
|
15
|
+
)
|
|
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.progress import (
|
|
25
|
+
NullProgressReporter,
|
|
26
|
+
ProgressEvent,
|
|
27
|
+
ProgressReporter,
|
|
28
|
+
)
|
|
29
|
+
from git_contribution_analyzer.application.ports.structural_baseline import (
|
|
30
|
+
StructuralBaselineStore,
|
|
31
|
+
)
|
|
32
|
+
from git_contribution_analyzer.domain.errors import WorkspaceError
|
|
33
|
+
from git_contribution_analyzer.domain.models.structural_baseline import (
|
|
34
|
+
StructuralRuleConfig,
|
|
35
|
+
StructuralTimeStrategy,
|
|
36
|
+
)
|
|
37
|
+
from git_contribution_analyzer.domain.services.structural_baseline import (
|
|
38
|
+
build_structural_baseline,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def rebuild_structural_baseline(
|
|
43
|
+
path: Path,
|
|
44
|
+
*,
|
|
45
|
+
cutoff: datetime,
|
|
46
|
+
branch: str | None = None,
|
|
47
|
+
scope: str | None = None,
|
|
48
|
+
time_strategy: StructuralTimeStrategy | None = None,
|
|
49
|
+
progress: ProgressReporter | None = None,
|
|
50
|
+
cancellation: CancellationToken | None = None,
|
|
51
|
+
) -> dict[str, Any]:
|
|
52
|
+
active_progress = progress or NullProgressReporter()
|
|
53
|
+
active_cancellation = cancellation or NeverCancelledToken()
|
|
54
|
+
active_cancellation.raise_if_cancelled()
|
|
55
|
+
repository = discover_repository(path)
|
|
56
|
+
task_id = str(uuid4())
|
|
57
|
+
layout = WorkspaceLayout.for_repository(repository.root)
|
|
58
|
+
if not layout.root.is_dir():
|
|
59
|
+
raise WorkspaceError("GCA workspace is not initialized; run 'gca init' first")
|
|
60
|
+
initialize_database(layout.database)
|
|
61
|
+
config = load_config(layout.config)
|
|
62
|
+
actual_branch = branch or config.default_branch
|
|
63
|
+
target_ref = (
|
|
64
|
+
actual_branch
|
|
65
|
+
if actual_branch.startswith("refs/")
|
|
66
|
+
else f"refs/heads/{actual_branch}"
|
|
67
|
+
)
|
|
68
|
+
history = NativeGitHistory(repository.root)
|
|
69
|
+
try:
|
|
70
|
+
allowed_hashes = set(history.reachable_commits(target_ref))
|
|
71
|
+
except Exception as exc:
|
|
72
|
+
raise WorkspaceError(f"Unable to resolve structural target ref: {target_ref}") from exc
|
|
73
|
+
store: StructuralBaselineStore = SqliteStructuralBaselineStore(
|
|
74
|
+
layout.database,
|
|
75
|
+
str(repository.root),
|
|
76
|
+
)
|
|
77
|
+
active_config = config.structural.to_rule_config(time_strategy=time_strategy)
|
|
78
|
+
fingerprint = _filter_fingerprint(target_ref, scope, active_config)
|
|
79
|
+
with workspace_lock(layout.locks / "workspace.lock"):
|
|
80
|
+
active_cancellation.raise_if_cancelled()
|
|
81
|
+
baseline_commit = store.latest_fact_commit(
|
|
82
|
+
allowed_hashes=allowed_hashes,
|
|
83
|
+
cutoff=cutoff,
|
|
84
|
+
scope=scope,
|
|
85
|
+
)
|
|
86
|
+
cached = store.find_completed(
|
|
87
|
+
branch=target_ref,
|
|
88
|
+
scope=scope,
|
|
89
|
+
cutoff=cutoff,
|
|
90
|
+
baseline_commit=baseline_commit,
|
|
91
|
+
filter_fingerprint=fingerprint,
|
|
92
|
+
time_strategy=active_config.time_strategy.value,
|
|
93
|
+
)
|
|
94
|
+
if cached is not None:
|
|
95
|
+
active_progress.report(
|
|
96
|
+
ProgressEvent(
|
|
97
|
+
task_id=task_id,
|
|
98
|
+
operation="structural_rebuild",
|
|
99
|
+
stage="completed",
|
|
100
|
+
repository=repository.root,
|
|
101
|
+
current=1,
|
|
102
|
+
total=1,
|
|
103
|
+
message="Structural baseline cache hit",
|
|
104
|
+
occurred_at=datetime.now(UTC),
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
return cached
|
|
108
|
+
diagnostic_id = _diagnostic_id(task_id)
|
|
109
|
+
store.begin_baseline(
|
|
110
|
+
diagnostic_id,
|
|
111
|
+
branch=target_ref,
|
|
112
|
+
scope=scope,
|
|
113
|
+
cutoff=cutoff,
|
|
114
|
+
baseline_commit=baseline_commit,
|
|
115
|
+
filter_fingerprint=fingerprint,
|
|
116
|
+
config=active_config,
|
|
117
|
+
)
|
|
118
|
+
try:
|
|
119
|
+
active_progress.report(
|
|
120
|
+
_event(task_id, repository.root, "reading_facts", "Reading structural facts")
|
|
121
|
+
)
|
|
122
|
+
commits = store.load_commits(
|
|
123
|
+
allowed_hashes=allowed_hashes,
|
|
124
|
+
cutoff=cutoff,
|
|
125
|
+
scope=scope,
|
|
126
|
+
)
|
|
127
|
+
active_cancellation.raise_if_cancelled()
|
|
128
|
+
active_progress.report(
|
|
129
|
+
_event(task_id, repository.root, "building_baseline", "Building baseline")
|
|
130
|
+
)
|
|
131
|
+
baseline = build_structural_baseline(
|
|
132
|
+
commits,
|
|
133
|
+
cutoff=cutoff,
|
|
134
|
+
config=active_config,
|
|
135
|
+
identity_context={
|
|
136
|
+
"repositoryId": store.repository_id(),
|
|
137
|
+
"branch": target_ref,
|
|
138
|
+
"scope": scope,
|
|
139
|
+
},
|
|
140
|
+
)
|
|
141
|
+
active_cancellation.raise_if_cancelled()
|
|
142
|
+
active_progress.report(
|
|
143
|
+
_event(task_id, repository.root, "publishing_baseline", "Publishing baseline")
|
|
144
|
+
)
|
|
145
|
+
result = store.save_baseline(
|
|
146
|
+
baseline,
|
|
147
|
+
branch=target_ref,
|
|
148
|
+
scope=scope,
|
|
149
|
+
baseline_commit=baseline_commit,
|
|
150
|
+
filter_fingerprint=fingerprint,
|
|
151
|
+
diagnostic_id=diagnostic_id,
|
|
152
|
+
)
|
|
153
|
+
except OperationCancelled as exc:
|
|
154
|
+
store.finish_baseline(
|
|
155
|
+
diagnostic_id,
|
|
156
|
+
status="CANCELLED",
|
|
157
|
+
error_message=type(exc).__name__,
|
|
158
|
+
)
|
|
159
|
+
raise OperationCancelled(
|
|
160
|
+
f"Operation cancelled; structural diagnostic: {diagnostic_id}"
|
|
161
|
+
) from exc
|
|
162
|
+
except Exception as exc:
|
|
163
|
+
store.finish_baseline(
|
|
164
|
+
diagnostic_id,
|
|
165
|
+
status="FAILED",
|
|
166
|
+
error_message=type(exc).__name__,
|
|
167
|
+
)
|
|
168
|
+
raise WorkspaceError(
|
|
169
|
+
f"Structural baseline build failed; diagnostic: {diagnostic_id}"
|
|
170
|
+
) from exc
|
|
171
|
+
active_progress.report(
|
|
172
|
+
ProgressEvent(
|
|
173
|
+
task_id=task_id,
|
|
174
|
+
operation="structural_rebuild",
|
|
175
|
+
stage="completed",
|
|
176
|
+
repository=repository.root,
|
|
177
|
+
current=1,
|
|
178
|
+
total=1,
|
|
179
|
+
message="Structural baseline rebuilt",
|
|
180
|
+
occurred_at=datetime.now(UTC),
|
|
181
|
+
)
|
|
182
|
+
)
|
|
183
|
+
return result
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def get_structural_status(path: Path) -> dict[str, Any]:
|
|
187
|
+
repository = discover_repository(path)
|
|
188
|
+
layout = WorkspaceLayout.for_repository(repository.root)
|
|
189
|
+
if not layout.root.is_dir():
|
|
190
|
+
raise WorkspaceError("GCA workspace is not initialized; run 'gca init' first")
|
|
191
|
+
initialize_database(layout.database)
|
|
192
|
+
return SqliteStructuralBaselineStore(
|
|
193
|
+
layout.database, str(repository.root)
|
|
194
|
+
).status()
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def show_structural_baseline(path: Path, baseline_id: str) -> dict[str, Any]:
|
|
198
|
+
repository = discover_repository(path)
|
|
199
|
+
layout = WorkspaceLayout.for_repository(repository.root)
|
|
200
|
+
if not layout.root.is_dir():
|
|
201
|
+
raise WorkspaceError("GCA workspace is not initialized; run 'gca init' first")
|
|
202
|
+
initialize_database(layout.database)
|
|
203
|
+
result = SqliteStructuralBaselineStore(
|
|
204
|
+
layout.database, str(repository.root)
|
|
205
|
+
).show(baseline_id)
|
|
206
|
+
if result is None:
|
|
207
|
+
raise WorkspaceError(f"Structural baseline not found: {baseline_id}")
|
|
208
|
+
return result
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def prune_structural_baselines(path: Path, *, keep: int) -> dict[str, int]:
|
|
212
|
+
repository = discover_repository(path)
|
|
213
|
+
layout = WorkspaceLayout.for_repository(repository.root)
|
|
214
|
+
if not layout.root.is_dir():
|
|
215
|
+
raise WorkspaceError("GCA workspace is not initialized; run 'gca init' first")
|
|
216
|
+
initialize_database(layout.database)
|
|
217
|
+
with workspace_lock(layout.locks / "workspace.lock"):
|
|
218
|
+
return SqliteStructuralBaselineStore(
|
|
219
|
+
layout.database, str(repository.root)
|
|
220
|
+
).prune(keep)
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def _filter_fingerprint(
|
|
224
|
+
branch: str,
|
|
225
|
+
scope: str | None,
|
|
226
|
+
config: StructuralRuleConfig,
|
|
227
|
+
) -> str:
|
|
228
|
+
payload = {
|
|
229
|
+
"branch": branch,
|
|
230
|
+
"scope": scope,
|
|
231
|
+
"timeStrategy": config.time_strategy.value,
|
|
232
|
+
"minimumBaselineCommits": config.minimum_baseline_commits,
|
|
233
|
+
"hotspotPercentile": config.hotspot_percentile,
|
|
234
|
+
"minimumCoChangeCount": config.minimum_co_change_count,
|
|
235
|
+
"minimumSubsetRatio": config.minimum_subset_ratio,
|
|
236
|
+
"minimumJaccard": config.minimum_jaccard,
|
|
237
|
+
"minimumHubPenalty": config.minimum_hub_penalty,
|
|
238
|
+
"maximumContextPaths": config.maximum_context_paths,
|
|
239
|
+
"rollingWindowDays": config.rolling_window_days,
|
|
240
|
+
"generatedRule": "contribution-generated-v1",
|
|
241
|
+
}
|
|
242
|
+
canonical = json.dumps(payload, sort_keys=True, separators=(",", ":"))
|
|
243
|
+
return hashlib.sha256(canonical.encode("utf-8")).hexdigest()
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def default_structural_cutoff() -> datetime:
|
|
247
|
+
return datetime.now(UTC)
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def _diagnostic_id(task_id: str) -> str:
|
|
251
|
+
return hashlib.sha256(task_id.encode("ascii")).hexdigest()
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _event(task_id: str, repository: Path, stage: str, message: str) -> ProgressEvent:
|
|
255
|
+
return ProgressEvent(
|
|
256
|
+
task_id=task_id,
|
|
257
|
+
operation="structural_rebuild",
|
|
258
|
+
stage=stage,
|
|
259
|
+
repository=repository,
|
|
260
|
+
message=message,
|
|
261
|
+
occurred_at=datetime.now(UTC),
|
|
262
|
+
)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from git_contribution_analyzer.adapters.git.repository_discovery import discover_repository
|
|
7
|
+
from git_contribution_analyzer.adapters.storage.sqlite.git_index import SqliteGitIndexStore
|
|
8
|
+
from git_contribution_analyzer.adapters.workspace.layout import WorkspaceLayout
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def map_identity(
|
|
12
|
+
path: Path,
|
|
13
|
+
*,
|
|
14
|
+
name: str,
|
|
15
|
+
email: str,
|
|
16
|
+
person_name: str,
|
|
17
|
+
person_email: str,
|
|
18
|
+
) -> dict[str, Any]:
|
|
19
|
+
repository = discover_repository(path)
|
|
20
|
+
layout = WorkspaceLayout.for_repository(repository.root)
|
|
21
|
+
store = SqliteGitIndexStore(layout.database, str(repository.root))
|
|
22
|
+
person = store.map_identity(
|
|
23
|
+
name=name,
|
|
24
|
+
email=email,
|
|
25
|
+
person_name=person_name,
|
|
26
|
+
person_email=person_email,
|
|
27
|
+
)
|
|
28
|
+
return {"person": person}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import UTC, datetime
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from git_contribution_analyzer.adapters.git.repository_discovery import discover_repository
|
|
7
|
+
from git_contribution_analyzer.adapters.storage.sqlite.analysis import SqliteAnalysisStore
|
|
8
|
+
from git_contribution_analyzer.adapters.storage.sqlite.database import initialize_database
|
|
9
|
+
from git_contribution_analyzer.adapters.workspace.layout import WorkspaceLayout
|
|
10
|
+
from git_contribution_analyzer.adapters.workspace.locks import workspace_lock
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def recover_interrupted_runs(path: Path) -> int:
|
|
14
|
+
repository = discover_repository(path)
|
|
15
|
+
layout = WorkspaceLayout.for_repository(repository.root)
|
|
16
|
+
initialize_database(layout.database)
|
|
17
|
+
store = SqliteAnalysisStore(layout.database, str(repository.root))
|
|
18
|
+
with workspace_lock(layout.locks / "workspace.lock"):
|
|
19
|
+
return store.fail_running_runs(
|
|
20
|
+
datetime.now(UTC),
|
|
21
|
+
"Interrupted before completion",
|
|
22
|
+
)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from git_contribution_analyzer.adapters.git.native_git import NativeGitHistory
|
|
7
|
+
from git_contribution_analyzer.adapters.git.repository_discovery import (
|
|
8
|
+
discover_repository,
|
|
9
|
+
git_version,
|
|
10
|
+
)
|
|
11
|
+
from git_contribution_analyzer.adapters.storage.sqlite.database import (
|
|
12
|
+
check_database,
|
|
13
|
+
initialize_database,
|
|
14
|
+
)
|
|
15
|
+
from git_contribution_analyzer.adapters.storage.sqlite.structural_baseline import (
|
|
16
|
+
SqliteStructuralBaselineStore,
|
|
17
|
+
)
|
|
18
|
+
from git_contribution_analyzer.adapters.workspace.config import load_config
|
|
19
|
+
from git_contribution_analyzer.adapters.workspace.layout import WorkspaceLayout
|
|
20
|
+
from git_contribution_analyzer.adapters.workspace.locks import can_acquire_lock
|
|
21
|
+
from git_contribution_analyzer.domain.errors import WorkspaceError
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def run_doctor(path: Path) -> dict[str, Any]:
|
|
25
|
+
repository = discover_repository(path)
|
|
26
|
+
layout = WorkspaceLayout.for_repository(repository.root)
|
|
27
|
+
if layout.database.is_file():
|
|
28
|
+
initialize_database(layout.database)
|
|
29
|
+
database_healthy = check_database(layout.database)
|
|
30
|
+
checks = [
|
|
31
|
+
{"name": "git", "healthy": bool(git_version()), "detail": git_version()},
|
|
32
|
+
{
|
|
33
|
+
"name": "workspace",
|
|
34
|
+
"healthy": (
|
|
35
|
+
layout.root.is_dir() and layout.config.is_file() and layout.metadata.is_file()
|
|
36
|
+
),
|
|
37
|
+
"detail": str(layout.root),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "database",
|
|
41
|
+
"healthy": database_healthy,
|
|
42
|
+
"detail": str(layout.database),
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "lock",
|
|
46
|
+
"healthy": can_acquire_lock(layout.locks / "workspace.lock"),
|
|
47
|
+
"detail": str(layout.locks / "workspace.lock"),
|
|
48
|
+
},
|
|
49
|
+
]
|
|
50
|
+
if database_healthy:
|
|
51
|
+
structural_store = SqliteStructuralBaselineStore(
|
|
52
|
+
layout.database, str(repository.root)
|
|
53
|
+
)
|
|
54
|
+
structural = structural_store.status()
|
|
55
|
+
history = NativeGitHistory(repository.root)
|
|
56
|
+
stale = int(structural["staleBaselines"])
|
|
57
|
+
for baseline in structural_store.completed_baseline_refs():
|
|
58
|
+
baseline_commit = baseline["baselineCommit"]
|
|
59
|
+
try:
|
|
60
|
+
reachable = baseline_commit is None or history.is_ancestor(
|
|
61
|
+
baseline_commit, str(baseline["branch"])
|
|
62
|
+
)
|
|
63
|
+
except WorkspaceError:
|
|
64
|
+
reachable = False
|
|
65
|
+
if not reachable:
|
|
66
|
+
stale += 1
|
|
67
|
+
checks.append(
|
|
68
|
+
{
|
|
69
|
+
"name": "structural",
|
|
70
|
+
"healthy": structural["unhealthyBaselines"] == 0 and stale == 0,
|
|
71
|
+
"detail": (
|
|
72
|
+
f"{structural['baselineCount']} baseline(s), "
|
|
73
|
+
f"{structural['processedCommits']} processed commit(s), "
|
|
74
|
+
f"{structural['orphanBaselines']} orphan baseline(s), "
|
|
75
|
+
f"{stale} stale baseline(s)"
|
|
76
|
+
),
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
if layout.config.is_file():
|
|
80
|
+
load_config(layout.config)
|
|
81
|
+
return {"healthy": all(bool(item["healthy"]) for item in checks), "checks": checks}
|