Be the first to rate this article.
Processing...
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 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.
Comments & Questions (0)
No comments yet
Be the first to comment!