repotoire 0.3.91

Graph-powered code analysis CLI. 108 detectors for security, architecture, and code quality.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# Repotoire 🎼

**Graph-Powered Code Intelligence β€” Local-First, Blazing Fast**

Repotoire builds a knowledge graph of your codebase to detect architectural issues, code smells, and security vulnerabilities that traditional linters miss.

[![Crates.io](https://img.shields.io/crates/v/repotoire.svg)](https://crates.io/crates/repotoire)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Rust](https://img.shields.io/badge/rust-1.70+-orange.svg)](https://www.rust-lang.org/)

## Why Repotoire?

Most linters analyze files in isolation. Repotoire sees the **whole picture**:

```
Traditional Linters          Repotoire
─────────────────────        ─────────────────────
file1.py βœ“                   file1.py ──┐
file2.py βœ“                   file2.py ──┼── Knowledge Graph
file3.py βœ“                   file3.py β”€β”€β”˜
                                  β”‚
                             Circular deps?
                             God classes?
                             Dead code?
                             Coupling hotspots?
```

## Quick Start

### Option 1: Download Binary (Easiest)
```bash
# Linux
curl -L https://github.com/Zach-hammad/repotoire/releases/latest/download/repotoire-linux-x86_64.tar.gz | tar xz
sudo mv repotoire /usr/local/bin/

# macOS (Apple Silicon)
curl -L https://github.com/Zach-hammad/repotoire/releases/latest/download/repotoire-macos-aarch64.tar.gz | tar xz
sudo mv repotoire /usr/local/bin/

# macOS (Intel)
curl -L https://github.com/Zach-hammad/repotoire/releases/latest/download/repotoire-macos-x86_64.tar.gz | tar xz
sudo mv repotoire /usr/local/bin/
```

### Option 2: Cargo Binstall (No cmake needed)
```bash
cargo binstall repotoire
```

### Option 3: Cargo Install
```bash
cargo install repotoire
```

That's it. No API keys required. No Docker. No cloud account.

## ⚑ Performance

Pure Rust. No external dependencies. Blazing fast.

| Codebase | Files | Time | Speed |
|----------|-------|------|-------|
| Django | 3,000 | 55s | 54 files/sec |
| Express.js | 141 | 0.4s | 350 files/sec |
| Medium project | 500 | ~5s | 100 files/sec |

Progress bars show you what's happening:
```
Processing files... β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘ 75% (375/500) 0:00:08
```

## What It Finds

**108 detectors** across 4 categories:

### πŸ—οΈ Architecture
- Circular dependencies (Tarjan's SCC algorithm)
- Architectural bottlenecks (betweenness centrality)
- Hub dependencies (fragile central nodes)
- Module cohesion problems

### πŸ” Code Smells
- God classes (too many responsibilities)
- Dead code (unreachable functions/classes)
- Feature envy (methods using wrong class data)
- Shotgun surgery (changes ripple everywhere)
- AI-generated code patterns (complexity spikes, churn, naming)

### πŸ”’ Security
- SQL injection patterns
- Hardcoded secrets (API keys, passwords)
- Unsafe deserialization (pickle, yaml.load)
- Eval/exec with user input
- GitHub Actions injection

### πŸ“Š Quality
- Complexity hotspots
- Type hint coverage gaps
- Duplicate code blocks
- Missing tests for new functions

## Sample Output

```
╔════════════════════ 🎼 Repotoire Health Report ════════════════════╗
β•‘  Grade: B                                                          β•‘
β•‘  Score: 82.5/100                                                   β•‘
β•‘  Good - Minor improvements recommended                             β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Category            β”‚ Weight β”‚ Score     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Graph Structure     β”‚  40%   β”‚ 85.0/100  β”‚
β”‚ Code Quality        β”‚  30%   β”‚ 78.3/100  β”‚
β”‚ Architecture Health β”‚  30%   β”‚ 84.2/100  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ” Findings (23 total)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”
β”‚ πŸ”΄ Critical β”‚     2 β”‚
β”‚ 🟠 High     β”‚     5 β”‚
β”‚ 🟑 Medium   β”‚    12 β”‚
β”‚ πŸ”΅ Low      β”‚     4 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜
```

## Supported Languages

| Language | Parsing | Call Graph | Imports | Status |
|----------|---------|------------|---------|--------|
| Rust | βœ… | βœ… | βœ… | **Full Support** |
| Python | βœ… | 🚧 | 🚧 | Parsing only |
| TypeScript | βœ… | 🚧 | 🚧 | Parsing only |
| JavaScript | βœ… | 🚧 | 🚧 | Parsing only |
| Go | βœ… | 🚧 | 🚧 | Parsing only |
| Java | βœ… | 🚧 | 🚧 | Parsing only |
| C/C++ | βœ… | 🚧 | 🚧 | Parsing only |
| C# | βœ… | 🚧 | 🚧 | Parsing only |
| Kotlin | βœ… | 🚧 | 🚧 | Parsing only |

All languages use tree-sitter for parsing, compiled to native code via Rust.

**Note:** Call graph analysis (function calls, imports) is currently implemented for Rust only. Other languages get full AST parsing with class/function/module detection β€” call graph support is actively in development and coming soon!

## CLI Reference

```bash
# Analysis
repotoire analyze .                    # Full analysis
repotoire analyze . --offline          # Skip cloud sync
repotoire analyze . --output report.json
repotoire analyze . --format html

# Graph operations
repotoire ingest .                     # Build graph only
repotoire ask "what calls UserService" # Natural language queries

# Utilities
repotoire doctor                       # Check your setup
repotoire version                      # Show version info
```

### Doctor Output

```
$ repotoire doctor

Repotoire Doctor

βœ“ Python version: 3.12.0
βœ“ Rust extension: Loaded
⚠ API keys: Present: OPENAI | Missing: ANTHROPIC, DEEPINFRA
βœ“ Kuzu database: Importable v0.11.3
βœ“ Disk space (home): 150.2GB free (35% used)
```

## AI-Powered Fixes (Optional)

Bring your own API key β€” or use local AI for free:

```bash
# Cloud providers (pick one):
export ANTHROPIC_API_KEY=sk-ant-...   # Claude (best quality)
export OPENAI_API_KEY=sk-...          # GPT-4
export DEEPINFRA_API_KEY=...          # Llama 3.3 (cheapest cloud)
export OPENROUTER_API_KEY=...         # Any model

# Or use Ollama for 100% local, free AI:
ollama pull llama3.3                  # One-time download
repotoire fix 1                       # Auto-detects Ollama!
```

**Get your key:**
- Anthropic: https://console.anthropic.com/settings/keys
- OpenAI: https://platform.openai.com/api-keys
- Deepinfra: https://deepinfra.com/dash/api_keys
- OpenRouter: https://openrouter.ai/keys
- **Ollama: https://ollama.ai** (πŸ†“ free, runs locally)

No API key and no Ollama? No problem. All analysis works offline.

## Configuration

Create `repotoire.toml` in your repository root for project-specific settings:

```toml
# repotoire.toml - Project Configuration

# Detector-specific overrides
[detectors.god-class]
enabled = true
thresholds = { method_count = 30, loc = 600 }

[detectors.sql-injection]
severity = "high"  # Downgrade from critical for this project
enabled = true

[detectors.long-parameter-list]
thresholds = { max_params = 8 }  # More lenient than default (6)

[detectors.magic-numbers]
enabled = false  # Disable this detector entirely

# Scoring customization
[scoring]
security_multiplier = 5.0  # Weight security findings more heavily (default: 3.0)

[scoring.pillar_weights]
structure = 0.3      # Code structure/complexity (default: 0.4)
quality = 0.4        # Code quality/smells (default: 0.3)
architecture = 0.3   # Architectural health (default: 0.3)

# Path exclusions (in addition to .gitignore)
[exclude]
paths = [
    "generated/",
    "vendor/",
    "**/migrations/**",
    "**/*.generated.ts",
]

# Default CLI flags (can still be overridden via command line)
[defaults]
format = "text"           # Default output format
severity = "low"          # Minimum severity to report
workers = 8               # Parallel workers
per_page = 20             # Findings per page
thorough = false          # Don't run external tools by default
no_git = false            # Include git enrichment
no_emoji = false          # Use emoji in output
fail_on = "critical"      # CI failure threshold
skip_detectors = []       # Always skip these detectors
```

### Alternative Config Formats

Repotoire also supports:
- `.repotoirerc.json` (JSON format)
- `.repotoire.yaml` or `.repotoire.yml` (YAML format)

The search order is: `repotoire.toml` β†’ `.repotoirerc.json` β†’ `.repotoire.yaml`

### Detector Names

Use kebab-case for detector names in config (e.g., `god-class`, `sql-injection`).
The following formats are all equivalent:
- `god-class`
- `god_class`
- `GodClassDetector`

### Inline Suppression

Suppress individual findings with comments:

```python
# repotoire: ignore
def legacy_function():  # This line won't trigger findings
    pass
```

```javascript
// repotoire: ignore
const sqlQuery = `SELECT * FROM ${table}`;  // Suppressed
```

```go
// repotoire: ignore
exec.Command(userInput)  // Suppressed
```

The comment must be on the line before or on the same line as the finding.
Works with `#`, `//`, `/* */`, and `--` comment styles.

## How It Works

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Source  │───▢│ Rust Parser   │───▢│  Kuzu Graph  │───▢│ Detectorsβ”‚
β”‚  Files   β”‚    β”‚ (tree-sitter) β”‚    β”‚  (embedded)  β”‚    β”‚   (108)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
     β”‚                                      β”‚
     β”‚         6 languages                  β”‚      Graph algorithms:
     β”‚         Parallel parsing             β”‚      β€’ Tarjan's SCC
     β”‚         ~100-400 files/sec           β”‚      β€’ Betweenness centrality
     β”‚                                      β”‚      β€’ Community detection
     β”‚                                      β–Ό
     β”‚                               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     └──────────────────────────────▢│   Reports    β”‚
                                     β”‚ CLI/HTML/JSONβ”‚
                                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

**Key components:**
- **Tree-sitter** β€” Fast, accurate parsing for all languages
- **Kuzu** β€” Embedded graph database (no external deps)
- **Rust extension** β€” Native speed for parsing + graph algorithms

## CI/CD Integration

### GitHub Actions

```yaml
- name: Code Health Check
  run: |
    pip install repotoire
    repotoire analyze . --output report.json
    
- name: Fail on critical issues
  run: |
    CRITICAL=$(jq '.findings | map(select(.severity == "critical")) | length' report.json)
    if [ "$CRITICAL" -gt 0 ]; then exit 1; fi
```

### Pre-commit Hook

```yaml
# .pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: repotoire
        name: repotoire
        entry: repotoire analyze . --offline
        language: system
        pass_filenames: false
```

## Comparison

| Feature | Repotoire | SonarQube | CodeClimate |
|---------|-----------|-----------|-------------|
| Local-first | βœ… | ❌ | ❌ |
| No Docker | βœ… | ❌ | βœ… |
| Graph analysis | βœ… | Partial | ❌ |
| Multi-language | 6 | Many | Many |
| Circular deps | βœ… | βœ… | ❌ |
| Dead code | βœ… | βœ… | βœ… |
| AI code smell detection | βœ… | ❌ | ❌ |
| BYOK AI fixes | βœ… | ❌ | ❌ |
| Free | βœ… | Limited | Limited |

## Troubleshooting

### "Cannot open file .repotoire/kuzu_db/.lock: Not a directory"
You have a stale database from a previous version. Delete it:
```bash
rm -rf .repotoire
repotoire analyze .
```

### "cmake not installed" during cargo install
Install cmake first:
```bash
# macOS
brew install cmake

# Ubuntu/Debian
sudo apt install cmake build-essential

# Or use cargo binstall (no cmake needed)
cargo binstall repotoire
```

### Analysis is slow
Use `--relaxed` for faster runs (only high-severity findings):
```bash
repotoire analyze . --relaxed
```

## Documentation

- **[Schema Reference]docs/SCHEMA.md** β€” Graph node/edge types and Cypher examples
- **[Detectors]docs/DETECTORS.md** β€” Full list of 108 detectors with configuration

## Contributing

```bash
git clone https://github.com/Zach-hammad/repotoire
cd repotoire
pip install -e ".[dev]"
pytest
```

The Rust extension builds automatically on first install.

## License

MIT β€” see [LICENSE](LICENSE)

---

**[Get started β†’](https://pypi.org/project/repotoire/)** 

```bash
pip install repotoire && repotoire analyze .
```