How krystalunity/krystal-quorum works
1. Krystal Quorum is a Python CLI package that acts as a review gate, not an agent runtime. Its job is to review a markdown plan before implementation and, separately, review an implementation diff after code changes.
2. The top-level entry points are the CLI and module launcher (krystal_quorum.cli, __main__.py). From there the tool fans out into three user-facing workflows: review, demo, and init for installing agent import packs.
3. The core plan-review pipeline is: load a plan document, build reviewer prompts, send the plan to one or more reviewers, parse strict JSON responses, then reconcile the reviewer outputs into one verdict and human-readable summary.
4. Reviewer execution is abstracted behind adapter types in src/krystal_quorum/reviewers/. The repository supports local mock reviewers, command-based reviewers, Ollama-backed reviewers, OpenAI-compatible reviewers, and a hosted reviewer mode. This is the main “pluggable backend” boundary.
5. Reconciliation is a first-class subsystem, not a simple vote count. The codebase has dedicated modules for commitments, issue matching, diversity, approvals, and general reconcile logic. The system is intentionally safety-biased: a single BLOCK can veto the merged result, and low diversity or singleton blockers reduce confidence.
6. Diff review is a separate subsystem with its own models, prompts, formatting, persistence, and reconciliation path. Files such as diff_service.py, diff_models.py, diff_prompts.py, diff_reconcile.py, and diff_persist.py indicate that plan review and diff review share the same architectural pattern but are handled independently.
7. Persistence is local and append-only under .krystal-quorum/reviews/. The CLI writes raw reviewer outputs, merged summaries, and artifact metadata so the user can inspect what happened after the run. This artifact directory is also what the GitHub Action exposes as build output.
8. Configuration is split between CLI flags, project config, and environment variables. config.py, reviewer_specs.py, and the integration docs indicate that reviewers can be declared in TOML, while runtime secrets and endpoints come from env vars such as OpenAI keys, Ollama base URLs, or the hosted API token.
9. The repository has a clear boundary between local and hosted infrastructure. Local mode talks directly to tools or model servers on the machine/network; hosted mode submits the same plan to Krystal Unity’s control plane and polls for completion. The README also notes that hosted reviewers are exclusive in v1 and are not mixed with local reviewers in one command.
10. GitHub Actions support is a separate delivery surface. integrations/github-action/ and action.yml wire the CLI into pull-request checks, usually in diff mode with explicit base/head SHAs. The action is designed to emit artifacts and fail the workflow on revise/block outcomes.
11. Agent import packs are another integration layer, distinct from the core reviewer engine. The templates under src/krystal_quorum/templates/agent_integrations/ and the docs in integrations/ install prompt files or skill files for specific agent ecosystems such as Claude Code, Codex, Copilot, Hermes, OpenClaw, and OpenCode.
12. Validation is broad and architecture-relevant: tests/ covers CLI behavior, adapters, diff flow, reconciliation, persistence, GitHub Action wiring, and end-to-end plan-to-diff behavior. benchmarks/ and experiments/ exist to compare reviewer behavior and consensus matching, showing that the repository treats review quality as a measurable subsystem.
Main entry points: reconcile.py Reconcile · base.py Reviewer API · cli.py CLI · diff_service.py Diff service
Components 24
Entry points
CLI and module launcher surface.
- CLI · Top-level command routing for review, demo, and init.
src/krystal_quorum/cli.py - Module run · Module entry point for python -m execution.
src/krystal_quorum/__main__.py - Init command · Installs agent import packs and related templates.
src/krystal_quorum/init_command.py
Plan review
Core markdown-plan review pipeline.
- Plan prompts · Builds reviewer prompts for plan review.
src/krystal_quorum/prompts.py - Plan models · Data models for plan review input and outputs.
src/krystal_quorum/models.py - Reconcile · Merges reviewer outputs into one verdict and summary.
src/krystal_quorum/reconcile.py
Diff review
Separate code-diff review pipeline.
- Diff service · Coordinates the separate diff-review workflow.
src/krystal_quorum/diff_service.py - Diff models · Data structures for diff review inputs and outputs.
src/krystal_quorum/diff_models.py - Diff prompts · Constructs prompts for code-diff review.
src/krystal_quorum/diff_prompts.py - Diff reconcile · Reconciles diff-review responses using the same pattern as plan review.
src/krystal_quorum/diff_reconcile.py - Diff store · Persists diff-review artifacts and results.
src/krystal_quorum/diff_persist.py
Reviewer backends
Pluggable execution adapters for local and hosted reviewers.
- Reviewer API · Shared reviewer interfaces and abstractions.
src/krystal_quorum/reviewers/base.py - Mock backend · Deterministic local reviewer for testing and demos.
src/krystal_quorum/reviewers/mock.py - Command backend · Runs external commands as reviewers.
src/krystal_quorum/reviewers/command.py - Ollama backend · Talks to a local or networked Ollama model server.
src/krystal_quorum/reviewers/ollama.py - OpenAI backend · Uses OpenAI-compatible API endpoints.
src/krystal_quorum/reviewers/openai_compatible.py - Hosted mode · Submits reviews to the Krystal Unity control plane.
src/krystal_quorum/hosted.py
Integrations
Delivery surfaces for GitHub Action and agent import packs.
- GitHub Action · Wires the CLI into pull-request checks and artifact output.
integrations/github-action/action.yml - Agent packs · Templates for installing agent import packs across ecosystems.
src/krystal_quorum/templates/agent_integrations/common/quorum-review.md
Core services
Shared policies, persistence, config, and reconciliation utilities.
- Commitments · Tracks explicit commitments used during reconciliation.
src/krystal_quorum/commitments.py - Issue match · Matches reviewer findings across responses.
src/krystal_quorum/issue_matching.py - Diversity · Scores reviewer diversity and lowers confidence for near-duplicates.
src/krystal_quorum/diversity.py - Approval · Safety-biased BLOCK/approve logic for final verdicts.
src/krystal_quorum/approval.py - Review store · Writes raw outputs, summaries, and metadata under local review artifacts.
src/krystal_quorum/persist.py
Connections 29
- Module run → CLI: launches · Module execution enters the same CLI surface.
- CLI → Init command: routes init · CLI dispatches to package/install workflows.
- CLI → Plan prompts: review flow · Review command builds prompts from plan input.
- CLI → Plan models: loads input · CLI feeds plan and review models into the pipeline.
- Plan prompts → Reviewer API: send prompts · Prompted work is executed through reviewer adapters.
- Reviewer API → Mock backend: adapts · Mock reviewers implement the common reviewer interface.
- Reviewer API → Command backend: adapts · Command-backed reviewers implement the common reviewer interface.
- Reviewer API → Ollama backend: adapts · Ollama-backed reviewers implement the common reviewer interface.
- Reviewer API → OpenAI backend: adapts · OpenAI-compatible reviewers implement the common reviewer interface.
- Reviewer API → Hosted mode: adapts · Hosted reviewers live behind the same boundary.
- Hosted mode → Reconcile: returns verdicts · Hosted mode feeds into the same aggregation step.
- Command backend → Reconcile: local verdicts · Reviewer outputs are merged after execution.
- Ollama backend → Reconcile: local verdicts · Reviewer outputs are merged after execution.
- OpenAI backend → Reconcile: local verdicts · Reviewer outputs are merged after execution.
- Mock backend → Reconcile: local verdicts · Reviewer outputs are merged after execution.
- Reconcile → Commitments: checks · Reconciliation accounts for explicit commitments.
- Reconcile → Issue match: matches · Similar findings are grouped during merge.
- Reconcile → Diversity: scores · Consensus confidence depends on reviewer diversity.
- Reconcile → Approval: applies gate · A single BLOCK can veto the merged result.
- Reconcile → Review store: stores · Merged summaries and raw outputs are written locally.
- CLI → Diff service: routes diff · CLI also exposes a separate diff-review workflow.
- Diff service → Diff prompts: builds · Diff review has its own prompt construction.
- Diff service → Diff models: uses · Diff workflow uses separate models and result types.
- Diff service → Reviewer API: executes via · Diff review reuses the reviewer adapter boundary.
- Diff service → Diff reconcile: merges · Diff reviewer outputs are reconciled separately.
- Diff reconcile → Diff store: stores · Diff artifacts and status are persisted independently.
- GitHub Action → CLI: invokes · The action shells into the CLI for PR checks.
- GitHub Action → Diff service: prefers diff · GitHub checks typically run diff review with base/head SHAs.
- Init command → Agent packs: installs · Init copies agent-pack templates into target ecosystems.