lgit-cli 5.3.0__py3-none-any.whl → 5.4.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.
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__ = "5.0.0"
11
+ __version__ = "5.4.0"
12
12
 
13
13
  _CORE_MODEL_EXPORTS = (
14
14
  "Mode",
lgit/api.py CHANGED
@@ -18,7 +18,7 @@ import httpx
18
18
  from jinja2 import Template
19
19
 
20
20
  from . import cache as llm_cache
21
- from . import pricing, profile
21
+ from . import pricing, profile, style
22
22
  from .diffing import condense_stat
23
23
  from .errors import ApiContextLengthExceeded, ApiError, LgitError
24
24
  from .markdown_output import (
@@ -34,7 +34,14 @@ from .markdown_output import (
34
34
  from .markdown_output import (
35
35
  strip_type_prefix as strip_markdown_type_prefix,
36
36
  )
37
- from .models import CommitSummary, ConventionalAnalysis, ConventionalCommit, ResolvedApiMode, resolve_model_name
37
+ from .models import (
38
+ CommitSummary,
39
+ ConventionalAnalysis,
40
+ ConventionalCommit,
41
+ ResolvedApiMode,
42
+ resolve_model_chain,
43
+ resolve_model_name,
44
+ )
38
45
  from .normalization import post_process_commit_message
39
46
  from .validation import is_past_tense_first_word, repair_summary_tense, validate_summary_quality
40
47
 
@@ -287,7 +294,6 @@ async def generate_analysis_with_map_reduce(
287
294
  and fires only when the map-reduce path is taken.
288
295
  """
289
296
 
290
- from . import style
291
297
  from .map_reduce import run_map_reduce, should_use_map_reduce
292
298
  from .tokens import create_token_counter
293
299
 
@@ -498,6 +504,39 @@ def decode_cache_payload(tool_name: str, operation: str, stored: str) -> tuple[A
498
504
 
499
505
 
500
506
  async def _run_oneshot_response(config: CommitConfig, spec: OneShotSpec) -> OneShotResponse:
507
+ """Run one request, walking the model chain when a model fails outright.
508
+
509
+ Each candidate gets the full retry budget; a model that still fails — 5xx
510
+ stream stalls, refusals, or a context window that cannot hold the prompt —
511
+ hands off to the next entry of the ``;``-separated chain instead of failing
512
+ the whole run.
513
+ """
514
+
515
+ candidates = resolve_model_chain(spec.model or "")
516
+ for idx, candidate in enumerate(candidates):
517
+ try:
518
+ return await _run_oneshot_attempt(config, replace(spec, model=candidate))
519
+ except (
520
+ LgitError,
521
+ httpx.TimeoutException,
522
+ httpx.TransportError,
523
+ json.JSONDecodeError,
524
+ ValueError,
525
+ TypeError,
526
+ ) as exc:
527
+ if idx == len(candidates) - 1:
528
+ raise
529
+ fallback = candidates[idx + 1]
530
+ style.warn(f"{spec.operation}: {candidate} failed ({_fallback_reason(exc)}); falling back to {fallback}")
531
+ raise LgitError(f"No model candidates configured for {spec.operation}")
532
+
533
+
534
+ def _fallback_reason(exc: Exception) -> str:
535
+ text = str(exc).strip() or type(exc).__name__
536
+ return text if len(text) <= 160 else f"{text[:157]}..."
537
+
538
+
539
+ async def _run_oneshot_attempt(config: CommitConfig, spec: OneShotSpec) -> OneShotResponse:
501
540
  mode = _resolved_mode(config, spec.model or "")
502
541
  cache_entry = _build_cache_entry(config, spec)
503
542
  if cache_entry is not None:
lgit/cli.py CHANGED
@@ -39,7 +39,7 @@ from .diffing import (
39
39
  from .errors import LgitError, NoChanges, ValidationFailure
40
40
  from .map_reduce import FileObservation, should_use_map_reduce
41
41
  from .markdown_output import fallback_summary
42
- from .models import ConventionalAnalysis, ConventionalCommit, Mode, resolve_model_name
42
+ from .models import ConventionalAnalysis, ConventionalCommit, Mode, format_model_chain, resolve_model_name
43
43
  from .normalization import post_process_commit_message
44
44
  from .tokens import create_token_counter
45
45
  from .validation import check_type_scope_consistency, validate_commit_message, validate_summary_quality
@@ -547,7 +547,9 @@ async def _generate_fast_workflow(
547
547
  scope_candidates, _wide = (
548
548
  extract_scope_candidates(numstat, args.target, args.dir, config) if numstat.strip() else ("(none)", False)
549
549
  )
550
- style.status(f"{style.dim('›')} {style.dim('fast mode:')} {style.model(config.effective_fast_model)}")
550
+ style.status(
551
+ f"{style.dim('›')} {style.dim('fast mode:')} {style.model(format_model_chain(config.effective_fast_model))}"
552
+ )
551
553
  style.status(f"{style.info('›')} Analyzing {style.bold(mode.value)} changes...")
552
554
  if changelog_runner is not None:
553
555
  changelog_runner.start_with_diff()
@@ -576,17 +578,17 @@ async def _generate_standard_workflow(
576
578
  with profile.section("create_token_counter", collector):
577
579
  token_counter = create_token_counter(config)
578
580
  if config.analysis_model == config.summary_model == config.effective_map_model:
579
- style.status(f"{style.dim('›')} {style.dim('model:')} {style.model(config.analysis_model)}")
581
+ style.status(f"{style.dim('›')} {style.dim('model:')} {style.model(format_model_chain(config.analysis_model))}")
580
582
  elif config.effective_map_model != config.summary_model:
581
583
  style.status(
582
584
  f"{style.dim('›')} {style.dim('models:')} {style.dim('map')} "
583
- f"{style.model(config.effective_map_model)} {style.dim('analysis')} "
584
- f"{style.model(config.analysis_model)} {style.dim('summary')} {style.model(config.summary_model)}"
585
+ f"{style.model(format_model_chain(config.effective_map_model))} {style.dim('analysis')} "
586
+ f"{style.model(format_model_chain(config.analysis_model))} {style.dim('summary')} {style.model(format_model_chain(config.summary_model))}"
585
587
  )
586
588
  else:
587
589
  style.status(
588
590
  f"{style.dim('›')} {style.dim('models:')} {style.dim('analysis')} "
589
- f"{style.model(config.analysis_model)} {style.dim('summary')} {style.model(config.summary_model)}"
591
+ f"{style.model(format_model_chain(config.analysis_model))} {style.dim('summary')} {style.model(format_model_chain(config.summary_model))}"
590
592
  )
591
593
  with profile.section("prepare_diff", collector):
592
594
  use_map_reduce = should_use_map_reduce(diff, config, token_counter)
lgit/models.py CHANGED
@@ -116,6 +116,37 @@ def resolve_model_name(name: str) -> str:
116
116
  return _MODEL_ALIASES.get(name, name)
117
117
 
118
118
 
119
+ MODEL_CHAIN_SEPARATOR = ";"
120
+
121
+
122
+ def resolve_model_chain(name: str) -> tuple[str, ...]:
123
+ """Resolve a ``;``-separated model chain into ordered full model names.
124
+
125
+ The first entry is the primary model; later entries are fallbacks tried in
126
+ order when a request exhausts its retries against the previous one — for
127
+ example ``"flash-lite;haiku"`` survives a provider that stalls on a stream.
128
+ Blank segments and repeats are dropped; a plain name yields a 1-tuple.
129
+ """
130
+
131
+ resolved: list[str] = []
132
+ for part in str(name).split(MODEL_CHAIN_SEPARATOR):
133
+ candidate = resolve_model_name(part.strip())
134
+ if candidate and candidate not in resolved:
135
+ resolved.append(candidate)
136
+ return tuple(resolved) or ("",)
137
+
138
+
139
+ def format_model_chain(name: str) -> str:
140
+ """Render a model chain for status output as ``primary->fallback``.
141
+
142
+ Provider prefixes carry no information once the model is chosen, so only the
143
+ trailing segment survives: ``"openrouter/google/gemini-3.1-flash-lite;haiku"``
144
+ renders as ``"gemini-3.1-flash-lite->claude-haiku-4-5"``.
145
+ """
146
+
147
+ return "->".join(candidate.rsplit("/", 1)[-1] for candidate in resolve_model_chain(name))
148
+
149
+
119
150
  @dataclass(frozen=True, slots=True)
120
151
  class TypeConfig:
121
152
  """Classification guidance for one conventional commit type."""
@@ -871,7 +902,10 @@ __all__ = [
871
902
  "SUMMARY_GUIDELINE_LENGTH",
872
903
  "Mode",
873
904
  "ApiMode",
905
+ "MODEL_CHAIN_SEPARATOR",
906
+ "format_model_chain",
874
907
  "ResolvedApiMode",
908
+ "resolve_model_chain",
875
909
  "resolve_model_name",
876
910
  "TypeConfig",
877
911
  "CategoryMatch",
lgit/tokens.py CHANGED
@@ -8,6 +8,8 @@ from urllib.parse import urljoin
8
8
 
9
9
  import httpx
10
10
 
11
+ from .models import resolve_model_chain
12
+
11
13
 
12
14
  @dataclass(slots=True)
13
15
  class TokenCounter:
@@ -62,7 +64,9 @@ def create_token_counter(config: object) -> TokenCounter:
62
64
  return TokenCounter(
63
65
  api_base_url=str(getattr(config, "api_base_url", "http://localhost:4000")),
64
66
  api_key=getattr(config, "api_key", None),
65
- model=str(getattr(config, "analysis_model", getattr(config, "model", "claude-opus-4.8"))),
67
+ model=resolve_model_chain(str(getattr(config, "analysis_model", getattr(config, "model", "claude-opus-4.8"))))[
68
+ 0
69
+ ],
66
70
  timeout=float(getattr(config, "connect_timeout_secs", 10) or 10),
67
71
  )
68
72
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: lgit-cli
3
- Version: 5.3.0
3
+ Version: 5.4.0
4
4
  Summary: AI-powered git commit message generator using Claude and other LLMs via OpenAI-compatible APIs
5
5
  Project-URL: Homepage, https://github.com/can1357/llm-git
6
6
  Project-URL: Repository, https://github.com/can1357/llm-git
@@ -164,9 +164,11 @@ Create `~/.config/llm-git/config.toml`:
164
164
  api_base_url = "http://localhost:4000" # Default: LiteLLM proxy
165
165
  api_key = "sk-..." # Or use LLM_GIT_API_KEY env var
166
166
 
167
- # Model
167
+ # Model — any role accepts a `;`-separated fallback chain, tried left to right
168
168
  analysis_model = "claude-sonnet-4.5" # Diff analysis / classification
169
169
  summary_model = "claude-haiku-4-5" # Summary line generation
170
+ map_model = "" # Per-file map phase; empty = summary_model
171
+ fast_model = "flash-lite;haiku" # Fast mode; falls back when the primary stalls
170
172
 
171
173
  # Commit message limits
172
174
  summary_guideline = 72 # Target length
@@ -1,10 +1,10 @@
1
- lgit/__init__.py,sha256=y37z3-HahOME0CKTU7Gg3UHxN57G4ovK1mogGUs0iTc,1767
1
+ lgit/__init__.py,sha256=IY7A9AjLTKfI6O4w71fGDa2D4wb3F6pGWuwgTqEKz3I,1767
2
2
  lgit/__main__.py,sha256=VbaRO8-0ehWv7zA27BpyHYWTQVvt5M-aG5HnWr7ws0U,165
3
3
  lgit/analysis.py,sha256=j8bduuV6pqvMuza-r_RNJDe5SMQGKTtU6gwktaAeSS4,10671
4
- lgit/api.py,sha256=Ypo6-6Y3fHKT_zJvzyZMClg5NUi6uCv6NK4paEYWrxo,38129
4
+ lgit/api.py,sha256=vWy8H3Ze6c0bIEGtJJEpXMmduAIBUvkEtkxbvK8R5Aw,39474
5
5
  lgit/cache.py,sha256=mrF5g74HMP9FR9kCJgwBcT4l34DuAuBaAkC1pCV7x6M,12477
6
6
  lgit/changelog.py,sha256=HGuz2qeM_2m8uV2x36X79OP5SL9Wn0JxFhfvk4oCG_o,37264
7
- lgit/cli.py,sha256=nqvrJZfLxkYwjHSPNqaajZKe_PCPRcpDkfING3crhto,52778
7
+ lgit/cli.py,sha256=eItsGYXIAg1aFS73W-2wua6jh55s_XA6h-MSq3eUQRk,52952
8
8
  lgit/compose.py,sha256=g4HW7NDNR9ynFtDk9TtPBuHvTnhHOUUrG3NAX7N4HC0,83243
9
9
  lgit/config.py,sha256=GkldpfMAX8T7Vzkl5RVY3eTgNM8Dalqntf2IuUmFnrg,14749
10
10
  lgit/diffing.py,sha256=USk8qws0kXEfTlphvf7-hMyBdqdOD9H7i7UOimm99SY,17595
@@ -12,7 +12,7 @@ lgit/errors.py,sha256=DkPJKA2ag5KbBoyuRk1d8zKgz9Mp1qRoLVBGRudlqkg,3457
12
12
  lgit/git.py,sha256=_wavbMwewf0lP1fZrrhgW5yD36jwWUC87Y7jfIikIEk,31543
13
13
  lgit/map_reduce.py,sha256=Tk11z9FT9Ox2pFZEy7Ns-eruyWo62jZokQuUWWCFyqE,20188
14
14
  lgit/markdown_output.py,sha256=mgRLhpa9TBr3AVCoFaMYktXPYfxh6NqM75xpcudYexA,26355
15
- lgit/models.py,sha256=hc3AJ37YXoLBGgSbdLQN5EEnDNViXf-wywlkUW92_Z8,28942
15
+ lgit/models.py,sha256=2D1QMK2PBg0W-zJRmEm_-qMuQea75LqGqEJwvmS3WcE,30221
16
16
  lgit/normalization.py,sha256=Kj_xqLw_fLDkN7wTFtAbwlEAD8t_s8v8JEGcLWLG8DM,11889
17
17
  lgit/patch.py,sha256=6Nx66t8pFZf4iNJS8nxxdtbSjiYk737EZVPpZscW4G0,30579
18
18
  lgit/pricing.py,sha256=uVBsXKOp7WLWswiHOQO_0HMsnZotOQUB53XgstRn8B8,6342
@@ -22,7 +22,7 @@ lgit/repo.py,sha256=eflCUY_XvTx8NY-KES5_BsyxpQczFEiT46eV2Fi4itQ,8926
22
22
  lgit/rewrite.py,sha256=PX6Pf7fS9ySU5DFdsvR2apecX_A6tZ8u5jTbnOERm5U,8771
23
23
  lgit/style.py,sha256=gfQYsUU-6nZFVhFkDBw6kWpsC3y7cGjOyUCJTV9ModY,7504
24
24
  lgit/templates.py,sha256=8wjtsSE9hfr3zYa4yHCxbg0YlUU2b7urQM1jD-uuuKY,12298
25
- lgit/tokens.py,sha256=BbAhjIUtCXVBStPXzq4ZeuZa8H5r9ZqZJUnA1XHD_MI,3123
25
+ lgit/tokens.py,sha256=WUKRvEcfQMZsbj5tjzPV4LTEWxm49He9-7vZLuHDg8o,3210
26
26
  lgit/validation.py,sha256=l1BMjyscypImLUHxA6f_igyHNkGEZF0-MTAR3qKCxdk,19214
27
27
  lgit/resources/__init__.py,sha256=w6eXZjQeAp_h24IJu_GhNIZelcSMuM3qk8GOmWLQPaQ,53
28
28
  lgit/resources/commit_types.json,sha256=IPtUig1U8UAIFnfMVaszQFI_LOZIiaZ2yyE20J1FG1E,11900
@@ -42,8 +42,8 @@ lgit/testing/compare.py,sha256=jRY98uLclVPyQ7e1TMqFVz2cjUi6kwwn2dkQyR_xsgY,1834
42
42
  lgit/testing/fixture.py,sha256=VXk02ZzFTBHHhYax6bsoGowdyz06nmrJm3ylenyfGbU,13654
43
43
  lgit/testing/report.py,sha256=wb7YnP_lsYwsg5OIFtsIC1bMHtK42Mttul_zQcwRNpk,9036
44
44
  lgit/testing/runner.py,sha256=5Sr4QvEOTdE7CAxB-CKcNJClEZARQGqB-t_6P6-UA2c,9514
45
- lgit_cli-5.3.0.dist-info/METADATA,sha256=07djXpV_LJpdd8TU6Vz-RFYpBgGwiWAuAl4gqgJ6DQI,9565
46
- lgit_cli-5.3.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
47
- lgit_cli-5.3.0.dist-info/entry_points.txt,sha256=CUSsokc0V3oVHQ2Z1ocL09wV7Krhm0SSfLZpnRMBdA0,39
48
- lgit_cli-5.3.0.dist-info/licenses/LICENSE,sha256=6dqVzjngLuIcUMd4wWLXPLpv-Pi8gySZAEE3hSN5iKw,1076
49
- lgit_cli-5.3.0.dist-info/RECORD,,
45
+ lgit_cli-5.4.0.dist-info/METADATA,sha256=soDetjx0tsbdvAEE_oTo7JbRstNZK7QxwBKGtb0L9IM,9814
46
+ lgit_cli-5.4.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
47
+ lgit_cli-5.4.0.dist-info/entry_points.txt,sha256=CUSsokc0V3oVHQ2Z1ocL09wV7Krhm0SSfLZpnRMBdA0,39
48
+ lgit_cli-5.4.0.dist-info/licenses/LICENSE,sha256=6dqVzjngLuIcUMd4wWLXPLpv-Pi8gySZAEE3hSN5iKw,1076
49
+ lgit_cli-5.4.0.dist-info/RECORD,,