|
| 1 | +<div align="center"> |
| 2 | + |
| 3 | +# 👁️ sight Architecture |
| 4 | + |
| 5 | +**AI-Powered Code Review on Diffs** |
| 6 | + |
| 7 | +[](https://go.dev/) |
| 8 | +[]() |
| 9 | + |
| 10 | +</div> |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## 🎯 Overview |
| 15 | + |
| 16 | +sight is an AI-powered code review library for Go. It parses unified diffs, enriches with **code context** and **git history**, and runs **parallel multi-concern reviews** through an LLM provider. |
| 17 | + |
| 18 | +> 💡 No LLM client bundled — consumers inject their own via the `Provider` interface. |
| 19 | +
|
| 20 | +--- |
| 21 | + |
| 22 | +## 🧱 Components |
| 23 | + |
| 24 | +``` |
| 25 | +sight/ |
| 26 | +├── api/openapi.yaml 📜 MCP tool surface reference |
| 27 | +├── cmd/sight/main.go 🖥️ CLI entry (mcp, taint subcommands) |
| 28 | +├── sight.go 📤 Public API: Review(), Finding, Result, Stats |
| 29 | +├── reviewer.go 🔄 Reviewer: parallel concern orchestration |
| 30 | +├── options.go ⚙️ config, With* functions, presets |
| 31 | +├── provider.go 🔌 Provider interface (consumers implement) |
| 32 | +├── severity.go 📊 Re-exports from hawk/shared/types |
| 33 | +├── static_rules.go 🛡️ 30+ static analysis rules |
| 34 | +├── taint_analysis.go 🔗 SSA-based taint tracking |
| 35 | +├── sast_integration.go 🔒 SAST-LLM fusion |
| 36 | +├── autofix.go 🔧 Fix suggestion pipeline |
| 37 | +├── eval.go 📊 Evaluation harness |
| 38 | +├── mcp/ 🔌 MCP server (stdio + HTTP) |
| 39 | +└── internal/ |
| 40 | + ├── diff/ 📄 Unified diff parser |
| 41 | + ├── review/ 🧠 Concerns, prompts, response parsing |
| 42 | + ├── comment/ 💬 Inline comment formatting |
| 43 | + ├── context/ 📖 Code context + git blame |
| 44 | + └── output/ 📊 SARIF and terminal formatters |
| 45 | +``` |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## 📤 Public API |
| 50 | + |
| 51 | +```go |
| 52 | +// 🚀 One-shot review |
| 53 | +result, err := sight.Review(ctx, diffText, |
| 54 | + sight.WithProvider(myLLMProvider), |
| 55 | + sight.Thorough, |
| 56 | +) |
| 57 | + |
| 58 | +// 🔄 Reusable reviewer |
| 59 | +reviewer := sight.NewReviewer(sight.WithProvider(myLLMProvider)) |
| 60 | +result, err := reviewer.Review(ctx, diffText) |
| 61 | + |
| 62 | +// ❌ Check if any findings are above threshold |
| 63 | +if result.Failed() { |
| 64 | + fmt.Printf("Review failed: %d findings\n", len(result.Findings)) |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## 🔌 Provider Interface |
| 71 | + |
| 72 | +```go |
| 73 | +type Provider interface { |
| 74 | + Chat(ctx context.Context, messages []Message, opts ChatOpts) (*Response, error) |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +> Consumers implement this with their LLM client (e.g., using eyrie). hawk wires eyrie as the provider via `internal/bridge/sight/bridge.go`. |
| 79 | +
|
| 80 | +--- |
| 81 | + |
| 82 | +## ⚡ Presets |
| 83 | + |
| 84 | +| Preset | Concerns | Speed | |
| 85 | +|--------|----------|:-----:| |
| 86 | +| 🏃 `Quick` | security, correctness | Fast | |
| 87 | +| 📊 `Standard` | security, correctness, style, docs | Medium | |
| 88 | +| 🔬 `Thorough` | all concerns | Slow | |
| 89 | +| 🔒 `SecurityFocus` | security, taint only | Fast | |
| 90 | +| 🤖 `CI` | Standard, fail on High+ | Medium | |
| 91 | + |
| 92 | +--- |
| 93 | + |
| 94 | +## 🔌 MCP Server |
| 95 | + |
| 96 | +```bash |
| 97 | +sight mcp # 📡 stdio transport |
| 98 | +sight mcp --transport http --addr :8080 # 🌐 HTTP transport |
| 99 | +``` |
| 100 | + |
| 101 | +**Tools:** `sight_review` · `sight_describe` · `sight_improve` · `sight_taint` |
| 102 | + |
| 103 | +--- |
| 104 | + |
| 105 | +## 🔎 Findings |
| 106 | + |
| 107 | +| Field | Description | |
| 108 | +|-------|-------------| |
| 109 | +| `Concern` | Review category (security, style, etc.) | |
| 110 | +| `Severity` | 🟢 Info · 🟡 Low · 🟠 Medium · 🔴 High · 🟥 Critical | |
| 111 | +| `File` / `Line` | Location in the diff | |
| 112 | +| `Message` | What was found and why | |
| 113 | +| `Fix` | Suggested fix | |
| 114 | +| `CWE` | CWE reference (security findings) | |
| 115 | +| `Confidence` | 0.0–1.0 score | |
| 116 | +| `InlineComment` | PR-ready inline comment | |
| 117 | + |
| 118 | +--- |
| 119 | + |
| 120 | +## 🛡️ Static Rules + Taint Analysis |
| 121 | + |
| 122 | +**30+ built-in rules** run without LLM overhead — hardcoded secret patterns, SQL injection sinks, unsafe deserialization, etc. Fused with LLM results. |
| 123 | + |
| 124 | +**Taint analysis** (`sight taint --path .`) uses SSA-based cross-function tracking to detect source→sink data flows. Sources, sinks, and sanitizers are configurable. |
0 commit comments