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,117 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import shutil
|
|
5
|
+
from collections.abc import Mapping
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from git_contribution_analyzer.adapters.llm.anthropic import AnthropicProvider
|
|
10
|
+
from git_contribution_analyzer.adapters.llm.claude_cli import ClaudeCliProvider
|
|
11
|
+
from git_contribution_analyzer.adapters.llm.codex_cli import CodexCliProvider
|
|
12
|
+
from git_contribution_analyzer.adapters.llm.mock import MockLlmProvider
|
|
13
|
+
from git_contribution_analyzer.adapters.llm.ollama import OllamaProvider
|
|
14
|
+
from git_contribution_analyzer.adapters.llm.openai_compatible import (
|
|
15
|
+
OpenAiCompatibleProvider,
|
|
16
|
+
)
|
|
17
|
+
from git_contribution_analyzer.adapters.workspace.config import LlmConfig
|
|
18
|
+
from git_contribution_analyzer.application.ports.llm import LlmProvider
|
|
19
|
+
from git_contribution_analyzer.domain.errors import ConfigurationError
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True, slots=True)
|
|
23
|
+
class ProviderDescriptor:
|
|
24
|
+
provider_id: str
|
|
25
|
+
local_execution: bool
|
|
26
|
+
requires_api_key: bool
|
|
27
|
+
default_base_url: str
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
PROVIDERS = (
|
|
31
|
+
ProviderDescriptor("mock", True, False, "local"),
|
|
32
|
+
ProviderDescriptor("openai-compatible", False, True, "https://api.openai.com/v1"),
|
|
33
|
+
ProviderDescriptor("anthropic", False, True, "https://api.anthropic.com"),
|
|
34
|
+
ProviderDescriptor("ollama", True, False, "http://127.0.0.1:11434"),
|
|
35
|
+
ProviderDescriptor("codex-cli", True, False, "local-command"),
|
|
36
|
+
ProviderDescriptor("claude-cli", True, False, "local-command"),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def provider_descriptors() -> tuple[ProviderDescriptor, ...]:
|
|
41
|
+
return PROVIDERS
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def build_provider(
|
|
45
|
+
config: LlmConfig,
|
|
46
|
+
*,
|
|
47
|
+
environ: Mapping[str, str] | None = None,
|
|
48
|
+
) -> LlmProvider:
|
|
49
|
+
env = os.environ if environ is None else environ
|
|
50
|
+
provider_id = env.get("GCA_LLM_PROVIDER", config.provider).strip().lower()
|
|
51
|
+
model = env.get("GCA_LLM_MODEL", config.model).strip()
|
|
52
|
+
base_url = env.get("GCA_LLM_BASE_URL", config.base_url or "").strip()
|
|
53
|
+
descriptor = next(
|
|
54
|
+
(candidate for candidate in PROVIDERS if candidate.provider_id == provider_id), None
|
|
55
|
+
)
|
|
56
|
+
if descriptor is None:
|
|
57
|
+
supported = ", ".join(item.provider_id for item in PROVIDERS)
|
|
58
|
+
raise ConfigurationError(
|
|
59
|
+
f"Unsupported LLM provider '{provider_id}'. Supported providers: {supported}"
|
|
60
|
+
)
|
|
61
|
+
resolved_base_url = base_url or descriptor.default_base_url
|
|
62
|
+
if provider_id == "mock":
|
|
63
|
+
return MockLlmProvider()
|
|
64
|
+
if provider_id == "ollama":
|
|
65
|
+
return OllamaProvider(
|
|
66
|
+
model=model,
|
|
67
|
+
base_url=resolved_base_url,
|
|
68
|
+
timeout_seconds=config.timeout_seconds,
|
|
69
|
+
max_retries=config.max_retries,
|
|
70
|
+
)
|
|
71
|
+
if provider_id in ("codex-cli", "claude-cli"):
|
|
72
|
+
executable_name = "codex" if provider_id == "codex-cli" else "claude"
|
|
73
|
+
configured_executable = env.get("GCA_LLM_EXECUTABLE") or config.executable
|
|
74
|
+
discovered_executable = shutil.which(executable_name) or executable_name
|
|
75
|
+
executable = configured_executable or _prefer_native_command(
|
|
76
|
+
provider_id, discovered_executable
|
|
77
|
+
)
|
|
78
|
+
command_model = "configured-default" if model == "deterministic" else model
|
|
79
|
+
provider_type = CodexCliProvider if provider_id == "codex-cli" else ClaudeCliProvider
|
|
80
|
+
return provider_type(
|
|
81
|
+
executable=executable,
|
|
82
|
+
model=command_model,
|
|
83
|
+
timeout_seconds=config.command_timeout_seconds,
|
|
84
|
+
)
|
|
85
|
+
api_key = env.get(config.api_key_env, "")
|
|
86
|
+
if not api_key:
|
|
87
|
+
raise ConfigurationError(
|
|
88
|
+
f"LLM provider '{provider_id}' requires environment variable "
|
|
89
|
+
f"{config.api_key_env}"
|
|
90
|
+
)
|
|
91
|
+
if provider_id == "anthropic":
|
|
92
|
+
return AnthropicProvider(
|
|
93
|
+
model=model,
|
|
94
|
+
base_url=resolved_base_url,
|
|
95
|
+
api_key=api_key,
|
|
96
|
+
timeout_seconds=config.timeout_seconds,
|
|
97
|
+
max_retries=config.max_retries,
|
|
98
|
+
)
|
|
99
|
+
return OpenAiCompatibleProvider(
|
|
100
|
+
model=model,
|
|
101
|
+
base_url=resolved_base_url,
|
|
102
|
+
api_key=api_key,
|
|
103
|
+
timeout_seconds=config.timeout_seconds,
|
|
104
|
+
max_retries=config.max_retries,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _prefer_native_command(provider_id: str, executable: str) -> str:
|
|
109
|
+
path = Path(executable)
|
|
110
|
+
if provider_id != "codex-cli" or path.name.casefold() != "codex.cmd":
|
|
111
|
+
return executable
|
|
112
|
+
pattern = (
|
|
113
|
+
"node_modules/@openai/codex/node_modules/@openai/"
|
|
114
|
+
"codex-win32-*/vendor/*/bin/codex.exe"
|
|
115
|
+
)
|
|
116
|
+
candidates = sorted(path.parent.glob(pattern))
|
|
117
|
+
return str(candidates[0]) if candidates else executable
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from git_contribution_analyzer.adapters.mcp.protocol import McpProtocolHandler, McpToolDefinition
|
|
4
|
+
from git_contribution_analyzer.adapters.mcp.server import run_stdio_server
|
|
5
|
+
from git_contribution_analyzer.adapters.mcp.tools import WorkspaceSandbox, build_readonly_tools
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"McpProtocolHandler",
|
|
9
|
+
"McpToolDefinition",
|
|
10
|
+
"WorkspaceSandbox",
|
|
11
|
+
"build_readonly_tools",
|
|
12
|
+
"run_stdio_server",
|
|
13
|
+
]
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
import shutil
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from datetime import UTC, datetime
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from git_contribution_analyzer.domain.errors import ConfigurationError
|
|
12
|
+
|
|
13
|
+
SUPPORTED_AGENT_TARGETS = ("antigravity", "codex", "claude", "cursor")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True, slots=True)
|
|
17
|
+
class AgentInstallResult:
|
|
18
|
+
target: str
|
|
19
|
+
config_path: Path
|
|
20
|
+
config_format: str
|
|
21
|
+
applied: bool
|
|
22
|
+
backup_path: Path | None
|
|
23
|
+
snippet: str
|
|
24
|
+
workspaces: tuple[str, ...]
|
|
25
|
+
|
|
26
|
+
def to_dict(self) -> dict[str, Any]:
|
|
27
|
+
return {
|
|
28
|
+
"target": self.target,
|
|
29
|
+
"configPath": str(self.config_path),
|
|
30
|
+
"configFormat": self.config_format,
|
|
31
|
+
"applied": self.applied,
|
|
32
|
+
"backupPath": str(self.backup_path) if self.backup_path is not None else None,
|
|
33
|
+
"snippet": self.snippet,
|
|
34
|
+
"workspaces": list(self.workspaces),
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def default_config_path(target: str, *, home_dir: Path | None = None) -> Path:
|
|
39
|
+
home = (home_dir or Path.home()).expanduser().resolve()
|
|
40
|
+
key = target.strip().lower()
|
|
41
|
+
if key == "antigravity":
|
|
42
|
+
return home / ".gemini" / "antigravity" / "mcp_config.json"
|
|
43
|
+
if key == "claude":
|
|
44
|
+
return home / ".claude.json"
|
|
45
|
+
if key == "cursor":
|
|
46
|
+
return home / ".cursor" / "mcp.json"
|
|
47
|
+
if key == "codex":
|
|
48
|
+
return home / ".codex" / "config.toml"
|
|
49
|
+
supported = ", ".join(SUPPORTED_AGENT_TARGETS)
|
|
50
|
+
raise ConfigurationError(f"Unsupported agent target {target!r}; expected one of: {supported}")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _build_args(workspaces: tuple[Path, ...]) -> list[str]:
|
|
54
|
+
args = ["serve", "--mcp"]
|
|
55
|
+
for ws in workspaces:
|
|
56
|
+
args.extend(["--workspace", str(ws)])
|
|
57
|
+
return args
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _render_json_snippet(command: str, args: list[str]) -> str:
|
|
61
|
+
snippet_obj = {
|
|
62
|
+
"mcpServers": {
|
|
63
|
+
"gca": {
|
|
64
|
+
"command": command,
|
|
65
|
+
"args": args,
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return json.dumps(snippet_obj, ensure_ascii=False, indent=2) + "\n"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _render_toml_snippet(command: str, args: list[str]) -> str:
|
|
73
|
+
escaped_cmd = json.dumps(command, ensure_ascii=False)
|
|
74
|
+
escaped_args = ", ".join(json.dumps(item, ensure_ascii=False) for item in args)
|
|
75
|
+
return f"[mcp_servers.gca]\ncommand = {escaped_cmd}\nargs = [{escaped_args}]\n"
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _merge_json_config(existing_text: str, command: str, args: list[str]) -> str:
|
|
79
|
+
if existing_text.strip():
|
|
80
|
+
try:
|
|
81
|
+
data = json.loads(existing_text)
|
|
82
|
+
except json.JSONDecodeError as exc:
|
|
83
|
+
raise ConfigurationError(
|
|
84
|
+
f"Existing MCP config is not valid JSON: {exc.msg}"
|
|
85
|
+
) from exc
|
|
86
|
+
if not isinstance(data, dict):
|
|
87
|
+
raise ConfigurationError("Existing MCP JSON config root must be an object")
|
|
88
|
+
else:
|
|
89
|
+
data = {}
|
|
90
|
+
|
|
91
|
+
servers = data.get("mcpServers")
|
|
92
|
+
if servers is None:
|
|
93
|
+
servers = {}
|
|
94
|
+
data["mcpServers"] = servers
|
|
95
|
+
elif not isinstance(servers, dict):
|
|
96
|
+
raise ConfigurationError("Existing 'mcpServers' entry must be a JSON object")
|
|
97
|
+
|
|
98
|
+
servers["gca"] = {"command": command, "args": args}
|
|
99
|
+
return json.dumps(data, ensure_ascii=False, indent=2) + "\n"
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _merge_toml_config(existing_text: str, snippet: str) -> str:
|
|
103
|
+
section_re = re.compile(
|
|
104
|
+
r"(?ms)^\[mcp_servers\.gca\]\s*\n.*?(?=^\[|\Z)",
|
|
105
|
+
)
|
|
106
|
+
if section_re.search(existing_text):
|
|
107
|
+
updated = section_re.sub(snippet, existing_text, count=1)
|
|
108
|
+
return updated if updated.endswith("\n") else updated + "\n"
|
|
109
|
+
base = existing_text.rstrip()
|
|
110
|
+
if not base:
|
|
111
|
+
return snippet
|
|
112
|
+
return f"{base}\n\n{snippet}"
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def install_agent_mcp_config(
|
|
116
|
+
*,
|
|
117
|
+
target: str,
|
|
118
|
+
workspaces: tuple[Path, ...],
|
|
119
|
+
command: str = "gca",
|
|
120
|
+
config_path: Path | None = None,
|
|
121
|
+
apply: bool = False,
|
|
122
|
+
home_dir: Path | None = None,
|
|
123
|
+
) -> AgentInstallResult:
|
|
124
|
+
"""生成或安全合并 Antigravity / Codex / Claude / Cursor 的 GCA MCP 配置."""
|
|
125
|
+
key = target.strip().lower()
|
|
126
|
+
if key not in SUPPORTED_AGENT_TARGETS:
|
|
127
|
+
supported = ", ".join(SUPPORTED_AGENT_TARGETS)
|
|
128
|
+
raise ConfigurationError(
|
|
129
|
+
f"Unsupported agent target {target!r}; expected one of: {supported}"
|
|
130
|
+
)
|
|
131
|
+
if not workspaces:
|
|
132
|
+
raise ConfigurationError("At least one --workspace directory is required")
|
|
133
|
+
|
|
134
|
+
resolved_workspaces = tuple(ws.expanduser().resolve() for ws in workspaces)
|
|
135
|
+
resolved_target = (
|
|
136
|
+
config_path.expanduser().resolve()
|
|
137
|
+
if config_path is not None
|
|
138
|
+
else default_config_path(key, home_dir=home_dir)
|
|
139
|
+
)
|
|
140
|
+
args = _build_args(resolved_workspaces)
|
|
141
|
+
is_toml = key == "codex"
|
|
142
|
+
snippet = (
|
|
143
|
+
_render_toml_snippet(command, args)
|
|
144
|
+
if is_toml
|
|
145
|
+
else _render_json_snippet(command, args)
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
backup_path: Path | None = None
|
|
149
|
+
if apply:
|
|
150
|
+
resolved_target.parent.mkdir(parents=True, exist_ok=True)
|
|
151
|
+
existing_text = ""
|
|
152
|
+
if resolved_target.is_file():
|
|
153
|
+
stamp = datetime.now(UTC).strftime("%Y%m%d%H%M%S")
|
|
154
|
+
backup_path = resolved_target.with_name(
|
|
155
|
+
f"{resolved_target.name}.gca-backup-{stamp}"
|
|
156
|
+
)
|
|
157
|
+
shutil.copy2(resolved_target, backup_path)
|
|
158
|
+
existing_text = resolved_target.read_text(encoding="utf-8")
|
|
159
|
+
|
|
160
|
+
merged = (
|
|
161
|
+
_merge_toml_config(existing_text, snippet)
|
|
162
|
+
if is_toml
|
|
163
|
+
else _merge_json_config(existing_text, command, args)
|
|
164
|
+
)
|
|
165
|
+
resolved_target.write_text(merged, encoding="utf-8", newline="\n")
|
|
166
|
+
|
|
167
|
+
return AgentInstallResult(
|
|
168
|
+
target=key,
|
|
169
|
+
config_path=resolved_target,
|
|
170
|
+
config_format="toml" if is_toml else "json",
|
|
171
|
+
applied=apply,
|
|
172
|
+
backup_path=backup_path,
|
|
173
|
+
snippet=snippet,
|
|
174
|
+
workspaces=tuple(str(ws) for ws in resolved_workspaces),
|
|
175
|
+
)
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from git_contribution_analyzer.adapters.mcp.protocol import (
|
|
7
|
+
McpPromptArgument,
|
|
8
|
+
McpPromptDefinition,
|
|
9
|
+
McpResourceDefinition,
|
|
10
|
+
)
|
|
11
|
+
from git_contribution_analyzer.adapters.mcp.tools import WorkspaceSandbox
|
|
12
|
+
from git_contribution_analyzer.adapters.workspace.layout import WorkspaceLayout
|
|
13
|
+
from git_contribution_analyzer.adapters.workspace.portfolio_workspace import FilePortfolioStore
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _user_message(text: str) -> list[dict[str, Any]]:
|
|
17
|
+
return [{"role": "user", "content": {"type": "text", "text": text}}]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def build_readonly_prompts() -> tuple[McpPromptDefinition, ...]:
|
|
21
|
+
"""构建 4 个开箱即用的防幻觉工程记忆 MCP Prompts."""
|
|
22
|
+
|
|
23
|
+
def standup_recap(args: dict[str, str]) -> list[dict[str, Any]]:
|
|
24
|
+
target = args.get("targetDir") or "."
|
|
25
|
+
window = args.get("window") or "today"
|
|
26
|
+
lang = args.get("language") or "zh-CN"
|
|
27
|
+
person_hint = f" for `{args['person']}`" if args.get("person") else ""
|
|
28
|
+
return _user_message(
|
|
29
|
+
f"Use `gca_generate_recap` on `{target}` with window=`{window}` and "
|
|
30
|
+
f"language=`{lang}`{person_hint}. Summarize delivered highlights (LANDED/RELEASED) "
|
|
31
|
+
"separately from pending unmerged branches (AUTHORED_ONLY). Cite every bullet with "
|
|
32
|
+
"its exact `EV-xxx` or `<repoKey>:EV-xxx` evidence ID and never invent metrics."
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
def weekly_report(args: dict[str, str]) -> list[dict[str, Any]]:
|
|
36
|
+
target = args.get("targetDir") or "."
|
|
37
|
+
lang = args.get("language") or "zh-CN"
|
|
38
|
+
person_hint = f" for `{args['person']}`" if args.get("person") else ""
|
|
39
|
+
return _user_message(
|
|
40
|
+
f"Call `gca_generate_recap` on `{target}` with window=`7d` and "
|
|
41
|
+
f"language=`{lang}`{person_hint}. Inspect top delivered items with `gca_get_evidence` "
|
|
42
|
+
"if more module detail is needed. Group completed work vs. unmerged follow-ups, "
|
|
43
|
+
"keep structural observations marked as observation-only, and suggest 1-3 concrete "
|
|
44
|
+
"entries to record in `outcomes.yml`."
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
def brag_doc(args: dict[str, str]) -> list[dict[str, Any]]:
|
|
48
|
+
target = args.get("targetDir") or "."
|
|
49
|
+
since = args.get("since") or ""
|
|
50
|
+
until = args.get("until") or ""
|
|
51
|
+
window_hint = (
|
|
52
|
+
f" between `{since}` and `{until}`"
|
|
53
|
+
if since or until
|
|
54
|
+
else " for the current quarter (`window='quarter'`)"
|
|
55
|
+
)
|
|
56
|
+
return _user_message(
|
|
57
|
+
f"Inspect `{target}` using `gca_workspace_overview` and `gca_portfolio_summary`"
|
|
58
|
+
f"{window_hint}. Draft an evidence-backed Brag Document organized by impact themes. "
|
|
59
|
+
"Respect GCA claim-strength ceilings (pure Git evidence never unlocks LED), omit "
|
|
60
|
+
"raw emails and team rankings, and verify every citation via `gca_verify_citations`."
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def audit_resume_claims(args: dict[str, str]) -> list[dict[str, Any]]:
|
|
64
|
+
target = args.get("targetDir") or "."
|
|
65
|
+
draft = args.get("markdownText") or "<paste resume markdown here>"
|
|
66
|
+
return _user_message(
|
|
67
|
+
f"Audit the following resume or performance draft against GCA deterministic evidence "
|
|
68
|
+
f"in `{target}` by calling `gca_verify_citations`. Flag any bare `EV-xxx` citations "
|
|
69
|
+
"in portfolio mode, nonexistent evidence IDs, unknown repository keys, or unverified "
|
|
70
|
+
f"business/latency numbers not backed by `outcomes.yml`.\n\nDraft:\n{draft}"
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
McpPromptDefinition(
|
|
75
|
+
name="standup-recap",
|
|
76
|
+
description=(
|
|
77
|
+
"Generate an evidence-backed daily standup recap separating "
|
|
78
|
+
"delivered vs pending work."
|
|
79
|
+
),
|
|
80
|
+
arguments=(
|
|
81
|
+
McpPromptArgument(
|
|
82
|
+
"targetDir",
|
|
83
|
+
"Repository or portfolio directory inside allowed roots.",
|
|
84
|
+
),
|
|
85
|
+
McpPromptArgument(
|
|
86
|
+
"window",
|
|
87
|
+
"Recap window (default: today; supports yesterday, 1d, 7d).",
|
|
88
|
+
),
|
|
89
|
+
McpPromptArgument(
|
|
90
|
+
"person",
|
|
91
|
+
"Optional person selector (defaults to local git identity).",
|
|
92
|
+
),
|
|
93
|
+
McpPromptArgument("language", "Output language: zh-CN or en-US."),
|
|
94
|
+
),
|
|
95
|
+
handler=standup_recap,
|
|
96
|
+
),
|
|
97
|
+
McpPromptDefinition(
|
|
98
|
+
name="weekly-report",
|
|
99
|
+
description=(
|
|
100
|
+
"Draft a 7-day engineering weekly report with evidence IDs and outcome prompts."
|
|
101
|
+
),
|
|
102
|
+
arguments=(
|
|
103
|
+
McpPromptArgument(
|
|
104
|
+
"targetDir",
|
|
105
|
+
"Repository or portfolio directory inside allowed roots.",
|
|
106
|
+
),
|
|
107
|
+
McpPromptArgument("person", "Optional person selector."),
|
|
108
|
+
McpPromptArgument("language", "Output language: zh-CN or en-US."),
|
|
109
|
+
),
|
|
110
|
+
handler=weekly_report,
|
|
111
|
+
),
|
|
112
|
+
McpPromptDefinition(
|
|
113
|
+
name="brag-doc",
|
|
114
|
+
description=(
|
|
115
|
+
"Assemble a quarterly or annual Brag Document grounded in verified GCA evidence."
|
|
116
|
+
),
|
|
117
|
+
arguments=(
|
|
118
|
+
McpPromptArgument(
|
|
119
|
+
"targetDir",
|
|
120
|
+
"Repository or portfolio directory inside allowed roots.",
|
|
121
|
+
),
|
|
122
|
+
McpPromptArgument("since", "Optional inclusive start date (YYYY-MM-DD)."),
|
|
123
|
+
McpPromptArgument("until", "Optional inclusive end date (YYYY-MM-DD)."),
|
|
124
|
+
),
|
|
125
|
+
handler=brag_doc,
|
|
126
|
+
),
|
|
127
|
+
McpPromptDefinition(
|
|
128
|
+
name="audit-resume-claims",
|
|
129
|
+
description=(
|
|
130
|
+
"Verify resume or review markdown citations against persisted GCA evidence."
|
|
131
|
+
),
|
|
132
|
+
arguments=(
|
|
133
|
+
McpPromptArgument(
|
|
134
|
+
"targetDir",
|
|
135
|
+
"Repository or portfolio directory inside allowed roots.",
|
|
136
|
+
),
|
|
137
|
+
McpPromptArgument("markdownText", "Draft markdown text to verify.", required=True),
|
|
138
|
+
),
|
|
139
|
+
handler=audit_resume_claims,
|
|
140
|
+
),
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def build_readonly_resources(sandbox: WorkspaceSandbox) -> tuple[McpResourceDefinition, ...]:
|
|
145
|
+
"""构建只读、脱敏(绝不暴露本机绝对路径)的 MCP Resources."""
|
|
146
|
+
|
|
147
|
+
def read_workspace_overview() -> str:
|
|
148
|
+
entries: list[dict[str, Any]] = []
|
|
149
|
+
for idx, root in enumerate(sandbox.allowed_roots, start=1):
|
|
150
|
+
alias = f"workspace-{idx}"
|
|
151
|
+
if (root / "portfolio.yml").is_file():
|
|
152
|
+
store = FilePortfolioStore(root)
|
|
153
|
+
manifest = store.load_manifest()
|
|
154
|
+
entries.append(
|
|
155
|
+
{
|
|
156
|
+
"workspaceAlias": alias,
|
|
157
|
+
"mode": "PORTFOLIO",
|
|
158
|
+
"name": manifest.name,
|
|
159
|
+
"repositories": [repo.repo_key for repo in manifest.repositories],
|
|
160
|
+
}
|
|
161
|
+
)
|
|
162
|
+
elif (root / ".git").exists():
|
|
163
|
+
layout = WorkspaceLayout.for_repository(root)
|
|
164
|
+
entries.append(
|
|
165
|
+
{
|
|
166
|
+
"workspaceAlias": alias,
|
|
167
|
+
"mode": "REPOSITORY",
|
|
168
|
+
"name": root.name,
|
|
169
|
+
"initialized": layout.database.is_file(),
|
|
170
|
+
}
|
|
171
|
+
)
|
|
172
|
+
else:
|
|
173
|
+
entries.append(
|
|
174
|
+
{
|
|
175
|
+
"workspaceAlias": alias,
|
|
176
|
+
"mode": "DIRECTORY",
|
|
177
|
+
"name": root.name,
|
|
178
|
+
}
|
|
179
|
+
)
|
|
180
|
+
return json.dumps({"workspaces": entries}, ensure_ascii=False, indent=2) + "\n"
|
|
181
|
+
|
|
182
|
+
def read_outcomes_template() -> str:
|
|
183
|
+
return (
|
|
184
|
+
"outcomes:\n"
|
|
185
|
+
" - id: OUT-001\n"
|
|
186
|
+
" text: API P95 latency reduced from 420ms to 180ms\n"
|
|
187
|
+
" source: benchmark-report-2026-04.md\n"
|
|
188
|
+
" verifiedBy: team-lead\n"
|
|
189
|
+
" verifiedAt: 2026-04-20\n"
|
|
190
|
+
" kind: OUTCOME\n"
|
|
191
|
+
" evidenceIds:\n"
|
|
192
|
+
" - EV-001\n"
|
|
193
|
+
" tags:\n"
|
|
194
|
+
" - performance\n"
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
McpResourceDefinition(
|
|
199
|
+
uri="gca://workspace/overview",
|
|
200
|
+
name="GCA Allowed Workspaces Overview",
|
|
201
|
+
description=(
|
|
202
|
+
"Sanitized read-only inventory of allowlisted GCA repositories and portfolios "
|
|
203
|
+
"(host absolute paths omitted)."
|
|
204
|
+
),
|
|
205
|
+
mime_type="application/json",
|
|
206
|
+
handler=read_workspace_overview,
|
|
207
|
+
),
|
|
208
|
+
McpResourceDefinition(
|
|
209
|
+
uri="gca://workspace/outcomes-template",
|
|
210
|
+
name="GCA Verified Outcomes YAML Template",
|
|
211
|
+
description=(
|
|
212
|
+
"Schema-compliant outcomes.yml template for recording verified business and "
|
|
213
|
+
"performance metrics linked to EV-xxx evidence IDs."
|
|
214
|
+
),
|
|
215
|
+
mime_type="application/yaml",
|
|
216
|
+
handler=read_outcomes_template,
|
|
217
|
+
),
|
|
218
|
+
)
|