Metadata-Version: 2.4
Name: code-council
Version: 1.0.0
Summary: Multi-agent code review. Several LLM reviewers, one merged report. Review mode and diff mode, CLI and local web UI.
Author: Filip Dimitrijević
License-Expression: MIT
Project-URL: Homepage, https://github.com/Cofson/code-council
Project-URL: Repository, https://github.com/Cofson/code-council
Project-URL: Issues, https://github.com/Cofson/code-council/issues
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Provides-Extra: mcp
Requires-Dist: mcp<2,>=1; extra == "mcp"
Dynamic: license-file

# code-council

Multi-agent code review. Several LLM reviewers read your code, each from its own angle, and a judge merges what they found into one prioritised report. It has two modes:

- **Review:** paste code (a function, a file, several files) and get improvement suggestions based on established best practices.
- **Compare:** paste an old and a new version and find out what got better, what got worse, and what new problems the change introduced.

It runs as a CLI or a local web UI. It only gives suggestions and never changes your code.

Sibling project: [spec-council](https://github.com/cofson/spec-council) does the same for specifications. code-council is for code only.

```mermaid
flowchart LR
    A[Code<br/>or old + new version] --> R1[Correctness]
    A --> R2[Security]
    A --> R3[Maintainability]
    A --> R4[Performance]
    R1 & R2 & R3 & R4 --> J[Judge<br/>merges, de-duplicates, ranks]
    J --> V[Fact-check<br/>flags questionable suggestions]
    V --> O[Report<br/>fix first · disagreements · nice to have]
```

## Why several reviewers

One model asked to "review this code" tends to give a generic, evenly weighted list. Reviewers with narrow roles go deeper in their own area, and they sometimes disagree, for example security against simplicity or performance against readability. The judge shows those conflicts openly instead of hiding them in an average. You can also mix providers, so one model's blind spots get caught by another.

## Features

- **Configurable reviewers.** Each one is defined in TOML: name, role in plain words, provider and model. Add, remove or rewrite roles freely.
- **Several providers.** Anthropic, OpenAI, Gemini and local models through Ollama, mixed in one council, called over plain HTTP. No SDKs and no runtime dependencies.
- **Structured findings.** Every finding has a severity, a location (line or symbol), the issue, a suggestion and an optional fix snippet. Findings are sorted by severity.
- **Fact-check pass.** An optional AI verifier flags questionable findings without deleting the original suggestions. It can be wrong; human review is required.
- **Diff mode.** Findings are labelled `improved`, `regressed`, `new` or `unchanged`, and the run ends with a verdict: better, worse, mixed or same.
- **Parallel reviewers.** Reviewers run concurrently up to the configured parallelism limit.
- **Fault tolerant.** If one reviewer fails (bad key, timeout), the rest still report and the error is shown.
- **Local web UI.** Paste code, read the report, download it as Markdown. API keys stay on the server side.
- **Offline mode.** A mock provider runs the whole flow without API keys, for demos and tests.

## Quick start

For the published package, use `pip install code-council`. Clone the repository for example configurations and development:

```bash
git clone https://github.com/cofson/code-council
cd code-council
pip install -e .

# Offline demo, no API keys (placeholder output)
code-council serve --config examples/agents.mock.toml
# open http://127.0.0.1:8765
```

### Free options

**Local with Ollama.** Free, no API key, and the code never leaves your machine:

```bash
# install Ollama from https://ollama.com, then:
ollama pull qwen2.5-coder:32b      # ~20 GB, needs ~24 GB VRAM; use :14b or :7b on smaller GPUs
code-council serve --config examples/agents.ollama.toml
```

**Gemini free tier.** Get a free key at aistudio.google.com:

```bash
export GEMINI_API_KEY=...
code-council serve --config examples/agents.gemini-free.toml
```

Both configs run reviewers one after another, which suits a single GPU and free-tier rate limits.

### Paid APIs

With real models:

```bash
export ANTHROPIC_API_KEY=...
export OPENAI_API_KEY=...
export GEMINI_API_KEY=...

code-council serve --config examples/agents.toml

# or from the command line
code-council review src/app.py src/db.py --config examples/agents.toml
code-council diff examples/orders_old.py examples/orders_new.py --config examples/agents.toml
```

CLI runs write `runs/<timestamp>/report.md` and `report.json`.

The `examples/orders_*.py` pair is a small refactor to try diff mode on. The old version builds SQL by string concatenation and the new one uses a parameterised query.

![code-council comparing two versions with a free local model](docs/ui-diff-ollama-top.jpg)

*A real run in compare mode: three reviewers, a judge and a fact-check pass on Qwen2.5-Coder 32B through Ollama, on a MacBook, at no cost. [Full-page screenshot](docs/ui-diff-ollama.jpg).*

**Real output, unedited, across three iterations:**

- [First run](docs/example-report-ollama-before.md). All three reviewers flagged the SQL injection as critical and the verdict was right. But the judge listed already-fixed issues as things to fix, and no reviewer noticed that `apply_discount` still doesn't validate its input.
- [After rewriting the diff-mode judge prompt](docs/example-report-ollama-after.md). The report now separates **What improved** from **Still to fix**, and the `apply_discount` check is caught. Two weak suggestions remained: renaming the SELECT columns is not useful, and the tip to use `with sqlite3.connect(...)` instead of `closing(...)` is wrong, because a sqlite3 connection used as a context manager commits or rolls back but does not close. These led to the **fact-check pass** and stricter reviewer rules (no renaming of things defined outside the code, no fix unless it is known to be correct). The reports are kept unedited as a record of the problems these changes address.
- [With stricter reviewers and the fact-check pass](docs/example-report-ollama-factcheck.md). Both wrong suggestions are gone, and "Still to fix" holds only the one real remaining issue: `apply_discount` doesn't reject negative prices or percentages over 100. The verdict, *better*, is correct.

Treat the report as a reviewer's opinion, not a guarantee. Larger models and mixed providers catch more.

## Automated GitHub PR reviews

After merging the workflow into your default branch, configure repository Actions secrets `ANTHROPIC_API_KEY`, `OPENAI_API_KEY` and `GEMINI_API_KEY` for the example mixed-provider council. The workflow skips reviews if any key is missing. It reviews non-draft same-repository PRs on open, update or reopen and updates one bot comment. Forks are skipped. It checks out only the trusted base revision, never the PR head, and sends selected patch text to the configured external providers. Review only code you are authorized to disclose. The report is advisory, patch-only, and limited to 15 supported files and 30,000 characters; skipped files are counted. API usage may incur costs. The first review can run only after the workflow is merged.

## Config

```toml
[run]
parallel = 4

[[reviewers]]
name = "Correctness"
role = "Find bugs, wrong logic, unhandled edge cases, error handling gaps and race conditions."
provider = "anthropic"
model = "claude-sonnet-4-5"

[[reviewers]]
name = "Security"
role = "Find security issues. Think like an attacker."
provider = "openai"
model = "gpt-4o"

[judge]
provider = "anthropic"
model = "claude-sonnet-4-5"
```

Model names change often. Use the ones your accounts have access to.

## Limits

- **Context, not repository.** The reviewers see only the code you paste. They can't follow imports or run the code, so a finding about something defined elsewhere may be wrong. The input limit is 120,000 characters per run.
- **LLM findings are suggestions.** They can be wrong or miss things. Treat the report as a reviewer's opinion, not a verdict, and keep your tests and human review.
- **Cost.** Each run normally makes one call per reviewer, one for the judge and an optional fact-check call; fallback attempts can add calls.
- **Testing.** The test suite covers the full flow, the CLI and the web API offline with the mock provider, and the Ollama provider against a fake server. Real runs so far: local Qwen2.5-Coder 32B via Ollama (reports above). The manual live-validation workflow also exercises Ollama on a CPU runner with Qwen2.5-Coder 1.5B. Cloud providers are not covered by that live test. The 7B benchmark on five synthetic cases identified all four expected issues on manual inspection (75% keyword recall), with no findings on the single clean control. This is not a general accuracy estimate.

## Development

```bash
pip install -e ".[dev]"
pytest -q
```

## How this was built

Directed by Filip Dimitrijević (scope, priorities, review) and built with AI assistance (Claude).

## License

[MIT](LICENSE)

## Additional capabilities and maturity

- [Fallback providers](docs/fallback.md)
- [Project policy](docs/project-policy.md)
- [Advanced PR review](docs/advanced-review.md) (raw AI findings are not verified)
- [Cost estimates](docs/cost-estimation.md) (not billing totals)
- [Local history](docs/history.md)
- [MCP server](docs/mcp.md) (optional dependency)
- [VS Code extension](extensions/vscode/README.md) (development host)
- [Docker](docs/docker.md)
- [Benchmarks](docs/benchmarks.md)
- [Release readiness](docs/release-1.0.md)

AI suggestions require human review. Configured remote providers receive submitted source code. Do not submit secrets or code you are not authorized to share.
