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.
Files changed (187) hide show
  1. git_contribution_analyzer/__init__.py +3 -0
  2. git_contribution_analyzer/adapters/__init__.py +1 -0
  3. git_contribution_analyzer/adapters/git/__init__.py +1 -0
  4. git_contribution_analyzer/adapters/git/local_identity.py +51 -0
  5. git_contribution_analyzer/adapters/git/native_git.py +353 -0
  6. git_contribution_analyzer/adapters/git/pydriller_history.py +57 -0
  7. git_contribution_analyzer/adapters/git/repository_discovery.py +75 -0
  8. git_contribution_analyzer/adapters/gui/__init__.py +1 -0
  9. git_contribution_analyzer/adapters/gui/app.py +63 -0
  10. git_contribution_analyzer/adapters/gui/controller.py +1084 -0
  11. git_contribution_analyzer/adapters/gui/models/__init__.py +3 -0
  12. git_contribution_analyzer/adapters/gui/models/base_table.py +108 -0
  13. git_contribution_analyzer/adapters/gui/settings.py +53 -0
  14. git_contribution_analyzer/adapters/gui/task_runner.py +196 -0
  15. git_contribution_analyzer/adapters/llm/__init__.py +1 -0
  16. git_contribution_analyzer/adapters/llm/anthropic.py +52 -0
  17. git_contribution_analyzer/adapters/llm/base.py +142 -0
  18. git_contribution_analyzer/adapters/llm/cache.py +148 -0
  19. git_contribution_analyzer/adapters/llm/claude_cli.py +52 -0
  20. git_contribution_analyzer/adapters/llm/codex_cli.py +52 -0
  21. git_contribution_analyzer/adapters/llm/command_base.py +153 -0
  22. git_contribution_analyzer/adapters/llm/mock.py +82 -0
  23. git_contribution_analyzer/adapters/llm/ollama.py +53 -0
  24. git_contribution_analyzer/adapters/llm/openai_compatible.py +61 -0
  25. git_contribution_analyzer/adapters/llm/registry.py +117 -0
  26. git_contribution_analyzer/adapters/mcp/__init__.py +13 -0
  27. git_contribution_analyzer/adapters/mcp/installer.py +175 -0
  28. git_contribution_analyzer/adapters/mcp/prompts_resources.py +218 -0
  29. git_contribution_analyzer/adapters/mcp/protocol.py +361 -0
  30. git_contribution_analyzer/adapters/mcp/server.py +52 -0
  31. git_contribution_analyzer/adapters/mcp/tools.py +621 -0
  32. git_contribution_analyzer/adapters/outcomes/__init__.py +1 -0
  33. git_contribution_analyzer/adapters/outcomes/yaml_loader.py +55 -0
  34. git_contribution_analyzer/adapters/outcomes/yaml_store.py +104 -0
  35. git_contribution_analyzer/adapters/reporting/__init__.py +1 -0
  36. git_contribution_analyzer/adapters/reporting/brag_markdown.py +115 -0
  37. git_contribution_analyzer/adapters/reporting/html_report.py +1413 -0
  38. git_contribution_analyzer/adapters/reporting/markdown.py +217 -0
  39. git_contribution_analyzer/adapters/reporting/portfolio_markdown.py +167 -0
  40. git_contribution_analyzer/adapters/reporting/recap_markdown.py +212 -0
  41. git_contribution_analyzer/adapters/reporting/resume_markdown.py +37 -0
  42. git_contribution_analyzer/adapters/reporting/work_assessment_csv.py +117 -0
  43. git_contribution_analyzer/adapters/reporting/work_assessment_markdown.py +90 -0
  44. git_contribution_analyzer/adapters/reporting/work_assessment_series_markdown.py +31 -0
  45. git_contribution_analyzer/adapters/storage/__init__.py +1 -0
  46. git_contribution_analyzer/adapters/storage/sqlite/__init__.py +1 -0
  47. git_contribution_analyzer/adapters/storage/sqlite/analysis.py +708 -0
  48. git_contribution_analyzer/adapters/storage/sqlite/database.py +98 -0
  49. git_contribution_analyzer/adapters/storage/sqlite/git_index.py +482 -0
  50. git_contribution_analyzer/adapters/storage/sqlite/identity_merge.py +373 -0
  51. git_contribution_analyzer/adapters/storage/sqlite/llm_audit.py +109 -0
  52. git_contribution_analyzer/adapters/storage/sqlite/migrations/env.py +34 -0
  53. git_contribution_analyzer/adapters/storage/sqlite/migrations/script.py.mako +22 -0
  54. git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0001_initial.py +51 -0
  55. git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0002_git_index.py +146 -0
  56. git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0003_analysis.py +79 -0
  57. git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0004_llm_audit.py +69 -0
  58. git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0005_run_types.py +42 -0
  59. git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0006_identity_merges.py +83 -0
  60. git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0007_structural_baselines.py +173 -0
  61. git_contribution_analyzer/adapters/storage/sqlite/models.py +354 -0
  62. git_contribution_analyzer/adapters/storage/sqlite/structural_baseline.py +841 -0
  63. git_contribution_analyzer/adapters/workspace/__init__.py +1 -0
  64. git_contribution_analyzer/adapters/workspace/config.py +135 -0
  65. git_contribution_analyzer/adapters/workspace/git_exclude.py +32 -0
  66. git_contribution_analyzer/adapters/workspace/layout.py +40 -0
  67. git_contribution_analyzer/adapters/workspace/locks.py +27 -0
  68. git_contribution_analyzer/adapters/workspace/portfolio_workspace.py +380 -0
  69. git_contribution_analyzer/adapters/workspace/ranking_config.py +17 -0
  70. git_contribution_analyzer/application/__init__.py +1 -0
  71. git_contribution_analyzer/application/dto/__init__.py +19 -0
  72. git_contribution_analyzer/application/dto/gui.py +86 -0
  73. git_contribution_analyzer/application/dto/results.py +21 -0
  74. git_contribution_analyzer/application/facades/__init__.py +3 -0
  75. git_contribution_analyzer/application/facades/gui.py +568 -0
  76. git_contribution_analyzer/application/ports/__init__.py +22 -0
  77. git_contribution_analyzer/application/ports/cancellation.py +50 -0
  78. git_contribution_analyzer/application/ports/git_history.py +22 -0
  79. git_contribution_analyzer/application/ports/llm.py +44 -0
  80. git_contribution_analyzer/application/ports/portfolio_store.py +34 -0
  81. git_contribution_analyzer/application/ports/progress.py +43 -0
  82. git_contribution_analyzer/application/ports/structural_baseline.py +93 -0
  83. git_contribution_analyzer/application/services/__init__.py +1 -0
  84. git_contribution_analyzer/application/services/assessment_explanation.py +127 -0
  85. git_contribution_analyzer/application/services/default_person.py +61 -0
  86. git_contribution_analyzer/application/services/evidence_snapshot.py +64 -0
  87. git_contribution_analyzer/application/services/person_selection.py +88 -0
  88. git_contribution_analyzer/application/services/resume_generation.py +318 -0
  89. git_contribution_analyzer/application/services/semantic_enhancement.py +157 -0
  90. git_contribution_analyzer/application/services/time_boundaries.py +49 -0
  91. git_contribution_analyzer/application/use_cases/__init__.py +1 -0
  92. git_contribution_analyzer/application/use_cases/analyze_contributions.py +276 -0
  93. git_contribution_analyzer/application/use_cases/analyze_project.py +295 -0
  94. git_contribution_analyzer/application/use_cases/assess_portfolio.py +327 -0
  95. git_contribution_analyzer/application/use_cases/assess_work.py +602 -0
  96. git_contribution_analyzer/application/use_cases/assess_work_series.py +212 -0
  97. git_contribution_analyzer/application/use_cases/compare_assessment_runs.py +121 -0
  98. git_contribution_analyzer/application/use_cases/export_report.py +49 -0
  99. git_contribution_analyzer/application/use_cases/generate_brag.py +308 -0
  100. git_contribution_analyzer/application/use_cases/generate_portfolio_recap.py +244 -0
  101. git_contribution_analyzer/application/use_cases/generate_portfolio_resume.py +152 -0
  102. git_contribution_analyzer/application/use_cases/generate_recap.py +316 -0
  103. git_contribution_analyzer/application/use_cases/generate_report.py +32 -0
  104. git_contribution_analyzer/application/use_cases/generate_resume.py +209 -0
  105. git_contribution_analyzer/application/use_cases/get_portfolio_status.py +83 -0
  106. git_contribution_analyzer/application/use_cases/get_run.py +16 -0
  107. git_contribution_analyzer/application/use_cases/get_status.py +69 -0
  108. git_contribution_analyzer/application/use_cases/index_repository.py +267 -0
  109. git_contribution_analyzer/application/use_cases/init_portfolio.py +89 -0
  110. git_contribution_analyzer/application/use_cases/init_project.py +71 -0
  111. git_contribution_analyzer/application/use_cases/list_identities.py +16 -0
  112. git_contribution_analyzer/application/use_cases/list_providers.py +29 -0
  113. git_contribution_analyzer/application/use_cases/list_runs.py +17 -0
  114. git_contribution_analyzer/application/use_cases/manage_identity_merges.py +48 -0
  115. git_contribution_analyzer/application/use_cases/manage_outcomes.py +189 -0
  116. git_contribution_analyzer/application/use_cases/manage_structural_baselines.py +262 -0
  117. git_contribution_analyzer/application/use_cases/map_identity.py +28 -0
  118. git_contribution_analyzer/application/use_cases/recover_runs.py +22 -0
  119. git_contribution_analyzer/application/use_cases/run_doctor.py +81 -0
  120. git_contribution_analyzer/application/use_cases/sync_portfolio.py +232 -0
  121. git_contribution_analyzer/application/use_cases/test_provider.py +22 -0
  122. git_contribution_analyzer/application/use_cases/uninit_project.py +23 -0
  123. git_contribution_analyzer/application/use_cases/verify_portfolio.py +165 -0
  124. git_contribution_analyzer/cli/__init__.py +1 -0
  125. git_contribution_analyzer/cli/app.py +1430 -0
  126. git_contribution_analyzer/cli/exit_codes.py +13 -0
  127. git_contribution_analyzer/cli/output.py +26 -0
  128. git_contribution_analyzer/cli/portfolio_commands.py +629 -0
  129. git_contribution_analyzer/domain/__init__.py +1 -0
  130. git_contribution_analyzer/domain/errors.py +55 -0
  131. git_contribution_analyzer/domain/models/__init__.py +3 -0
  132. git_contribution_analyzer/domain/models/analysis.py +29 -0
  133. git_contribution_analyzer/domain/models/assessment.py +12 -0
  134. git_contribution_analyzer/domain/models/brag.py +148 -0
  135. git_contribution_analyzer/domain/models/contribution.py +55 -0
  136. git_contribution_analyzer/domain/models/git_history.py +69 -0
  137. git_contribution_analyzer/domain/models/person_selection.py +46 -0
  138. git_contribution_analyzer/domain/models/portfolio.py +498 -0
  139. git_contribution_analyzer/domain/models/ranking.py +48 -0
  140. git_contribution_analyzer/domain/models/recap.py +235 -0
  141. git_contribution_analyzer/domain/models/repository.py +10 -0
  142. git_contribution_analyzer/domain/models/resume.py +59 -0
  143. git_contribution_analyzer/domain/models/run.py +10 -0
  144. git_contribution_analyzer/domain/models/semantic.py +34 -0
  145. git_contribution_analyzer/domain/models/snapshot.py +208 -0
  146. git_contribution_analyzer/domain/models/structural_baseline.py +120 -0
  147. git_contribution_analyzer/domain/models/work_assessment.py +81 -0
  148. git_contribution_analyzer/domain/services/assessment_periods.py +182 -0
  149. git_contribution_analyzer/domain/services/brag_rules.py +250 -0
  150. git_contribution_analyzer/domain/services/capability_rules.py +91 -0
  151. git_contribution_analyzer/domain/services/contribution_clustering.py +98 -0
  152. git_contribution_analyzer/domain/services/contribution_rules.py +79 -0
  153. git_contribution_analyzer/domain/services/difficulty_rules.py +191 -0
  154. git_contribution_analyzer/domain/services/dimensional_summary.py +117 -0
  155. git_contribution_analyzer/domain/services/portfolio_aggregation.py +250 -0
  156. git_contribution_analyzer/domain/services/portfolio_resume_rules.py +265 -0
  157. git_contribution_analyzer/domain/services/portfolio_verifier.py +238 -0
  158. git_contribution_analyzer/domain/services/ranking_rules.py +226 -0
  159. git_contribution_analyzer/domain/services/recap_rules.py +268 -0
  160. git_contribution_analyzer/domain/services/resume_claim_rules.py +70 -0
  161. git_contribution_analyzer/domain/services/structural_baseline.py +317 -0
  162. git_contribution_analyzer/domain/services/structural_signals.py +151 -0
  163. git_contribution_analyzer/domain/services/workload_rules.py +185 -0
  164. git_contribution_analyzer/gui/__init__.py +1 -0
  165. git_contribution_analyzer/gui/qml/Main.qml +1141 -0
  166. git_contribution_analyzer/gui/qml/__init__.py +1 -0
  167. git_contribution_analyzer/prompts/__init__.py +1 -0
  168. git_contribution_analyzer/prompts/assessment/__init__.py +1 -0
  169. git_contribution_analyzer/prompts/assessment/v1/__init__.py +1 -0
  170. git_contribution_analyzer/prompts/assessment/v1/explanation.txt +4 -0
  171. git_contribution_analyzer/prompts/resume/__init__.py +1 -0
  172. git_contribution_analyzer/prompts/resume/v1/__init__.py +1 -0
  173. git_contribution_analyzer/prompts/resume/v1/style-concise.txt +1 -0
  174. git_contribution_analyzer/prompts/resume/v1/style-star.txt +1 -0
  175. git_contribution_analyzer/prompts/resume/v1/style-xyz.txt +1 -0
  176. git_contribution_analyzer/prompts/resume/v1/system.txt +3 -0
  177. git_contribution_analyzer/prompts/v1/__init__.py +1 -0
  178. git_contribution_analyzer/prompts/v1/capability_explanation.txt +2 -0
  179. git_contribution_analyzer/prompts/v1/contribution_summary.txt +2 -0
  180. git_contribution_analyzer/prompts/v1/overall_summary.txt +2 -0
  181. git_contribution_analyzer/prompts/v1/resume_bullet.txt +2 -0
  182. git_contribution_analyzer-0.8.0.dist-info/METADATA +667 -0
  183. git_contribution_analyzer-0.8.0.dist-info/RECORD +187 -0
  184. git_contribution_analyzer-0.8.0.dist-info/WHEEL +4 -0
  185. git_contribution_analyzer-0.8.0.dist-info/entry_points.txt +3 -0
  186. git_contribution_analyzer-0.8.0.dist-info/licenses/LICENSE +201 -0
  187. git_contribution_analyzer-0.8.0.dist-info/licenses/NOTICE +6 -0
