lgit-cli 4.0.1__py3-none-any.whl → 4.2.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 (45) hide show
  1. lgit/__init__.py +1 -1
  2. lgit/analysis.py +22 -33
  3. lgit/api.py +94 -276
  4. lgit/cache.py +29 -59
  5. lgit/changelog.py +47 -120
  6. lgit/cli.py +55 -15
  7. lgit/compose.py +175 -353
  8. lgit/config.py +0 -8
  9. lgit/diffing.py +21 -8
  10. lgit/errors.py +6 -1
  11. lgit/git.py +98 -94
  12. lgit/map_reduce.py +47 -85
  13. lgit/markdown_output.py +5 -13
  14. lgit/models.py +54 -72
  15. lgit/normalization.py +13 -12
  16. lgit/patch.py +75 -55
  17. lgit/repo.py +2 -2
  18. lgit/resources/prompts/{analysis/markdown.md → analysis.md} +1 -1
  19. lgit/resources/prompts/{changelog/markdown.md → changelog.md} +1 -1
  20. lgit/resources/prompts/{compose-bind/markdown.md → compose-bind.md} +1 -1
  21. lgit/resources/prompts/{compose-intent/markdown.md → compose-intent.md} +1 -1
  22. lgit/resources/prompts/{fast/markdown.md → fast.md} +1 -1
  23. lgit/resources/prompts/{map/markdown.md → map.md} +1 -1
  24. lgit/resources/prompts/{reduce/markdown.md → reduce.md} +1 -1
  25. lgit/resources/prompts/{summary/markdown.md → summary.md} +1 -1
  26. lgit/rewrite.py +23 -167
  27. lgit/style.py +2 -2
  28. lgit/templates.py +28 -44
  29. lgit/testing/fixture.py +10 -3
  30. lgit/testing/runner.py +13 -7
  31. lgit/validation.py +7 -4
  32. {lgit_cli-4.0.1.dist-info → lgit_cli-4.2.0.dist-info}/METADATA +2 -2
  33. lgit_cli-4.2.0.dist-info/RECORD +46 -0
  34. lgit/resources/prompts/analysis/default.md +0 -237
  35. lgit/resources/prompts/changelog/default.md +0 -89
  36. lgit/resources/prompts/compose-bind/default.md +0 -40
  37. lgit/resources/prompts/compose-intent/default.md +0 -63
  38. lgit/resources/prompts/fast/default.md +0 -46
  39. lgit/resources/prompts/map/default.md +0 -67
  40. lgit/resources/prompts/reduce/default.md +0 -81
  41. lgit/resources/prompts/summary/default.md +0 -74
  42. lgit_cli-4.0.1.dist-info/RECORD +0 -54
  43. {lgit_cli-4.0.1.dist-info → lgit_cli-4.2.0.dist-info}/WHEEL +0 -0
  44. {lgit_cli-4.0.1.dist-info → lgit_cli-4.2.0.dist-info}/entry_points.txt +0 -0
  45. {lgit_cli-4.0.1.dist-info → lgit_cli-4.2.0.dist-info}/licenses/LICENSE +0 -0
lgit/__init__.py CHANGED
@@ -8,7 +8,7 @@ from typing import TYPE_CHECKING, Any
8
8
  try:
9
9
  __version__ = metadata.version("lgit-cli")
10
10
  except metadata.PackageNotFoundError:
11
- __version__ = "4.0.1"
11
+ __version__ = "4.2.0"
12
12
 
