𝗕𝘂𝗶𝗹𝗱 𝗮 𝗟𝗼𝗰𝗮𝗹 𝗔𝗜 𝗖𝗼𝗱𝗲 𝗥𝗲𝘃𝗶𝗲𝘄𝗲𝗿 𝘄𝗶𝘁𝗵 𝗢𝗹𝗹𝗮𝗺𝗮

Your CI is green but shallow. A teammate might miss a simple bug because they are busy. You can build a second pair of eyes using a local LLM.

You can create a TypeScript CLI that reviews your staged git diff before you commit. This keeps your code private. It uses no API keys and no cloud providers.

How the tool works:

• Grab the staged diff using git diff --cached. • Send the diff to Ollama with a specific prompt. • Request JSON output and validate it with Zod. • Print findings to your terminal. • Set it as a pre-commit hook.

Technical choices for better results:

• Use --no-color to remove ANSI codes from the prompt. • Use -U3 to provide three lines of context for the model. • Set temperature to 0 for deterministic results. • Use a specific system prompt to ignore style and naming preferences.

Focus the model on logic errors, null access, and security issues. Tell it what to ignore. Telling a small model what not to report is more effective than telling it what to find.

A practical workflow for local models:

• Use qwen2.5-coder:7b for your git hook. • Use qwen2.5-coder:1.5b for fast local testing. • Only block commits on high severity bugs. • Let medium and low severity findings be advisory.

Local models are not staff engineers. They miss complex logic that spans multiple files. They also produce false positives. However, they catch the small mistakes like missing awaits or wrong operators.

Use this tool to catch careless bugs before they reach a pull request. It saves your team time and keeps your code clean.

Source: https://dev.to/pavelespitia/building-a-local-ai-code-reviewer-with-ollama-that-catches-bugs-before-your-team-49d3

Optional learning community: https://t.me/GyaanSetuAi