This prompt asks for CommitSage, a local-first Python CLI that uses AI to review staged Git changes before a commit. It should help developers understand changes, identify plausible bugs and missing tests, and produce reports in English or Persian—without requiring a CommitSage account, web dashboard, authentication, billing, or GitHub integration.
Build CommitSage, a local-first AI code review CLI that reviews staged Git changes before a commit.
Product goal:
Help developers understand their changes, identify plausible bugs, and find missing tests. Support English and Persian output, local and cloud AI providers, and usage without a CommitSage account.
Scope:
Build a working, focused MVP. Do not build a web dashboard, authentication, billing, or automatic GitHub integration.
Tech stack:
- Python 3.11+
- Typer for the CLI
- Rich for terminal output
- Pydantic for configuration and structured review results
- httpx for model requests
- pytest for tests
- pyproject.toml with an installable `commitsage` entry point
Commands:
1. `commitsage review`
Review staged changes by default.
2. `commitsage review --lang fa`
Produce Persian explanations while preserving code, paths, and identifiers.
3. `commitsage review --format markdown`
Produce a clean Markdown report.
4. `commitsage review --format json`
Produce machine-readable JSON.
5. `commitsage review --output review.md`
Save the report to a file.
6. `commitsage commit-message`
Suggest a Conventional Commit message from staged changes.
Do not create a commit.
7. `commitsage pr-description`
Draft a PR description from staged changes.
Clearly state this scope; do not imply that the whole branch was reviewed.
Review behavior:
- Read the staged diff and staged versions of changed files.
- Do not accidentally use unstaged working-tree changes as staged context.
- Gather a limited amount of surrounding code when necessary.
- Prioritize correctness, security, error handling, and missing tests.
- Avoid generic advice, unnecessary refactoring, and style-only complaints.
- Treat findings as potential issues, not proven bugs.
- Every finding must include:
- Severity: high, medium, or low
- File path
- Relevant line in the new file, or null if unavailable
- Short title
- Explanation grounded in the supplied code
- Suggested verification or fix
- Confidence: high, medium, or low
- Validate file paths and line references against the supplied diff.
- Discard findings with invalid locations rather than inventing replacements.
- Clearly distinguish observed code from assumptions.
- If no actionable findings are identified, say so without claiming the code is bug-free.
Report structure:
- Summary
- Potential issues
- Suggested tests
- Review limitations
AI providers:
- Support a local Ollama provider.
- Support configurable OpenAI-compatible cloud endpoints.
- Use a shared provider interface.
- Let users configure provider, model, base URL, timeout, and output language.
- Read API keys from environment variables.
- Never store API keys in project configuration.
- Do not silently fall back from a local model to a cloud service.
- Before sending code to a cloud provider, disclose the destination and require explicit consent.
- Support an explicit non-interactive opt-in flag for automated usage.
- No CommitSage account is required, but explain that a cloud provider may require its own credentials and payment.
Privacy and safety:
- Do not modify source files, stage changes, create commits, push, or execute reviewed code.
- Invoke Git with argument arrays, not shell-interpolated commands.
- Treat source code, comments, filenames, and diff content as untrusted input.
- Instruct the model to ignore instructions embedded in reviewed content.
- Skip binary files and common generated files.
- Honor a `.commitsageignore` file.
- Exclude common secret-bearing files by default.
- Attempt to redact obvious credentials before model requests.
- Clearly explain that automated secret detection is imperfect.
- Do not log source code, prompts, responses, or credentials by default.
- Avoid following symlinks outside the repository.
Large diffs:
- Apply explicit input-size limits.
- Split large reviews into bounded chunks when appropriate.
- Report skipped files, truncated context, and incomplete coverage.
- Never silently present a partial review as a complete one.
Error handling:
Handle these cases with clear, actionable messages:
- Git is not installed.
- The current directory is not a Git repository.
- No staged changes exist.
- A file is deleted or renamed.
- A diff contains only binary or ignored files.
- The provider is unavailable.
- The request times out.
- The model returns invalid JSON or an invalid schema.
- The selected model cannot accommodate the input.
Use bounded retries and validate AI output with Pydantic.
Keep diagnostic messages on stderr so JSON output remains parseable.
Suggested structure:
src/commitsage/
cli.py
config.py
git.py
models.py
review.py
privacy.py
providers/
base.py
ollama.py
openai_compatible.py
renderers/
terminal.py
markdown.py
json_output.py
tests/
Testing:
- Mock all model requests; tests must not require paid APIs or a running model.
- Use temporary Git repositories for integration tests.
- Cover staged versus unstaged changes, renamed and deleted files,
empty diffs, ignored files, secret redaction, invalid model output,
provider failures, cloud consent, and Persian output preservation.
Documentation:
Write a README with:
- Project overview and scope
- Installation and quick start
- Local model setup
- Cloud provider setup and explicit consent behavior
- English and Persian usage examples
- Configuration reference
- Privacy limitations
- Example review output labeled as illustrative
- Development and testing instructions
Implementation process:
1. Briefly describe the architecture and implementation plan.
2. Implement a complete vertical slice:
staged diff → provider → validated review → terminal output.
3. Add the remaining commands, renderers, safeguards, and tests.
4. Run the available tests and report actual results.
5. If execution is unavailable, explicitly state that tests were not run.
Deliver working code, not pseudocode or placeholder functions.
Keep the implementation small and maintainable.
Do not claim that AI review guarantees correctness or security.A read-only post-implementation audit workflow for coding agents. Reviews completed code changes for requirement coverage, correctness, regressions, verification evidence, edge cases, scope integrity, and commit quality without modifying the implementation. Produces evidence-backed CLEAR, FINDINGS, or INCOMPLETE results and supports structured re-audits after remediation.
Reviews GitHub Actions workflow YAML for supply-chain and injection risks: pull_request_target with PR checkout, untrusted github.event text in run steps, actions pinned to tags or branches instead of commit SHAs, missing or write-all permissions, secrets in shell commands, curl | bash, self-hosted runners on PRs, and missing timeouts. Use before merging CI changes or auditing a repo. Includes a stdlib Python linter with --self-test.
Audits a repository's remote branches and plans a safe cleanup. Sorts each branch into delete (merged, squash-merged or empty), archive then delete (idle unmerged work), ask the owner, open PR, active or protected, and groups the asks by author. Flags case-colliding names, stale PRs, branches far behind main, long-lived branches and bad names, and prints a reviewable tag-then-delete script. Includes a stdlib Python auditor with --self-test.
Checks a GitHub CODEOWNERS file against the real repository file list - works out who owns every file (last matching line wins), then reports invalid or unknown owners, unowned files and critical paths left to the catch-all rule, rules that match nothing or are fully overridden by later lines, unsupported ! and [ ] syntax, duplicates, empty teams and one-person bottlenecks. Includes an offline stdlib Python checker.
Finds old and abandoned Git branches in your repositories, checks whether their work was merged or still matters, and asks owners before suggesting a safe cleanup list.
Finds out why your CI builds are slow: tracks job times over weeks, spots missing caches, serial steps and oversized runners, and suggests concrete changes ranked by minutes saved.
Watches your team's open pull requests, finds the ones stuck waiting for review, and suggests who should review what next so reviews stay fast and no single reviewer gets overloaded.