13
13
  _CORE_MODEL_EXPORTS = (
14
14
  "Mode",
lgit/analysis.py CHANGED
@@ -2,22 +2,13 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ from collections import Counter
5
6
  from collections.abc import Sequence
6
7
  from dataclasses import dataclass, field
7
8
  from pathlib import Path
9
+ from typing import Protocol
8
10
 
9
- try: # Import defensively while shared model work lands independently.
10
- from .models import ScopeCandidate
11
- except Exception: # pragma: no cover - bootstrap fallback
12
-
13
- @dataclass(slots=True)
14
- class ScopeCandidate: # type: ignore[no-redef]
15
- """Candidate conventional-commit scope with confidence metadata."""
16
-
17
- path: str
18
- percentage: float
19
- confidence: float
20
-
11
+ from .models import ScopeCandidate
21
12
 
22
13
  PLACEHOLDER_DIRS = {
23
14
  "src",
@@ -39,15 +30,23 @@ PLACEHOLDER_DIRS = {
39
30
  SKIP_DIRS = {".test", "tests", "benches", "examples", "target", "build", "node_modules", ".github"}
40
31
 
41
32
 
33
+ class _ScopeConfig(Protocol):
34
+ """Config attributes read during scope analysis; satisfied by ``CommitConfig``."""
35
+
36
+ excluded_files: list[str]
37
+ wide_change_threshold: float
38
+ wide_change_abstract: bool
39
+
40
+
42
41
  @dataclass(slots=True)
43
42
  class ScopeAnalyzer:
44
43
  """Accumulates changed-line totals per meaningful path component."""
45
44
 
46
- component_lines: dict[str, int] = field(default_factory=dict)
45
+ component_lines: Counter[str] = field(default_factory=Counter)
47
46
  total_lines: int = 0
48
47
 
49
48
  @classmethod
50
- def from_numstat(cls, numstat: str, config: object | None = None) -> ScopeAnalyzer:
49
+ def from_numstat(cls, numstat: str, config: _ScopeConfig | None = None) -> ScopeAnalyzer:
51
50
  """Build an analyzer from git diff --numstat output."""
52
51
 
53
52
  analyzer = cls()
@@ -55,7 +54,7 @@ class ScopeAnalyzer:
55
54
  analyzer.process_numstat_line(line, config)
56
55
  return analyzer
57
56
 
58
- def process_numstat_line(self, line: str, config: object | None = None) -> None:
57
+ def process_numstat_line(self, line: str, config: _ScopeConfig | None = None) -> None:
59
58
  """Process one added/deleted/path numstat row."""
60
59
 
61
60
  parts = line.split("\t")
@@ -76,7 +75,7 @@ class ScopeAnalyzer:
76
75
  for component in extract_components_from_path(path):
77
76
  if any("." in segment for segment in component.split("/")):
78
77
  continue
79
- self.component_lines[component] = self.component_lines.get(component, 0) + lines_changed
78
+ self.component_lines[component] += lines_changed
80
79
 
81
80
  def build_scope_candidates(self) -> list[ScopeCandidate]:
82
81
  """Return sorted candidates with percentage and confidence scores."""
@@ -98,7 +97,7 @@ class ScopeAnalyzer:
98
97
  return candidates
99
98
 
100
99
  @staticmethod
101
- def is_wide_change(candidates: Sequence[ScopeCandidate], config: object | None = None) -> bool:
100
+ def is_wide_change(candidates: Sequence[ScopeCandidate], config: _ScopeConfig | None = None) -> bool:
102
101
  """Return true when no scope dominates or many roots are touched."""
103
102
 
104
103
  threshold = float(getattr(config, "wide_change_threshold", 0.5))
@@ -108,14 +107,14 @@ class ScopeAnalyzer:
108
107
  return len(roots) >= 3
109
108
 
110
109
  @staticmethod
111
- def extract_scope(numstat: str, config: object | None = None) -> tuple[list[ScopeCandidate], int]:
110
+ def extract_scope(numstat: str, config: _ScopeConfig | None = None) -> tuple[list[ScopeCandidate], int]:
112
111
  """Return candidates plus total changed lines from numstat."""
113
112
 
114
113
  analyzer = ScopeAnalyzer.from_numstat(numstat, config)
115
114
  return analyzer.build_scope_candidates(), analyzer.total_lines
116
115
 
117
116
  @staticmethod
118
- def count_changed_lines(numstat: str, config: object | None = None) -> int:
117
+ def count_changed_lines(numstat: str, config: _ScopeConfig | None = None) -> int:
119
118
  """Count changed non-binary, non-excluded lines in numstat."""
120
119
 
121
120
  return ScopeAnalyzer.from_numstat(numstat, config).total_lines
@@ -124,8 +123,8 @@ class ScopeAnalyzer:
124
123
  def analyze_wide_change(numstat: str) -> str | None:
125
124
  """Detect an abstract category for cross-cutting changes."""
126
125
 
127
- paths = [_path_from_numstat_line(line) for line in numstat.splitlines()]
128
- paths = [path for path in paths if path]
126
+ raw_paths = (_path_from_numstat_line(line) for line in numstat.splitlines())
127
+ paths = [path for path in raw_paths if path]
129
128
  if not paths:
130
129
  return None
131
130
 
@@ -175,7 +174,7 @@ def extract_scope_candidates(
175
174
  source: object,
176
175
  target: str | None = None,
177
176
  dir: str = ".",
178
- config: object | None = None,
177
+ config: _ScopeConfig | None = None,
179
178
  ) -> tuple[str, bool]:
180
179
  """Extract a scope prompt string and wide-change flag.
181
180
 
@@ -222,16 +221,6 @@ def extract_scope_candidates(
222
221
  return scope_str, is_wide
223
222
 
224
223
 
225
- def extract_scope_candidates_from_numstat(
226
- numstat: str,
227
- config: object | None = None,
228
- ) -> tuple[list[ScopeCandidate], bool, int]:
229
- """Return raw candidate objects, wide-change flag, and total lines."""
230
-
231
- candidates, total = ScopeAnalyzer.extract_scope(numstat, config)
232
- return candidates, ScopeAnalyzer.is_wide_change(candidates, config), total
233
-
234
-
235
224
  def extract_path_from_rename(path_part: str) -> str:
236
225
  """Return the destination path from git numstat rename syntax."""
237
226
 
@@ -305,7 +294,7 @@ def _is_file_segment(segment: str) -> bool:
305
294
  return "." in segment and not segment.startswith(".") and segment.rfind(".") > 0
306
295
 
307
296
 
308
- def _is_excluded(path: str, config: object | None) -> bool:
297
+ def _is_excluded(path: str, config: _ScopeConfig | None) -> bool:
309
298
  excluded = getattr(config, "excluded_files", ())
310
299
  return any(path.endswith(str(pattern)) for pattern in excluded)
311
300