Skip to content

feat: Phase 4 — Graceful Degradation and Prompt Templates - #7

Merged
getdownandcode merged 4 commits into
mainfrom
feat
Sep 15, 2026
Merged

getdownandcode merged 4 commits into
mainfrom
feat

Conversation

@getdownandcode

@getdownandcode getdownandcode commented Sep 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Phase 4 implements prompt templates and graceful degradation as specified in plan.md. If the LLM provider is down, rate-limited, offline, or unauthenticated, gitmate automatically catches the failure, displays a clear warning, and derives a high-quality commit message directly from diff metadata without an LLM call.

Changes

  • Versioned Prompt Templates (src/gitmate/templates/):
    • commit_conventional.txt: Conventional Commits prompt (version: 1).
    • commit_plain.txt: Plain imperative commit prompt (version: 1).
    • pr_summary.txt: Structured PR summary description prompt (version: 1).
  • Prompt Engine (src/gitmate/prompt.py):
    • PromptTemplate dataclass with version_key for diskcache hashing.
    • load_template() reads templates via importlib.resources.
    • render_commit_prompt() interpolates $diff and $summary_note safely via string.Template.
  • Heuristic Fallback Generator (src/gitmate/fallback.py):
    • generate_fallback_message(): zero LLM calls, completely offline.
    • Analyzes diff statuses (added, modified, deleted, renamed), paths, and extensions to generate conventional and plain commit messages.
  • Graceful Degradation Orchestrator (generate_commit_message in src/gitmate/fallback.py):
    • Integrates token budgeting, prompt rendering, and cached provider call.
    • Catches ProviderUnavailable and TokenBudgetError, warns the user, and produces the fallback message.
    • Accepts optional secret_store dependency injection; catches KeyringError safely when OS store is unavailable.
    • Returns structured GenerationResult tracking is_fallback and fallback_reason.
  • Documentation & Class Diagram:
    • README.md updated for Phase 4 usage.
    • docs/class-diagram.drawio updated with Phase 4 architecture and re-exported to docs/class-diagram.png (score: 0, 0 errors).
  • Test Suite:
    • 35 new tests across tests/test_prompt.py, tests/test_fallback.py, tests/test_orchestrator.py, and tests/test_config.py.
    • 153/153 tests passing.

Verification

  • uv run pytest: 153 passed.
  • uv run ruff check .: clean.
  • uv run ruff format --check .: 23 files formatted.
  • uv run mypy src tests: clean strict type check across 21 source files.
  • GitHub Actions CI: All checks passing (Job 104284065706, 104284054334).

- Prompt templates in templates/ (commit_conventional.txt, commit_plain.txt, pr_summary.txt) with embedded version headers
- Prompt engine in prompt.py with PromptTemplate, load_template, and render_commit_prompt using string.Template interpolation
- Deterministic template-based fallback generator in fallback.py for offline commit message derivation from diff metadata
- Graceful degradation in generate_commit_message catching ProviderUnavailable/TokenBudgetError with visible warning
- 31 new tests in test_prompt.py, test_fallback.py, and test_orchestrator.py (149 passed)
- README.md and class diagram updated for Phase 4
@getdownandcode
getdownandcode merged commit 733af12 into main Sep 15, 2026
2 checks passed
getdownandcode added a commit that referenced this pull request Sep 19, 2026
…d orchestrator consolidation

- #1 (Blocker): Fail loud with exit code 1 on git errors, budget cap breaches, and gh CLI errors across pr-summary and changelog CLI commands.
- #2: Prevent duplicate printing when no changes/commits exist by early returning None.
- #3: Route diagnostic warnings, budget alerts, and error messages to stderr console (err_console) to keep stdout clean for Unix piping.
- #4: Correctly parse and surface breaking changes (exclamation mark and BREAKING CHANGE: footers) in conventional commits and templates.
- #5: Bump changelog template to version 2, including from_ref..to_ref range and explicit release headers.
- #6: Support --title (-t) flag in pr-summary and propagate gh pr create failures.
- #7: Remove dead head argument from fallback PR summary.
- #8: Consolidate duplicate budget checking, safe telemetry recording, and heuristic token counters into orchestrator.py.
- #9: Enforce strict type hints with CommitLogEntry in fallback.py.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant