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,621 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from git_contribution_analyzer.adapters.mcp.protocol import McpToolDefinition
|
|
8
|
+
from git_contribution_analyzer.adapters.reporting.portfolio_markdown import (
|
|
9
|
+
render_portfolio_resume_markdown,
|
|
10
|
+
)
|
|
11
|
+
from git_contribution_analyzer.adapters.reporting.recap_markdown import render_recap_markdown
|
|
12
|
+
from git_contribution_analyzer.adapters.reporting.resume_markdown import render_resume_markdown
|
|
13
|
+
from git_contribution_analyzer.adapters.storage.sqlite.analysis import SqliteAnalysisStore
|
|
14
|
+
from git_contribution_analyzer.adapters.workspace.layout import WorkspaceLayout
|
|
15
|
+
from git_contribution_analyzer.adapters.workspace.portfolio_workspace import FilePortfolioStore
|
|
16
|
+
from git_contribution_analyzer.application.services.default_person import (
|
|
17
|
+
resolve_portfolio_default_person,
|
|
18
|
+
resolve_repo_default_person,
|
|
19
|
+
)
|
|
20
|
+
from git_contribution_analyzer.application.services.time_boundaries import parse_boundaries
|
|
21
|
+
from git_contribution_analyzer.application.use_cases.assess_portfolio import assess_portfolio
|
|
22
|
+
from git_contribution_analyzer.application.use_cases.assess_work import assess_work
|
|
23
|
+
from git_contribution_analyzer.application.use_cases.generate_portfolio_recap import (
|
|
24
|
+
generate_portfolio_recap,
|
|
25
|
+
)
|
|
26
|
+
from git_contribution_analyzer.application.use_cases.generate_portfolio_resume import (
|
|
27
|
+
generate_portfolio_resume,
|
|
28
|
+
)
|
|
29
|
+
from git_contribution_analyzer.application.use_cases.generate_recap import generate_recap
|
|
30
|
+
from git_contribution_analyzer.application.use_cases.generate_resume import generate_resume
|
|
31
|
+
from git_contribution_analyzer.application.use_cases.get_portfolio_status import (
|
|
32
|
+
get_portfolio_status,
|
|
33
|
+
)
|
|
34
|
+
from git_contribution_analyzer.application.use_cases.get_status import get_status
|
|
35
|
+
from git_contribution_analyzer.application.use_cases.verify_portfolio import (
|
|
36
|
+
_collect_evidence_index,
|
|
37
|
+
verify_portfolio,
|
|
38
|
+
)
|
|
39
|
+
from git_contribution_analyzer.domain.errors import ConfigurationError, ReportError
|
|
40
|
+
from git_contribution_analyzer.domain.models.analysis import AnalysisFilters
|
|
41
|
+
from git_contribution_analyzer.domain.services.portfolio_verifier import (
|
|
42
|
+
verify_portfolio_markdown_references,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
_SINGLE_REPO_EVIDENCE_RE = re.compile(r"\bEV-[A-Za-z0-9_-]+\b")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class WorkspaceAccessError(ConfigurationError):
|
|
49
|
+
"""MCP 工具访问路径超出白名单根目录时抛出的安全错误."""
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class WorkspaceSandbox:
|
|
53
|
+
"""强制校验所有 MCP 目标路径均位于显式授权的本地工作区白名单内."""
|
|
54
|
+
|
|
55
|
+
def __init__(self, allowed_roots: tuple[Path, ...]) -> None:
|
|
56
|
+
self._roots = tuple(root.expanduser().resolve() for root in allowed_roots)
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
def allowed_roots(self) -> tuple[Path, ...]:
|
|
60
|
+
return self._roots
|
|
61
|
+
|
|
62
|
+
def resolve_directory(self, raw_path: str | None) -> Path:
|
|
63
|
+
if not self._roots:
|
|
64
|
+
raise WorkspaceAccessError("MCP server has no configured workspace allowlist")
|
|
65
|
+
if raw_path is None:
|
|
66
|
+
resolved = self._roots[0]
|
|
67
|
+
if not resolved.is_dir():
|
|
68
|
+
raise WorkspaceAccessError("Default workspace root does not exist")
|
|
69
|
+
return resolved
|
|
70
|
+
text = raw_path.strip()
|
|
71
|
+
if not text:
|
|
72
|
+
raise WorkspaceAccessError("Directory path must be non-empty")
|
|
73
|
+
|
|
74
|
+
candidate = Path(text).expanduser()
|
|
75
|
+
if not candidate.is_absolute():
|
|
76
|
+
candidate = self._roots[0] / candidate
|
|
77
|
+
resolved = candidate.resolve()
|
|
78
|
+
|
|
79
|
+
if not any(resolved.is_relative_to(root) for root in self._roots):
|
|
80
|
+
raise WorkspaceAccessError(
|
|
81
|
+
"Access denied: target directory is outside the allowed MCP workspace roots"
|
|
82
|
+
)
|
|
83
|
+
if not resolved.is_dir():
|
|
84
|
+
raise WorkspaceAccessError("Target directory does not exist inside allowed workspace")
|
|
85
|
+
return resolved
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _require_str(args: dict[str, Any], key: str) -> str:
|
|
89
|
+
value = args.get(key)
|
|
90
|
+
if not isinstance(value, str) or not value.strip():
|
|
91
|
+
raise ValueError(f"Missing required string parameter: {key}")
|
|
92
|
+
return value.strip()
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _optional_str(args: dict[str, Any], key: str) -> str | None:
|
|
96
|
+
value = args.get(key)
|
|
97
|
+
if value is None:
|
|
98
|
+
return None
|
|
99
|
+
if not isinstance(value, str):
|
|
100
|
+
raise ValueError(f"Parameter {key} must be a string")
|
|
101
|
+
stripped = value.strip()
|
|
102
|
+
return stripped or None
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _sanitize_portfolio_summary(report: dict[str, Any]) -> dict[str, Any]:
|
|
106
|
+
"""移除原始邮箱与邮箱计数映射, 防止敏感身份信息外泄给外部模型."""
|
|
107
|
+
sanitized = dict(report)
|
|
108
|
+
raw_identity = report.get("identity")
|
|
109
|
+
if isinstance(raw_identity, dict):
|
|
110
|
+
sanitized["identity"] = {
|
|
111
|
+
"canonicalName": raw_identity.get("canonicalName"),
|
|
112
|
+
"notes": list(raw_identity.get("notes", [])),
|
|
113
|
+
}
|
|
114
|
+
return sanitized
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _sanitize_single_repo_assessment(report: dict[str, Any]) -> dict[str, Any]:
|
|
118
|
+
"""移除单仓评估报告中的原始邮箱与本机路径, 保证 MCP 输出隐私安全."""
|
|
119
|
+
sanitized = dict(report)
|
|
120
|
+
sanitized.pop("repository", None)
|
|
121
|
+
selection = report.get("selection")
|
|
122
|
+
if isinstance(selection, dict):
|
|
123
|
+
clean_selection = dict(selection)
|
|
124
|
+
clean_selection["requestedSelectors"] = []
|
|
125
|
+
sanitized["selection"] = clean_selection
|
|
126
|
+
parameters = report.get("parameters")
|
|
127
|
+
if isinstance(parameters, dict):
|
|
128
|
+
clean_params = dict(parameters)
|
|
129
|
+
if "people" in clean_params:
|
|
130
|
+
clean_params["people"] = []
|
|
131
|
+
sanitized["parameters"] = clean_params
|
|
132
|
+
subjects = report.get("subjects")
|
|
133
|
+
if isinstance(subjects, list):
|
|
134
|
+
clean_subjects: list[dict[str, Any]] = []
|
|
135
|
+
for subject in subjects:
|
|
136
|
+
if not isinstance(subject, dict):
|
|
137
|
+
continue
|
|
138
|
+
item = dict(subject)
|
|
139
|
+
person = item.get("person")
|
|
140
|
+
if isinstance(person, dict):
|
|
141
|
+
item["person"] = {
|
|
142
|
+
"id": person.get("id"),
|
|
143
|
+
"name": person.get("name"),
|
|
144
|
+
}
|
|
145
|
+
clean_subjects.append(item)
|
|
146
|
+
sanitized["subjects"] = clean_subjects
|
|
147
|
+
return sanitized
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _sanitize_single_repo_status(repo_dir: Path) -> dict[str, Any]:
|
|
151
|
+
raw = get_status(repo_dir)
|
|
152
|
+
return {
|
|
153
|
+
"mode": "REPOSITORY",
|
|
154
|
+
"repositoryName": repo_dir.name,
|
|
155
|
+
"workspaceInitialized": bool(raw.get("workspaceInitialized")),
|
|
156
|
+
"databaseHealthy": bool(raw.get("databaseHealthy")),
|
|
157
|
+
"defaultBranch": raw.get("defaultBranch"),
|
|
158
|
+
"counts": dict(raw.get("counts") or {}),
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _collect_repo_evidence(
|
|
163
|
+
repo_key: str,
|
|
164
|
+
repo_path: Path,
|
|
165
|
+
*,
|
|
166
|
+
qualify: bool,
|
|
167
|
+
) -> list[dict[str, Any]]:
|
|
168
|
+
layout = WorkspaceLayout.for_repository(repo_path)
|
|
169
|
+
if not layout.database.is_file():
|
|
170
|
+
return []
|
|
171
|
+
store = SqliteAnalysisStore(layout.database, str(repo_path.resolve()))
|
|
172
|
+
seen: dict[str, dict[str, Any]] = {}
|
|
173
|
+
for run in store.list_runs():
|
|
174
|
+
try:
|
|
175
|
+
run_payload = store.get_report(str(run["id"]))
|
|
176
|
+
except ReportError:
|
|
177
|
+
continue
|
|
178
|
+
for entry in run_payload.get("evidence", []):
|
|
179
|
+
raw_id = str(entry.get("id") or "")
|
|
180
|
+
if not raw_id:
|
|
181
|
+
continue
|
|
182
|
+
bare_id = raw_id.split(":")[-1]
|
|
183
|
+
ev_id = f"{repo_key}:{bare_id}" if qualify else bare_id
|
|
184
|
+
if ev_id in seen:
|
|
185
|
+
continue
|
|
186
|
+
seen[ev_id] = {
|
|
187
|
+
"evidenceId": ev_id,
|
|
188
|
+
"repoKey": repo_key,
|
|
189
|
+
"type": entry.get("type"),
|
|
190
|
+
"summary": entry.get("summary"),
|
|
191
|
+
"commitHashes": list(entry.get("commitHashes", [])),
|
|
192
|
+
"paths": list(entry.get("paths", [])),
|
|
193
|
+
"metrics": dict(entry.get("metrics", {})),
|
|
194
|
+
}
|
|
195
|
+
return list(seen.values())
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def _is_portfolio_dir(target: Path) -> bool:
|
|
199
|
+
return (target / "portfolio.yml").is_file()
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _resolve_target_person(target_dir: Path, explicit: str | None) -> str:
|
|
203
|
+
if explicit:
|
|
204
|
+
return explicit
|
|
205
|
+
if _is_portfolio_dir(target_dir):
|
|
206
|
+
return resolve_portfolio_default_person(target_dir)
|
|
207
|
+
return resolve_repo_default_person(target_dir)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _verify_single_repo_markdown(
|
|
211
|
+
repo_dir: Path,
|
|
212
|
+
markdown_text: str,
|
|
213
|
+
) -> dict[str, Any]:
|
|
214
|
+
records = _collect_repo_evidence(repo_dir.name, repo_dir, qualify=False)
|
|
215
|
+
valid_ids = {str(item["evidenceId"]) for item in records}
|
|
216
|
+
refs = _SINGLE_REPO_EVIDENCE_RE.findall(markdown_text)
|
|
217
|
+
issues: list[dict[str, str]] = []
|
|
218
|
+
for ref in refs:
|
|
219
|
+
if ref not in valid_ids:
|
|
220
|
+
issues.append(
|
|
221
|
+
{
|
|
222
|
+
"code": "UNKNOWN_EVIDENCE_ID",
|
|
223
|
+
"message": f"Evidence ID not found in indexed repository runs: {ref}",
|
|
224
|
+
"location": ref,
|
|
225
|
+
}
|
|
226
|
+
)
|
|
227
|
+
return {
|
|
228
|
+
"ok": not issues,
|
|
229
|
+
"scope": "REPOSITORY",
|
|
230
|
+
"checkedEvidenceReferences": len(refs),
|
|
231
|
+
"issues": issues,
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def build_readonly_tools(sandbox: WorkspaceSandbox) -> tuple[McpToolDefinition, ...]:
|
|
236
|
+
"""构建 7 个只读、隐私脱敏、同时兼容单仓与多仓的 MCP 工具."""
|
|
237
|
+
|
|
238
|
+
def handle_workspace_overview(args: dict[str, Any]) -> dict[str, Any]:
|
|
239
|
+
target_dir = sandbox.resolve_directory(_optional_str(args, "targetDir"))
|
|
240
|
+
if _is_portfolio_dir(target_dir):
|
|
241
|
+
status = get_portfolio_status(target_dir)
|
|
242
|
+
return {"mode": "PORTFOLIO", **status}
|
|
243
|
+
return _sanitize_single_repo_status(target_dir)
|
|
244
|
+
|
|
245
|
+
def handle_portfolio_status(args: dict[str, Any]) -> dict[str, Any]:
|
|
246
|
+
target_dir = sandbox.resolve_directory(
|
|
247
|
+
_optional_str(args, "portfolioDir") or _optional_str(args, "targetDir")
|
|
248
|
+
)
|
|
249
|
+
if _is_portfolio_dir(target_dir):
|
|
250
|
+
return get_portfolio_status(target_dir)
|
|
251
|
+
return _sanitize_single_repo_status(target_dir)
|
|
252
|
+
|
|
253
|
+
def handle_portfolio_summary(args: dict[str, Any]) -> dict[str, Any]:
|
|
254
|
+
target_dir = sandbox.resolve_directory(
|
|
255
|
+
_optional_str(args, "portfolioDir") or _optional_str(args, "targetDir")
|
|
256
|
+
)
|
|
257
|
+
person = _resolve_target_person(target_dir, _optional_str(args, "person"))
|
|
258
|
+
since_dt, until_dt = parse_boundaries(
|
|
259
|
+
_optional_str(args, "since"),
|
|
260
|
+
_optional_str(args, "until"),
|
|
261
|
+
)
|
|
262
|
+
if _is_portfolio_dir(target_dir):
|
|
263
|
+
result = assess_portfolio(
|
|
264
|
+
target_dir,
|
|
265
|
+
person_selector=person,
|
|
266
|
+
filters=AnalysisFilters(since=since_dt, until=until_dt),
|
|
267
|
+
refresh=False,
|
|
268
|
+
)
|
|
269
|
+
return {
|
|
270
|
+
"scope": "PORTFOLIO",
|
|
271
|
+
"runId": result["runId"],
|
|
272
|
+
"status": result["status"],
|
|
273
|
+
"failed": result["failed"],
|
|
274
|
+
"report": _sanitize_portfolio_summary(result["report"]),
|
|
275
|
+
}
|
|
276
|
+
assessment = assess_work(
|
|
277
|
+
target_dir,
|
|
278
|
+
person_selectors=(person,),
|
|
279
|
+
filters=AnalysisFilters(since=since_dt, until=until_dt),
|
|
280
|
+
llm_provider=None,
|
|
281
|
+
)
|
|
282
|
+
return {
|
|
283
|
+
"scope": "REPOSITORY",
|
|
284
|
+
"runId": assessment.get("runId"),
|
|
285
|
+
"status": "COMPLETED",
|
|
286
|
+
"failed": [],
|
|
287
|
+
"report": _sanitize_single_repo_assessment(assessment),
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
def handle_get_evidence(args: dict[str, Any]) -> dict[str, Any]:
|
|
291
|
+
target_dir = sandbox.resolve_directory(_optional_str(args, "targetDir"))
|
|
292
|
+
evidence_id = _optional_str(args, "evidenceId")
|
|
293
|
+
query = _optional_str(args, "query")
|
|
294
|
+
raw_limit = args.get("limit", 25)
|
|
295
|
+
if not isinstance(raw_limit, int) or raw_limit < 1 or raw_limit > 200:
|
|
296
|
+
raise ValueError("Parameter limit must be an integer between 1 and 200")
|
|
297
|
+
|
|
298
|
+
records: list[dict[str, Any]] = []
|
|
299
|
+
scope = "REPOSITORY"
|
|
300
|
+
if _is_portfolio_dir(target_dir):
|
|
301
|
+
scope = "PORTFOLIO"
|
|
302
|
+
store = FilePortfolioStore(target_dir)
|
|
303
|
+
manifest = store.load_manifest()
|
|
304
|
+
for repo in manifest.repositories:
|
|
305
|
+
repo_path = store.resolve_repo_path(repo)
|
|
306
|
+
if repo_path.is_dir():
|
|
307
|
+
records.extend(
|
|
308
|
+
_collect_repo_evidence(repo.repo_key, repo_path, qualify=True)
|
|
309
|
+
)
|
|
310
|
+
else:
|
|
311
|
+
records.extend(
|
|
312
|
+
_collect_repo_evidence(target_dir.name, target_dir, qualify=False)
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
filtered = records
|
|
316
|
+
if evidence_id is not None:
|
|
317
|
+
target_low = evidence_id.lower()
|
|
318
|
+
filtered = [
|
|
319
|
+
item
|
|
320
|
+
for item in filtered
|
|
321
|
+
if str(item["evidenceId"]).lower() == target_low
|
|
322
|
+
or str(item["evidenceId"]).lower().endswith(f":{target_low}")
|
|
323
|
+
]
|
|
324
|
+
if query is not None:
|
|
325
|
+
q_low = query.lower()
|
|
326
|
+
filtered = [
|
|
327
|
+
item
|
|
328
|
+
for item in filtered
|
|
329
|
+
if q_low in str(item.get("summary") or "").lower()
|
|
330
|
+
or q_low in str(item.get("repoKey") or "").lower()
|
|
331
|
+
or any(q_low in str(p).lower() for p in item.get("paths", []))
|
|
332
|
+
]
|
|
333
|
+
|
|
334
|
+
return {
|
|
335
|
+
"scope": scope,
|
|
336
|
+
"totalMatched": len(filtered),
|
|
337
|
+
"evidence": filtered[:raw_limit],
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
def handle_generate_recap(args: dict[str, Any]) -> dict[str, Any]:
|
|
341
|
+
target_dir = sandbox.resolve_directory(_optional_str(args, "targetDir"))
|
|
342
|
+
person = _resolve_target_person(target_dir, _optional_str(args, "person"))
|
|
343
|
+
window = _optional_str(args, "window")
|
|
344
|
+
since_dt, until_dt = parse_boundaries(
|
|
345
|
+
_optional_str(args, "since"),
|
|
346
|
+
_optional_str(args, "until"),
|
|
347
|
+
)
|
|
348
|
+
language = _optional_str(args, "language") or "zh-CN"
|
|
349
|
+
|
|
350
|
+
if _is_portfolio_dir(target_dir):
|
|
351
|
+
res = generate_portfolio_recap(
|
|
352
|
+
target_dir,
|
|
353
|
+
person_selector=person,
|
|
354
|
+
window=window,
|
|
355
|
+
since=since_dt,
|
|
356
|
+
until=until_dt,
|
|
357
|
+
refresh=False,
|
|
358
|
+
)
|
|
359
|
+
report = res["report"]
|
|
360
|
+
return {
|
|
361
|
+
"runId": res["runId"],
|
|
362
|
+
"status": res["status"],
|
|
363
|
+
"report": report,
|
|
364
|
+
"markdown": render_recap_markdown(report, language=language),
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
res = generate_recap(
|
|
368
|
+
target_dir,
|
|
369
|
+
person_selector=person,
|
|
370
|
+
window=window,
|
|
371
|
+
since=since_dt,
|
|
372
|
+
until=until_dt,
|
|
373
|
+
)
|
|
374
|
+
report = res["report"]
|
|
375
|
+
return {
|
|
376
|
+
"report": report,
|
|
377
|
+
"markdown": render_recap_markdown(report, language=language),
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
def handle_generate_portfolio_resume(args: dict[str, Any]) -> dict[str, Any]:
|
|
381
|
+
target_dir = sandbox.resolve_directory(
|
|
382
|
+
_optional_str(args, "portfolioDir") or _optional_str(args, "targetDir")
|
|
383
|
+
)
|
|
384
|
+
person = _resolve_target_person(target_dir, _optional_str(args, "person"))
|
|
385
|
+
target_role = _optional_str(args, "targetRole") or ""
|
|
386
|
+
language = _optional_str(args, "language") or "zh-CN"
|
|
387
|
+
style = _optional_str(args, "style") or "star"
|
|
388
|
+
max_bullets = args.get("maxBulletsPerGroup", 6)
|
|
389
|
+
if not isinstance(max_bullets, int) or max_bullets < 1 or max_bullets > 20:
|
|
390
|
+
raise ValueError("Parameter maxBulletsPerGroup must be an integer between 1 and 20")
|
|
391
|
+
include_pending = bool(args.get("includePending", False))
|
|
392
|
+
since_dt, until_dt = parse_boundaries(
|
|
393
|
+
_optional_str(args, "since"),
|
|
394
|
+
_optional_str(args, "until"),
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
if _is_portfolio_dir(target_dir):
|
|
398
|
+
res = generate_portfolio_resume(
|
|
399
|
+
target_dir,
|
|
400
|
+
person_selector=person,
|
|
401
|
+
filters=AnalysisFilters(since=since_dt, until=until_dt),
|
|
402
|
+
target_role=target_role,
|
|
403
|
+
language=language,
|
|
404
|
+
style=style,
|
|
405
|
+
max_bullets_per_group=max_bullets,
|
|
406
|
+
include_pending=include_pending,
|
|
407
|
+
refresh=False,
|
|
408
|
+
)
|
|
409
|
+
report = res["report"]
|
|
410
|
+
return {
|
|
411
|
+
"scope": "PORTFOLIO",
|
|
412
|
+
"runId": res["runId"],
|
|
413
|
+
"status": res["status"],
|
|
414
|
+
"report": report,
|
|
415
|
+
"markdown": render_portfolio_resume_markdown(report),
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
single_report = generate_resume(
|
|
419
|
+
target_dir,
|
|
420
|
+
person_selector=person,
|
|
421
|
+
filters=AnalysisFilters(since=since_dt, until=until_dt),
|
|
422
|
+
target_role=target_role,
|
|
423
|
+
language=language,
|
|
424
|
+
style=style,
|
|
425
|
+
max_bullets=max_bullets,
|
|
426
|
+
include_pending=include_pending,
|
|
427
|
+
llm_provider=None,
|
|
428
|
+
)
|
|
429
|
+
sanitized_single = dict(single_report)
|
|
430
|
+
sanitized_single.pop("repository", None)
|
|
431
|
+
return {
|
|
432
|
+
"scope": "REPOSITORY",
|
|
433
|
+
"runId": single_report.get("runId"),
|
|
434
|
+
"status": "COMPLETED",
|
|
435
|
+
"report": sanitized_single,
|
|
436
|
+
"markdown": render_resume_markdown(single_report),
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
def handle_verify_citations(args: dict[str, Any]) -> dict[str, Any]:
|
|
440
|
+
target_dir = sandbox.resolve_directory(
|
|
441
|
+
_optional_str(args, "portfolioDir") or _optional_str(args, "targetDir")
|
|
442
|
+
)
|
|
443
|
+
markdown_text = _require_str(args, "markdownText")
|
|
444
|
+
run_id = _optional_str(args, "runId")
|
|
445
|
+
|
|
446
|
+
if not _is_portfolio_dir(target_dir):
|
|
447
|
+
return _verify_single_repo_markdown(target_dir, markdown_text)
|
|
448
|
+
|
|
449
|
+
evidence_index = _collect_evidence_index(target_dir)
|
|
450
|
+
md_check = verify_portfolio_markdown_references(markdown_text, evidence_index)
|
|
451
|
+
issues: list[dict[str, Any]] = [
|
|
452
|
+
{"code": i.code, "message": i.message, "location": i.location}
|
|
453
|
+
for i in md_check.issues
|
|
454
|
+
]
|
|
455
|
+
checked_refs = md_check.checked_evidence_references
|
|
456
|
+
|
|
457
|
+
if run_id is not None:
|
|
458
|
+
run_check = verify_portfolio(
|
|
459
|
+
target_dir,
|
|
460
|
+
run_id=run_id,
|
|
461
|
+
evidence_index_override=evidence_index,
|
|
462
|
+
)
|
|
463
|
+
checked_refs += int(run_check.get("checkedEvidenceReferences", 0))
|
|
464
|
+
issues.extend(run_check.get("issues", []))
|
|
465
|
+
|
|
466
|
+
return {
|
|
467
|
+
"ok": not issues,
|
|
468
|
+
"scope": "PORTFOLIO",
|
|
469
|
+
"checkedEvidenceReferences": checked_refs,
|
|
470
|
+
"issues": issues,
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
return (
|
|
474
|
+
McpToolDefinition(
|
|
475
|
+
name="gca_workspace_overview",
|
|
476
|
+
description=(
|
|
477
|
+
"Read-only inspection of either a single Git repository or a GCA portfolio "
|
|
478
|
+
"inside allowed roots (auto-detects mode, omits host absolute paths)."
|
|
479
|
+
),
|
|
480
|
+
input_schema={
|
|
481
|
+
"type": "object",
|
|
482
|
+
"properties": {
|
|
483
|
+
"targetDir": {
|
|
484
|
+
"type": "string",
|
|
485
|
+
"description": (
|
|
486
|
+
"Optional repository or portfolio directory "
|
|
487
|
+
"(defaults to first allowed root)."
|
|
488
|
+
),
|
|
489
|
+
}
|
|
490
|
+
},
|
|
491
|
+
"additionalProperties": False,
|
|
492
|
+
},
|
|
493
|
+
handler=handle_workspace_overview,
|
|
494
|
+
),
|
|
495
|
+
McpToolDefinition(
|
|
496
|
+
name="gca_portfolio_status",
|
|
497
|
+
description=(
|
|
498
|
+
"Read-only inspection of a GCA portfolio or single repository workspace: "
|
|
499
|
+
"index health and persisted runs without exposing host paths."
|
|
500
|
+
),
|
|
501
|
+
input_schema={
|
|
502
|
+
"type": "object",
|
|
503
|
+
"properties": {
|
|
504
|
+
"portfolioDir": {
|
|
505
|
+
"type": "string",
|
|
506
|
+
"description": (
|
|
507
|
+
"Path to portfolio or repository workspace inside allowed roots."
|
|
508
|
+
),
|
|
509
|
+
},
|
|
510
|
+
"targetDir": {
|
|
511
|
+
"type": "string",
|
|
512
|
+
"description": (
|
|
513
|
+
"Alias for portfolioDir when inspecting a single repository."
|
|
514
|
+
),
|
|
515
|
+
},
|
|
516
|
+
},
|
|
517
|
+
"additionalProperties": False,
|
|
518
|
+
},
|
|
519
|
+
handler=handle_portfolio_status,
|
|
520
|
+
),
|
|
521
|
+
McpToolDefinition(
|
|
522
|
+
name="gca_portfolio_summary",
|
|
523
|
+
description=(
|
|
524
|
+
"Generate a deterministic contribution summary for a portfolio or single "
|
|
525
|
+
"repository (no raw emails, no source diffs; person defaults to local git user)."
|
|
526
|
+
),
|
|
527
|
+
input_schema={
|
|
528
|
+
"type": "object",
|
|
529
|
+
"properties": {
|
|
530
|
+
"portfolioDir": {"type": "string"},
|
|
531
|
+
"targetDir": {"type": "string"},
|
|
532
|
+
"person": {"type": "string"},
|
|
533
|
+
"since": {"type": "string"},
|
|
534
|
+
"until": {"type": "string"},
|
|
535
|
+
},
|
|
536
|
+
"additionalProperties": False,
|
|
537
|
+
},
|
|
538
|
+
handler=handle_portfolio_summary,
|
|
539
|
+
),
|
|
540
|
+
McpToolDefinition(
|
|
541
|
+
name="gca_get_evidence",
|
|
542
|
+
description=(
|
|
543
|
+
"Look up deterministic evidence records (EV-xxx or <repoKey>:EV-xxx) from "
|
|
544
|
+
"indexed repository or portfolio runs without exposing source code diffs."
|
|
545
|
+
),
|
|
546
|
+
input_schema={
|
|
547
|
+
"type": "object",
|
|
548
|
+
"properties": {
|
|
549
|
+
"targetDir": {"type": "string"},
|
|
550
|
+
"evidenceId": {"type": "string"},
|
|
551
|
+
"query": {"type": "string"},
|
|
552
|
+
"limit": {"type": "integer", "minimum": 1, "maximum": 200},
|
|
553
|
+
},
|
|
554
|
+
"additionalProperties": False,
|
|
555
|
+
},
|
|
556
|
+
handler=handle_get_evidence,
|
|
557
|
+
),
|
|
558
|
+
McpToolDefinition(
|
|
559
|
+
name="gca_generate_recap",
|
|
560
|
+
description=(
|
|
561
|
+
"Generate a daily/weekly/monthly/quarterly recap (today, yesterday, 1d, 7d, "
|
|
562
|
+
"14d, 30d, week, month, quarter) for a repository or portfolio with period deltas."
|
|
563
|
+
),
|
|
564
|
+
input_schema={
|
|
565
|
+
"type": "object",
|
|
566
|
+
"properties": {
|
|
567
|
+
"targetDir": {"type": "string"},
|
|
568
|
+
"person": {"type": "string"},
|
|
569
|
+
"window": {"type": "string"},
|
|
570
|
+
"since": {"type": "string"},
|
|
571
|
+
"until": {"type": "string"},
|
|
572
|
+
"language": {"type": "string"},
|
|
573
|
+
},
|
|
574
|
+
"additionalProperties": False,
|
|
575
|
+
},
|
|
576
|
+
handler=handle_generate_recap,
|
|
577
|
+
),
|
|
578
|
+
McpToolDefinition(
|
|
579
|
+
name="gca_generate_portfolio_resume",
|
|
580
|
+
description=(
|
|
581
|
+
"Generate an evidence-backed resume for a portfolio or single repository "
|
|
582
|
+
"with strict claim-strength ceilings and no raw emails."
|
|
583
|
+
),
|
|
584
|
+
input_schema={
|
|
585
|
+
"type": "object",
|
|
586
|
+
"properties": {
|
|
587
|
+
"portfolioDir": {"type": "string"},
|
|
588
|
+
"targetDir": {"type": "string"},
|
|
589
|
+
"person": {"type": "string"},
|
|
590
|
+
"targetRole": {"type": "string"},
|
|
591
|
+
"language": {"type": "string"},
|
|
592
|
+
"style": {"type": "string"},
|
|
593
|
+
"maxBulletsPerGroup": {"type": "integer", "minimum": 1, "maximum": 20},
|
|
594
|
+
"includePending": {"type": "boolean"},
|
|
595
|
+
"since": {"type": "string"},
|
|
596
|
+
"until": {"type": "string"},
|
|
597
|
+
},
|
|
598
|
+
"additionalProperties": False,
|
|
599
|
+
},
|
|
600
|
+
handler=handle_generate_portfolio_resume,
|
|
601
|
+
),
|
|
602
|
+
McpToolDefinition(
|
|
603
|
+
name="gca_verify_citations",
|
|
604
|
+
description=(
|
|
605
|
+
"Verify that all evidence references in a markdown draft match persisted "
|
|
606
|
+
"portfolio (<repoKey>:EV-xxx) or single-repository (EV-xxx) evidence."
|
|
607
|
+
),
|
|
608
|
+
input_schema={
|
|
609
|
+
"type": "object",
|
|
610
|
+
"required": ["markdownText"],
|
|
611
|
+
"properties": {
|
|
612
|
+
"portfolioDir": {"type": "string"},
|
|
613
|
+
"targetDir": {"type": "string"},
|
|
614
|
+
"markdownText": {"type": "string"},
|
|
615
|
+
"runId": {"type": "string"},
|
|
616
|
+
},
|
|
617
|
+
"additionalProperties": False,
|
|
618
|
+
},
|
|
619
|
+
handler=handle_verify_citations,
|
|
620
|
+
),
|
|
621
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Adapters for human-verified external outcomes."""
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import date
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import yaml
|
|
7
|
+
from pydantic import BaseModel, ConfigDict, Field, ValidationError
|
|
8
|
+
|
|
9
|
+
from git_contribution_analyzer.domain.errors import ConfigurationError
|
|
10
|
+
from git_contribution_analyzer.domain.models.resume import VerifiedOutcome
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class _Outcome(BaseModel):
|
|
14
|
+
model_config = ConfigDict(extra="forbid", populate_by_name=True)
|
|
15
|
+
|
|
16
|
+
id: str = Field(min_length=1)
|
|
17
|
+
text: str = Field(min_length=1)
|
|
18
|
+
source: str = Field(min_length=1)
|
|
19
|
+
verified_by: str = Field(alias="verifiedBy", min_length=1)
|
|
20
|
+
verified_at: date = Field(alias="verifiedAt")
|
|
21
|
+
kind: str = "OUTCOME"
|
|
22
|
+
evidence_ids: list[str] = Field(default_factory=list, alias="evidenceIds")
|
|
23
|
+
tags: list[str] = Field(default_factory=list)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class _OutcomeFile(BaseModel):
|
|
27
|
+
model_config = ConfigDict(extra="forbid")
|
|
28
|
+
|
|
29
|
+
outcomes: list[_Outcome]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def load_verified_outcomes(path: Path) -> tuple[VerifiedOutcome, ...]:
|
|
33
|
+
try:
|
|
34
|
+
payload = yaml.safe_load(path.read_text(encoding="utf-8")) or {}
|
|
35
|
+
parsed = _OutcomeFile.model_validate(payload)
|
|
36
|
+
except (OSError, yaml.YAMLError, ValidationError, ValueError) as exc:
|
|
37
|
+
raise ConfigurationError(f"Invalid verified outcomes file: {path}") from exc
|
|
38
|
+
ids = [entry.id for entry in parsed.outcomes]
|
|
39
|
+
if len(ids) != len(set(ids)):
|
|
40
|
+
raise ConfigurationError("Verified outcome IDs must be unique")
|
|
41
|
+
return tuple(
|
|
42
|
+
VerifiedOutcome(
|
|
43
|
+
id=entry.id,
|
|
44
|
+
text=entry.text,
|
|
45
|
+
source=entry.source,
|
|
46
|
+
verified_by=entry.verified_by,
|
|
47
|
+
verified_at=entry.verified_at,
|
|
48
|
+
kind=entry.kind.upper(),
|
|
49
|
+
evidence_ids=tuple(
|
|
50
|
+
item.strip() for item in entry.evidence_ids if item and item.strip()
|
|
51
|
+
),
|
|
52
|
+
tags=tuple(tag.strip() for tag in entry.tags if tag and tag.strip()),
|
|
53
|
+
)
|
|
54
|
+
for entry in parsed.outcomes
|
|
55
|
+
)
|