@@ -0,0 +1,13 @@
1
+ from enum import IntEnum
2
+
3
+
4
+ class ExitCode(IntEnum):
5
+ SUCCESS = 0
6
+ INVALID_USAGE = 2
7
+ NOT_A_REPOSITORY = 3
8
+ WORKSPACE_ERROR = 4
9
+ IDENTITY_AMBIGUOUS = 5
10
+ PROVIDER_ERROR = 6
11
+ REPORT_ERROR = 7
12
+ INTERRUPTED = 8
13
+ INTERNAL_ERROR = 10
@@ -0,0 +1,26 @@
1
+ from __future__ import annotations
2
+
3
+ import sys
4
+
5
+ import typer
6
+
7
+ from git_contribution_analyzer.application.dto.results import CommandEnvelope
8
+
9
+
10
+ def emit_json(envelope: CommandEnvelope) -> None:
11
+ typer.echo(_console_safe(envelope.model_dump_json(by_alias=True, exclude_none=False)))
12
+
13
+
14
+ def emit_human(message: str) -> None:
15
+ typer.echo(_console_safe(message))
16
+
17
+
18
+ def _console_safe(message: str) -> str:
19
+ encoding = getattr(sys.stdout, "encoding", None)
20
+ if not encoding:
21
+ return message
22
+ try:
23
+ message.encode(encoding)
24
+ except (LookupError, UnicodeEncodeError):
25
+ return message.encode(encoding, errors="backslashreplace").decode(encoding)
26
+ return message
@@ -0,0 +1,629 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import re
5
+ import webbrowser
6
+ from pathlib import Path
7
+ from typing import Annotated, Any
8
+
9
+ import typer
10
+
11
+ from git_contribution_analyzer.adapters.outcomes.yaml_loader import load_verified_outcomes
12
+ from git_contribution_analyzer.adapters.outcomes.yaml_store import (
13
+ default_outcomes_path,
14
+ load_outcomes_if_exists,
15
+ )
16
+ from git_contribution_analyzer.adapters.reporting.brag_markdown import render_brag_markdown
17
+ from git_contribution_analyzer.adapters.reporting.html_report import render_html_report
18
+ from git_contribution_analyzer.adapters.reporting.portfolio_markdown import (
19
+ render_portfolio_resume_markdown,
20
+ render_portfolio_summary_markdown,
21
+ )
22
+ from git_contribution_analyzer.adapters.reporting.recap_markdown import render_recap_markdown
23
+ from git_contribution_analyzer.application.dto.results import CommandEnvelope
24
+ from git_contribution_analyzer.application.services.time_boundaries import parse_boundaries
25
+ from git_contribution_analyzer.application.use_cases.assess_portfolio import assess_portfolio
26
+ from git_contribution_analyzer.application.use_cases.generate_brag import generate_portfolio_brag
27
+ from git_contribution_analyzer.application.use_cases.generate_portfolio_recap import (
28
+ generate_portfolio_recap,
29
+ )
30
+ from git_contribution_analyzer.application.use_cases.generate_portfolio_resume import (
31
+ generate_portfolio_resume,
32
+ )
33
+ from git_contribution_analyzer.application.use_cases.get_portfolio_status import (
34
+ get_portfolio_status,
35
+ )
36
+ from git_contribution_analyzer.application.use_cases.init_portfolio import init_portfolio
37
+ from git_contribution_analyzer.application.use_cases.sync_portfolio import sync_portfolio
38
+ from git_contribution_analyzer.application.use_cases.verify_portfolio import verify_portfolio
39
+ from git_contribution_analyzer.cli.exit_codes import ExitCode
40
+ from git_contribution_analyzer.cli.output import emit_human, emit_json
41
+ from git_contribution_analyzer.domain.errors import (
42
+ ConfigurationError,
43
+ GcaError,
44
+ IdentityResolutionError,
45
+ NotARepositoryError,
46
+ ReportError,
47
+ WorkspaceError,
48
+ )
49
+ from git_contribution_analyzer.domain.models.analysis import AnalysisFilters
50
+
51
+ portfolio_app = typer.Typer(
52
+ help="Manage, aggregate, verify and summarize multi-repository GCA portfolios.",
53
+ no_args_is_help=True,
54
+ )
55
+ BOUNDARY_HELP = "Inclusive ISO date/time; values without an offset use the system time zone."
56
+ JSON_HELP = "Emit versioned JSON output."
57
+
58
+
59
+ def _envelope(command: str, data: dict[str, Any], *, success: bool = True) -> CommandEnvelope:
60
+ return CommandEnvelope(command=command, success=success, data=data)
61
+
62
+
63
+ def _exit_for_portfolio_error(error: Exception) -> None:
64
+ if isinstance(error, NotARepositoryError):
65
+ emit_human(f"Error: {error}")
66
+ raise typer.Exit(code=ExitCode.NOT_A_REPOSITORY) from error
67
+ if isinstance(error, (WorkspaceError, ConfigurationError)):
68
+ emit_human(f"Error: {error}")
69
+ raise typer.Exit(code=ExitCode.WORKSPACE_ERROR) from error
70
+ if isinstance(error, IdentityResolutionError):
71
+ emit_human(f"Error: {error}")
72
+ raise typer.Exit(code=ExitCode.IDENTITY_AMBIGUOUS) from error
73
+ if isinstance(error, ReportError):
74
+ emit_human(f"Error: {error}")
75
+ raise typer.Exit(code=ExitCode.REPORT_ERROR) from error
76
+ emit_human(f"Error: {error}")
77
+ raise typer.Exit(code=ExitCode.INTERNAL_ERROR) from error
78
+
79
+
80
+ @portfolio_app.command("init")
81
+ def portfolio_init_command(
82
+ path: Annotated[Path, typer.Argument(help="Portfolio workspace directory.")] = Path("."),
83
+ name: Annotated[str | None, typer.Option("--name", help="Portfolio name.")] = None,
84
+ scan_root: Annotated[
85
+ list[Path] | None,
86
+ typer.Option("--scan-root", help="Repeatable local root directory to scan for Git repos."),
87
+ ] = None,
88
+ group: Annotated[
89
+ str,
90
+ typer.Option("--group", help="Default group name for discovered repositories."),
91
+ ] = "default",
92
+ exclude: Annotated[
93
+ list[str] | None,
94
+ typer.Option("--exclude", help="Repeatable glob patterns to exclude during discovery."),
95
+ ] = None,
96
+ json_output: Annotated[bool, typer.Option("--json", help=JSON_HELP)] = False,
97
+ ) -> None:
98
+ """Initialize a `.gca-portfolio/` workspace and `portfolio.yml` manifest."""
99
+ try:
100
+ result = init_portfolio(
101
+ path,
102
+ name=name,
103
+ scan_roots=tuple(scan_root or ()),
104
+ group_name=group,
105
+ exclude_patterns=tuple(exclude or ()),
106
+ )
107
+ except (GcaError, ValueError) as exc:
108
+ _exit_for_portfolio_error(exc)
109
+ return
110
+
111
+ if json_output:
112
+ emit_json(_envelope("portfolio init", result))
113
+ return
114
+ emit_human(
115
+ f"Initialized portfolio '{result['portfolioName']}' with "
116
+ f"{result['discoveredRepositories']} discovered repositories."
117
+ )
118
+
119
+
120
+ @portfolio_app.command("status")
121
+ def portfolio_status_command(
122
+ path: Annotated[Path, typer.Argument(help="Portfolio workspace directory.")] = Path("."),
123
+ json_output: Annotated[bool, typer.Option("--json", help=JSON_HELP)] = False,
124
+ ) -> None:
125
+ """Inspect member repository initialization, index health, and persisted runs."""
126
+ try:
127
+ result = get_portfolio_status(path)
128
+ except (GcaError, ValueError) as exc:
129
+ _exit_for_portfolio_error(exc)
130
+ return
131
+
132
+ if json_output:
133
+ emit_json(_envelope("portfolio status", result))
134
+ return
135
+ emit_human(
136
+ f"Portfolio: {result['portfolioName']} | "
137
+ f"Initialized: {result['initializedRepositories']}/{result['totalRepositories']} | "
138
+ f"Missing: {result['missingRepositories']} | Runs: {result['runs']}"
139
+ )
140
+
141
+
142
+ @portfolio_app.command("sync")
143
+ def portfolio_sync_command(
144
+ path: Annotated[Path, typer.Argument(help="Portfolio workspace directory.")] = Path("."),
145
+ full_rebuild: Annotated[
146
+ bool,
147
+ typer.Option("--full-rebuild", help="Rebuild each member repository index from scratch."),
148
+ ] = False,
149
+ fail_fast: Annotated[
150
+ bool,
151
+ typer.Option("--fail-fast", help="Stop immediately on the first failing repository."),
152
+ ] = False,
153
+ concurrency: Annotated[
154
+ int,
155
+ typer.Option("--concurrency", help="Number of repositories to sync concurrently (>=1)."),
156
+ ] = 1,
157
+ verbose: Annotated[
158
+ bool,
159
+ typer.Option("--verbose", help="Print per-repository sync progress to stderr."),
160
+ ] = False,
161
+ json_output: Annotated[bool, typer.Option("--json", help=JSON_HELP)] = False,
162
+ ) -> None:
163
+ """Initialize or sync all member repositories and apply portfolio identity rules."""
164
+ progress_cb = (
165
+ (
166
+ lambda repo_key, current, total, detail: typer.echo(
167
+ f"[{current}/{total}] {repo_key}: {detail}",
168
+ err=True,
169
+ )
170
+ )
171
+ if verbose
172
+ else None
173
+ )
174
+ try:
175
+ result = sync_portfolio(
176
+ path,
177
+ full_rebuild=full_rebuild,
178
+ continue_on_error=not fail_fast,
179
+ concurrency=concurrency,
180
+ on_repo_progress=progress_cb,
181
+ )
182
+ except (GcaError, ValueError) as exc:
183
+ _exit_for_portfolio_error(exc)
184
+ return
185
+
186
+ if json_output:
187
+ emit_json(_envelope("portfolio sync", result))
188
+ return
189
+ emit_human(
190
+ f"Portfolio sync {result['status']}: "
191
+ f"{result['syncedRepositories']}/{result['totalRepositories']} synced, "
192
+ f"{result['failedRepositories']} failed."
193
+ )
194
+
195
+
196
+ @portfolio_app.command("assess")
197
+ def portfolio_assess_command(
198
+ path: Annotated[Path, typer.Argument(help="Portfolio workspace directory.")] = Path("."),
199
+ person: Annotated[
200
+ str | None,
201
+ typer.Option("--person", help="Target person name or email configured in the portfolio."),
202
+ ] = None,
203
+ since: Annotated[str | None, typer.Option("--since", help=BOUNDARY_HELP)] = None,
204
+ until: Annotated[str | None, typer.Option("--until", help=BOUNDARY_HELP)] = None,
205
+ refresh: Annotated[
206
+ bool,
207
+ typer.Option("--refresh", help="Sync member repositories before aggregating."),
208
+ ] = False,
209
+ fail_fast: Annotated[
210
+ bool,
211
+ typer.Option("--fail-fast", help="Stop immediately on the first failing repository."),
212
+ ] = False,
213
+ no_llm: Annotated[
214
+ bool,
215
+ typer.Option("--no-llm", help="Run strictly offline deterministic aggregation."),
216
+ ] = True,
217
+ report_format: Annotated[
218
+ str,
219
+ typer.Option(
220
+ "--format",
221
+ help="Output file format when --output is given: json|markdown|html.",
222
+ ),
223
+ ] = "json",
224
+ output: Annotated[
225
+ Path | None,
226
+ typer.Option("--output", help="Optional path to write rendered summary report."),
227
+ ] = None,
228
+ json_output: Annotated[bool, typer.Option("--json", help=JSON_HELP)] = False,
229
+ ) -> None:
230
+ """Aggregate deterministic contribution and assessment summaries across repositories."""
231
+ _ = no_llm
232
+ try:
233
+ if not person:
234
+ raise ConfigurationError("--person is required")
235
+ since_dt, until_dt = parse_boundaries(since, until)
236
+ filters = AnalysisFilters(since=since_dt, until=until_dt)
237
+ result = assess_portfolio(
238
+ path,
239
+ person_selector=person,
240
+ filters=filters,
241
+ refresh=refresh,
242
+ continue_on_error=not fail_fast,
243
+ )
244
+ if output is not None:
245
+ fmt = report_format.lower()
246
+ if fmt == "json":
247
+ rendered = json.dumps(result["report"], ensure_ascii=False, indent=2) + "\n"
248
+ elif fmt == "markdown":
249
+ rendered = render_portfolio_summary_markdown(result["report"])
250
+ elif fmt == "html":
251
+ rendered = render_html_report(result["report"])
252
+ else:
253
+ raise ConfigurationError(f"Unsupported format: {report_format}")
254
+ output.parent.mkdir(parents=True, exist_ok=True)
255
+ output.write_text(rendered, encoding="utf-8", newline="\n")
256
+ except (GcaError, ValueError) as exc:
257
+ _exit_for_portfolio_error(exc)
258
+ return
259
+
260
+ if json_output:
261
+ emit_json(_envelope("portfolio assess", result))
262
+ return
263
+ totals = result["report"]["totals"]
264
+ scope = result["report"]["scope"]
265
+ emit_human(
266
+ f"Portfolio assess {result['status']} (run {result['runId']}): "
267
+ f"{scope['matchedRepositories']}/{scope['discoveredRepositories']} repos matched, "
268
+ f"{totals['commits']} commits ({totals['deliveredCommits']} delivered)."
269
+ )
270
+
271
+
272
+ @portfolio_app.command("resume")
273
+ def portfolio_resume_command(
274
+ path: Annotated[Path, typer.Argument(help="Portfolio workspace directory.")] = Path("."),
275
+ person: Annotated[
276
+ str | None,
277
+ typer.Option("--person", help="Target person name or email configured in the portfolio."),
278
+ ] = None,
279
+ target_role: Annotated[str, typer.Option("--target-role", help="Target role title.")] = "",
280
+ language: Annotated[
281
+ str,
282
+ typer.Option("--language", help="Resume language: zh-CN|en-US."),
283
+ ] = "zh-CN",
284
+ style: Annotated[
285
+ str,
286
+ typer.Option("--style", help="Resume style: concise|star|xyz."),
287
+ ] = "star",
288
+ max_bullets_per_group: Annotated[
289
+ int,
290
+ typer.Option("--max-bullets-per-group", help="Maximum bullets per project group (1-20)."),
291
+ ] = 6,
292
+ include_pending: Annotated[
293
+ bool,
294
+ typer.Option("--include-pending", help="Include AUTHORED_ONLY pending bullets."),
295
+ ] = False,
296
+ outcomes_file: Annotated[
297
+ Path | None,
298
+ typer.Option("--outcomes", help="Optional verified outcomes YAML file."),
299
+ ] = None,
300
+ no_default_outcomes: Annotated[
301
+ bool,
302
+ typer.Option(
303
+ "--no-default-outcomes",
304
+ help="Skip auto-loading .gca-portfolio/outcomes.yml when --outcomes is omitted.",
305
+ ),
306
+ ] = False,
307
+ since: Annotated[str | None, typer.Option("--since", help=BOUNDARY_HELP)] = None,
308
+ until: Annotated[str | None, typer.Option("--until", help=BOUNDARY_HELP)] = None,
309
+ refresh: Annotated[
310
+ bool,
311
+ typer.Option("--refresh", help="Sync member repositories before generating resume."),
312
+ ] = False,
313
+ no_llm: Annotated[
314
+ bool,
315
+ typer.Option("--no-llm", help="Run strictly offline deterministic resume template."),
316
+ ] = True,
317
+ report_format: Annotated[
318
+ str,
319
+ typer.Option(
320
+ "--format",
321
+ help="Output file format when --output is given: json|markdown|html.",
322
+ ),
323
+ ] = "markdown",
324
+ output: Annotated[
325
+ Path | None,
326
+ typer.Option("--output", help="Optional path to write rendered portfolio resume."),
327
+ ] = None,
328
+ json_output: Annotated[bool, typer.Option("--json", help=JSON_HELP)] = False,
329
+ ) -> None:
330
+ """Generate a deterministic cross-project resume with `<repoKey>:EV-xxx` citations."""
331
+ _ = no_llm
332
+ try:
333
+ if not person:
334
+ raise ConfigurationError("--person is required")
335
+ since_dt, until_dt = parse_boundaries(since, until)
336
+ filters = AnalysisFilters(since=since_dt, until=until_dt)
337
+ if outcomes_file is not None:
338
+ outcomes = load_verified_outcomes(outcomes_file)
339
+ elif not no_default_outcomes:
340
+ outcomes = load_outcomes_if_exists(default_outcomes_path(path))
341
+ else:
342
+ outcomes = ()
343
+ result = generate_portfolio_resume(
344
+ path,
345
+ person_selector=person,
346
+ filters=filters,
347
+ target_role=target_role,
348
+ language=language,
349
+ style=style,
350
+ max_bullets_per_group=max_bullets_per_group,
351
+ include_pending=include_pending,
352
+ outcomes=outcomes,
353
+ refresh=refresh,
354
+ )
355
+ if output is not None:
356
+ fmt = report_format.lower()
357
+ if fmt == "json":
358
+ rendered = json.dumps(result["report"], ensure_ascii=False, indent=2) + "\n"
359
+ elif fmt == "markdown":
360
+ rendered = render_portfolio_resume_markdown(result["report"])
361
+ elif fmt == "html":
362
+ rendered = render_html_report(result["report"], language=language)
363
+ else:
364
+ raise ConfigurationError(f"Unsupported format: {report_format}")
365
+ output.parent.mkdir(parents=True, exist_ok=True)
366
+ output.write_text(rendered, encoding="utf-8", newline="\n")
367
+ except (GcaError, ValueError) as exc:
368
+ _exit_for_portfolio_error(exc)
369
+ return
370
+
371
+ if json_output:
372
+ emit_json(_envelope("portfolio resume", result))
373
+ return
374
+ groups = result["report"]["projectGroups"]
375
+ bullet_count = sum(len(g["bullets"]) for g in groups)
376
+ emit_human(
377
+ f"Portfolio resume {result['status']} (run {result['runId']}): "
378
+ f"{len(groups)} groups, {bullet_count} evidence-backed bullets."
379
+ )
380
+
381
+
382
+ def _slug_filename(label: str) -> str:
383
+ cleaned = re.sub(r"[^A-Za-z0-9._-]+", "-", label.strip()).strip("-")
384
+ return cleaned or "report"
385
+
386
+
387
+ @portfolio_app.command("recap")
388
+ def portfolio_recap_command(
389
+ path: Annotated[Path, typer.Argument(help="Portfolio workspace directory.")] = Path("."),
390
+ person: Annotated[
391
+ str | None,
392
+ typer.Option(
393
+ "--person",
394
+ help="Canonical person name, email, or alias selector. Auto-inferred when unique.",
395
+ ),
396
+ ] = None,
397
+ me: Annotated[
398
+ bool,
399
+ typer.Option(
400
+ "--me",
401
+ help="Explicitly infer target identity from portfolio manifest or local git config.",
402
+ ),
403
+ ] = False,
404
+ window: Annotated[
405
+ str | None,
406
+ typer.Option(
407
+ "--window",
408
+ help="Shorthand window: today|yesterday|1d|day|7d|14d|30d|week|month|quarter.",
409
+ ),
410
+ ] = None,
411
+ since: Annotated[str | None, typer.Option("--since", help=BOUNDARY_HELP)] = None,
412
+ until: Annotated[str | None, typer.Option("--until", help=BOUNDARY_HELP)] = None,
413
+ refresh: Annotated[
414
+ bool,
415
+ typer.Option("--refresh", help="Sync member repositories before generating recap."),
416
+ ] = False,
417
+ language: Annotated[
418
+ str,
419
+ typer.Option("--language", help="Markdown/HTML language: zh-CN|en-US."),
420
+ ] = "zh-CN",
421
+ report_format: Annotated[
422
+ str | None,
423
+ typer.Option("--format", help="Output format: markdown|json|html."),
424
+ ] = None,
425
+ output: Annotated[
426
+ Path | None,
427
+ typer.Option("--output", help="Optional path to write rendered portfolio recap."),
428
+ ] = None,
429
+ open_browser: Annotated[
430
+ bool,
431
+ typer.Option(
432
+ "--open",
433
+ help="Render self-contained HTML and open it in the default browser.",
434
+ ),
435
+ ] = False,
436
+ json_output: Annotated[bool, typer.Option("--json", help=JSON_HELP)] = False,
437
+ ) -> None:
438
+ """Generate a deterministic daily/weekly/monthly/quarterly recap across portfolio repos."""
439
+ try:
440
+ if me and person:
441
+ raise ConfigurationError("Pass either --person or --me, not both")
442
+ fmt = (report_format or ("html" if open_browser else "markdown")).lower()
443
+ if fmt not in {"json", "markdown", "html"}:
444
+ raise ConfigurationError(f"Unsupported format: {report_format}")
445
+ if open_browser and fmt != "html":
446
+ raise ConfigurationError("--open is only supported with --format html")
447
+ since_dt, until_dt = parse_boundaries(since, until)
448
+ result = generate_portfolio_recap(
449
+ path,
450
+ person_selector=None if me else person,
451
+ window=window,
452
+ since=since_dt,
453
+ until=until_dt,
454
+ refresh=refresh,
455
+ )
456
+ if fmt == "json":
457
+ rendered = json.dumps(result["report"], ensure_ascii=False, indent=2) + "\n"
458
+ elif fmt == "markdown":
459
+ rendered = render_recap_markdown(result["report"], language=language)
460
+ else:
461
+ rendered = render_html_report(result["report"], language=language)
462
+
463
+ resolved_output = output
464
+ if open_browser and resolved_output is None:
465
+ reports_dir = path.expanduser().resolve() / ".gca-portfolio" / "reports"
466
+ reports_dir.mkdir(parents=True, exist_ok=True)
467
+ label_slug = _slug_filename(str(result["report"]["window"]["label"]))
468
+ resolved_output = reports_dir / f"portfolio-recap-{label_slug}.html"
469
+
470
+ if resolved_output is not None:
471
+ resolved_output.parent.mkdir(parents=True, exist_ok=True)
472
+ resolved_output.write_text(rendered, encoding="utf-8", newline="\n")
473
+ if open_browser and resolved_output is not None:
474
+ webbrowser.open(resolved_output.resolve().as_uri())
475
+ except (GcaError, ValueError) as exc:
476
+ _exit_for_portfolio_error(exc)
477
+ return
478
+
479
+ if json_output:
480
+ emit_json(_envelope("portfolio recap", result))
481
+ return
482
+ if resolved_output is not None:
483
+ totals = result["report"]["totals"]
484
+ emit_human(
485
+ f"Portfolio recap {result['status']} (run {result['runId']}) "
486
+ f"written to {resolved_output}: "
487
+ f"{totals['commits']} commits, {totals['completedItems']} completed, "
488
+ f"{totals['pendingItems']} pending."
489
+ )
490
+ return
491
+ typer.echo(rendered, nl=False)
492
+
493
+
494
+ @portfolio_app.command("brag")
495
+ def portfolio_brag_command(
496
+ path: Annotated[Path, typer.Argument(help="Portfolio workspace directory.")] = Path("."),
497
+ person: Annotated[
498
+ str | None,
499
+ typer.Option("--person", help="Canonical person selector (auto-inferred when unique)."),
500
+ ] = None,
501
+ me: Annotated[
502
+ bool,
503
+ typer.Option("--me", help="Explicitly infer identity from portfolio or local git config."),
504
+ ] = False,
505
+ year: Annotated[int | None, typer.Option("--year", help="Calendar year (e.g. 2026).")] = None,
506
+ quarter: Annotated[
507
+ str | None,
508
+ typer.Option("--quarter", help="Calendar quarter (e.g. 2026-Q3)."),
509
+ ] = None,
510
+ since: Annotated[str | None, typer.Option("--since", help=BOUNDARY_HELP)] = None,
511
+ until: Annotated[str | None, typer.Option("--until", help=BOUNDARY_HELP)] = None,
512
+ outcomes_file: Annotated[
513
+ Path | None,
514
+ typer.Option("--outcomes", help="Optional outcomes YAML file."),
515
+ ] = None,
516
+ refresh: Annotated[
517
+ bool,
518
+ typer.Option("--refresh", help="Sync member repositories before generating brag doc."),
519
+ ] = False,
520
+ language: Annotated[
521
+ str,
522
+ typer.Option("--language", help="Output language: zh-CN|en-US."),
523
+ ] = "zh-CN",
524
+ report_format: Annotated[
525
+ str | None,
526
+ typer.Option("--format", help="Output format: markdown|json|html."),
527
+ ] = None,
528
+ output: Annotated[
529
+ Path | None,
530
+ typer.Option("--output", help="Optional path to write rendered portfolio brag document."),
531
+ ] = None,
532
+ open_browser: Annotated[
533
+ bool,
534
+ typer.Option("--open", help="Render self-contained HTML and open it in the browser."),
535
+ ] = False,
536
+ json_output: Annotated[bool, typer.Option("--json", help=JSON_HELP)] = False,
537
+ ) -> None:
538
+ """Generate a cross-repository annual/quarterly Brag Document with verified outcomes."""
539
+ try:
540
+ if me and person:
541
+ raise ConfigurationError("Pass either --person or --me, not both")
542
+ fmt = (report_format or ("html" if open_browser else "markdown")).lower()
543
+ if fmt not in {"json", "markdown", "html"}:
544
+ raise ConfigurationError(f"Unsupported format: {report_format}")
545
+ if open_browser and fmt != "html":
546
+ raise ConfigurationError("--open is only supported with --format html")
547
+ since_dt, until_dt = parse_boundaries(since, until)
548
+ result = generate_portfolio_brag(
549
+ path,
550
+ person_selector=None if me else person,
551
+ year=year,
552
+ quarter=quarter,
553
+ since=since_dt,
554
+ until=until_dt,
555
+ outcomes_file=outcomes_file,
556
+ refresh=refresh,
557
+ )
558
+ if fmt == "json":
559
+ rendered = json.dumps(result["report"], ensure_ascii=False, indent=2) + "\n"
560
+ elif fmt == "markdown":
561
+ rendered = render_brag_markdown(result["report"], language=language)
562
+ else:
563
+ rendered = render_html_report(result["report"], language=language)
564
+
565
+ resolved_output = output
566
+ if open_browser and resolved_output is None:
567
+ reports_dir = path.expanduser().resolve() / ".gca-portfolio" / "reports"
568
+ reports_dir.mkdir(parents=True, exist_ok=True)
569
+ label_slug = _slug_filename(str(result["report"]["period"]["label"]))
570
+ resolved_output = reports_dir / f"portfolio-brag-{label_slug}.html"
571
+
572
+ if resolved_output is not None:
573
+ resolved_output.parent.mkdir(parents=True, exist_ok=True)
574
+ resolved_output.write_text(rendered, encoding="utf-8", newline="\n")
575
+ if open_browser and resolved_output is not None:
576
+ webbrowser.open(resolved_output.resolve().as_uri())
577
+ except (GcaError, ValueError) as exc:
578
+ _exit_for_portfolio_error(exc)
579
+ return
580
+
581
+ if json_output:
582
+ emit_json(_envelope("portfolio brag", result))
583
+ return
584
+ if resolved_output is not None:
585
+ summary = result["report"]["summary"]
586
+ emit_human(
587
+ f"Portfolio brag {result['status']} (run {result['runId']}) written to "
588
+ f"{resolved_output}: {summary['completedItems']} completed items, "
589
+ f"{summary['verifiedOutcomes']} outcomes."
590
+ )
591
+ return
592
+ typer.echo(rendered, nl=False)
593
+
594
+
595
+ @portfolio_app.command("verify")
596
+ def portfolio_verify_command(
597
+ path: Annotated[Path, typer.Argument(help="Portfolio workspace directory.")] = Path("."),
598
+ run: Annotated[
599
+ str,
600
+ typer.Option("--run", help="Persisted portfolio run ID or 'latest'."),
601
+ ] = "latest",
602
+ resume_file: Annotated[
603
+ Path | None,
604
+ typer.Option("--resume-file", help="Markdown resume file to verify EV references."),
605
+ ] = None,
606
+ json_output: Annotated[bool, typer.Option("--json", help=JSON_HELP)] = False,
607
+ ) -> None:
608
+ """Verify persisted portfolio accounting invariants and `<repoKey>:EV-xxx` citations."""
609
+ try:
610
+ result = verify_portfolio(
611
+ path,
612
+ run_id=run,
613
+ resume_markdown_path=resume_file,
614
+ )
615
+ except (GcaError, ValueError) as exc:
616
+ _exit_for_portfolio_error(exc)
617
+ return
618
+
619
+ if json_output:
620
+ emit_json(_envelope("portfolio verify", result, success=bool(result["ok"])))
621
+ else:
622
+ verdict = "OK" if result["ok"] else "FAILED"
623
+ emit_human(
624
+ f"Portfolio verify {verdict}: checked {result['checkedRepositories']} repos, "
625
+ f"{result['checkedEvidenceReferences']} evidence refs, "
626
+ f"{len(result['issues'])} issues."
627
+ )
628
+ if not result["ok"]:
629
+ raise typer.Exit(code=ExitCode.REPORT_ERROR)
@@ -0,0 +1 @@
1
+ """Domain models and rules."""