zerum 0.5.0

Deterministic Python code governance: ~75 checks, profiles, Ruff orchestration, remediation prompts
Documentation
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
# Zerum

<p align="center">
  <img src="docs/zerum-icon-02.jpg" alt="Zerum — Rust crab administering analysis extract to a Python snake" width="640" />
</p>

<p align="center">
  <strong>Zerum</strong> — deterministic code governance for Python · <em>Credo for Python</em>
</p>

<p align="center">
  <a href="https://crates.io/crates/zerum"><img src="https://img.shields.io/crates/v/zerum.svg" alt="crates.io" /></a>
  <a href="https://pypi.org/project/zerum/"><img src="https://img.shields.io/pypi/v/zerum.svg" alt="PyPI" /></a>
  <a href="https://github.com/latentmeta/zerum/releases"><img src="https://img.shields.io/github/v/release/latentmeta/zerum.svg" alt="GitHub release" /></a>
  <a href="https://github.com/latentmeta/zerum/actions/workflows/ci.yml"><img src="https://github.com/latentmeta/zerum/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
  <a href="https://docs.rs/zerum"><img src="https://docs.rs/zerum/badge.svg" alt="docs.rs" /></a>
  <a href="https://github.com/latentmeta/zerum/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT license" /></a>
  <a href="https://www.rust-lang.org/"><img src="https://img.shields.io/badge/rust-1.70%2B-orange.svg" alt="Rust 1.70+" /></a>
  <a href="https://www.python.org/"><img src="https://img.shields.io/badge/python-3.9%2B%20(wheels)-blue.svg" alt="Python 3.9+ wheels" /></a>
</p>

**v0.5.0** ships ~**75** native checks (ZR001–ZR510), explainable findings (curated copy for tier-1 rules; AST-precise fallbacks elsewhere), quiet **default** / full **strict** profiles, optional **Ruff** orchestration, `human` / `json` / `sarif` output, and **`--remediation-prompt`** — a deterministic markdown brief for LLM/editor agents (no model call in Zerum). Install via **PyPI**, **Homebrew**, **crates.io**, or GitHub Releases.

Zerum is **not** a Ruff replacement. It focuses on maintainability, consistency, architecture boundaries, and deterministic AI-slop patterns.



---

## Install

Pick one. After install you get a `zerum` command on your `PATH`.

### Standalone binary

Download a release archive for your OS/arch from
[GitHub Releases](https://github.com/latentmeta/zerum/releases), extract, and put `zerum` on your `PATH`.

**Homebrew** (tap formula; after the formula is published):

```bash
brew install latentmeta/tap/zerum
```

**crates.io** (requires Rust **1.70+**):

```bash
cargo install zerum --locked
```

### Python (recommended for most Python projects)

No Rust toolchain required — prebuilt wheels:

```bash
pip install zerum
```

Isolated tool installs:

```bash
pipx install zerum
# or
uv tool install zerum
```

Verify:

```bash
zerum --version
zerum --help
```

---

## Quick start

```bash
cd your-python-project

# Optional: write a starter zerum.toml (default profile)
zerum init

# Run checks on the project
zerum check .

# Write a remediation prompt for an LLM / editor agent
zerum check . --remediation-prompt

# Browse the catalog and learn a rule
zerum list-checks
zerum explain ZR001
```

Exit codes for `zerum check`:

| Code | Meaning |
|------|---------|
| 0 | No issues |
| 1 | Issues found |
| 2 | Operational error (bad path, CLI error, etc.) |

---

## Using Zerum

### Check a project

```bash
zerum check .
zerum check path/to/package
zerum check src/
```

Human-readable output is the default. Each finding includes rule id, location, explanation, and remediation.

### Remediation prompt (v0.5.0)

Zerum can save a **deterministic** markdown prompt from its findings — grouped by check type, ordered by severity (critical → info), with shared remediation text and source snippets. Zerum does **not** call an LLM; you paste the file into Cursor, ChatGPT, or another agent.

```bash
zerum check . --remediation-prompt
# → zerum-remediation-prompt.md

zerum check . --remediation-prompt fixes.md
zerum check . --profile strict --remediation-prompt fixes.md
```

Typical workflow:

1. `zerum check . --remediation-prompt fixes.md`
2. Open `fixes.md` in your editor / agent and ask it to apply the remediations
3. Re-run `zerum check .` until clean

The prompt includes:

- Goal and constraints (minimal edits, preserve APIs)
- Summary counts and a type index ordered by severity
- Findings **grouped by check id**, shared explanation/remediation once per type
- Per-occurrence location, message, and source context
- Instructions to re-run Zerum after edits

### Profiles: default vs strict

With **no** `zerum.toml` (or `[profile] name = "default"`), Zerum uses the built-in **default** profile: noisy pattern heuristics are off so greenfield modules stay quieter.

Enable the full catalog:

```bash
zerum check . --profile strict
```

Or persist it:

```bash
zerum init --strict
# writes a strict starter config
```

```toml
[profile]
name = "strict"
```

Compare:

```bash
zerum check .                    # default — quieter
zerum check . --profile strict   # all ~75 rules
```

### Configuration (`zerum.toml`)

```bash
zerum init              # default template
zerum init --strict     # strict template
```

Common knobs:

```toml
[profile]
name = "default"

[checks.ZR001]
enabled = true
max_lines = 50

[checks.ZR401]
severity = "high"

# Architecture layers (ZR207)
[[checks.ZR207.rules]]
from = "app.domain"
forbidden = "app.infrastructure"

# Always run Ruff when you check (requires ruff on PATH)
# external_checkers = ["ruff"]
```

Custom profiles can inherit:

```toml
[profiles.team]
extends = "default"

[profiles.team.checks.ZR001]
max_lines = 60
```

```bash
zerum check . --profile team
```

Starter files in the repo: `zerum.toml.example`, `zerum.toml.strict.example`.

### Explain a rule

```bash
zerum explain ZR001
zerum explain ZR401
zerum explain ZR501
```

Shows category, severity, rationale, false positives, tradeoffs, examples, and remediation.

### List checks and external checkers

```bash
zerum list-checks
zerum list-checkers
```

`list-checks` prints the full ZR catalog. `list-checkers` shows external adapters (e.g. Ruff) and whether they are available on `PATH`.

### Optional Ruff orchestration

Zerum can run **Ruff** alongside native checks and merge findings:

```bash
# one-off
zerum check . --with-external ruff

# or persist in zerum.toml
# external_checkers = ["ruff"]
zerum check .
```

Requires `ruff` on `PATH`. External findings use ids like `EXT-RUFF-E501`.

### Rule categories

| Range | Category |
|-------|----------|
| ZR001–015 | Readability |
| ZR101–110 | Consistency |
| ZR201–210 | Design |
| ZR301–315 | Refactor |
| ZR401–415 | Warning |
| ZR501–510 | AI (deterministic) |

---

## Output formats

```bash
zerum check . --format human    # default
zerum check . --format json
zerum check . --format sarif
zerum check . --profile strict
zerum check . --with-external ruff
zerum check . --remediation-prompt fixes.md
zerum list-checkers
```

| Output | When to use |
|--------|-------------|
| `human` | Terminal review — rule id, location, explanation, remediation |
| `json` | CI artifacts, scripts, and custom dashboards |
| `sarif` | GitHub code scanning and other SARIF consumers |
| `--remediation-prompt` | Markdown brief for an LLM/editor agent (file on disk; still prints `human`/`json`/`sarif` to stdout) |

Optional external checkers (Ruff) are available from **v0.4.0**. Use the **default** profile for low noise on greenfield code; use `--profile strict` for full catalog coverage.

---

## Tutorial

Educational material lives under [`docs/tutorial/`](https://github.com/latentmeta/zerum/tree/main/docs/tutorial/):

- [00 — Introduction]https://github.com/latentmeta/zerum/blob/main/docs/tutorial/00-introduction.md
- [01 — Static analysis basics]https://github.com/latentmeta/zerum/blob/main/docs/tutorial/01-static-analysis-basics.md
- [02 — Parsing Python in Rust]https://github.com/latentmeta/zerum/blob/main/docs/tutorial/02-parsing-python-in-rust.md
- [03 — Building a rule engine]https://github.com/latentmeta/zerum/blob/main/docs/tutorial/03-building-a-rule-engine.md
- [04 — Writing checks]https://github.com/latentmeta/zerum/blob/main/docs/tutorial/04-writing-checks.md
- [05 — Explain mode and configuration]https://github.com/latentmeta/zerum/blob/main/docs/tutorial/05-explain-mode-and-configuration.md
- [06 — Config and profiles]https://github.com/latentmeta/zerum/blob/main/docs/tutorial/06-config-profiles.md
- [12 — Roadmap]https://github.com/latentmeta/zerum/blob/main/docs/tutorial/12-roadmap.md

---

## Feature demos

Assume a project directory with some Python sources.

### 1. First pass (quiet default)

```bash
zerum check .
# exit 0 → clean under default profile
# exit 1 → findings printed to stdout
```

### 2. Full catalog

```bash
zerum check . --profile strict
```

Expect more findings on small modules (docstring / comment / heuristic rules).

### 3. Machine-readable report

```bash
zerum check . --format json > zerum-report.json
```

### 4. Learn why a finding fired

```bash
zerum check . --format human
# note a rule id, e.g. ZR003
zerum explain ZR003
```

### 5. Team config + architecture boundary

```bash
zerum init
# edit zerum.toml — set ZR207 rules for your layers
zerum check .
```

### 6. Zerum + Ruff in one command

```bash
zerum list-checkers
zerum check . --with-external ruff --format json
```

### 7. Save a remediation prompt for an LLM / editor agent

```bash
zerum check . --remediation-prompt
# → zerum-remediation-prompt.md

zerum check . --remediation-prompt fixes.md
```

Findings are **grouped by type** and **sorted by severity** (critical first).

### 8. Upgrade later

```bash
pip install --upgrade zerum
# or: pipx upgrade zerum
# or: uv tool upgrade zerum
# or: brew upgrade zerum
zerum --version
```

---

## Add Zerum to CI/CD (Python project)

Fail the job when Zerum finds issues (`exit 1`). Use JSON if you want artifacts.

### GitHub Actions (pip)

```yaml
name: Zerum

on:
  pull_request:
  push:
    branches: [main]

jobs:
  zerum:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Install Zerum
        run: pip install "zerum==0.5.0"

      - name: Run Zerum
        run: zerum check . --format human

      # Optional: remediation prompt artifact for reviewers / agents
      # - run: zerum check . --remediation-prompt zerum-remediation-prompt.md || true
      # - uses: actions/upload-artifact@v4
      #   if: failure()
      #   with:
      #     name: zerum-remediation-prompt
      #     path: zerum-remediation-prompt.md
```

### GitHub Actions (uv)

```yaml
- uses: astral-sh/setup-uv@v4
- run: uv tool install zerum
- run: zerum check .
```

### GitHub Actions (pipx)

```yaml
- uses: actions/setup-python@v5
  with:
    python-version: "3.12"
- run: pipx install zerum
- run: zerum check .
```

### Pre-commit

```yaml
# .pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: zerum
        name: zerum
        entry: zerum check .
        language: system
        pass_filenames: false
        types: [python]
```

Install Zerum on the machine (or in CI) before running pre-commit, e.g. `pipx install zerum`.

### GitLab CI

```yaml
zerum:
  image: python:3.12-slim
  script:
    - pip install "zerum==0.5.0"
    - zerum check .
```

### Tips for CI

- Start with **default** profile; move to `--profile strict` once the baseline is clean.
- Pin the version in CI: `pip install "zerum==0.5.0"`.
- Combine with Ruff only if `ruff` is installed in the job:  
  `zerum check . --with-external ruff`.
- Treat exit code `2` as infra failure; `1` as “findings to fix.”
- Optionally upload `--remediation-prompt` output as a CI artifact when the check fails.

---

## Changelog

See [CHANGELOG.md](https://github.com/latentmeta/zerum/blob/main/CHANGELOG.md). Release notes: [v0.5.0](https://github.com/latentmeta/zerum/blob/main/docs/RELEASE_v0.5.0.md).

---

## Building from source (contributors)

For hacking on Zerum itself — not required for normal use.

```bash
git clone https://github.com/latentmeta/zerum.git
cd zerum
cargo build --release
./target/release/zerum check path/to/python/project

# or run without installing
cargo run -- check path/to/python/project
cargo run -- explain ZR001
cargo run -- list-checks
cargo run -- init
cargo run -- check path/to/project --remediation-prompt /tmp/fixes.md

# editable Python-env install via maturin
pip install "maturin>=1.7,<2.0"
maturin develop
```

Tests and lint:

```bash
cargo test
cargo clippy --all-targets --all-features -- -D warnings
```

Coverage (rustup cargo; asdf shims break `cargo +toolchain`):

```bash
export PATH="$HOME/.cargo/bin:$PATH"
cargo +1.97.1 tarpaulin \
  --engine llvm --all-targets --all-features --follow-exec \
  --out Stdout --fail-under 70 -- --test-threads=1
```

Packaging notes: [`packaging/`](https://github.com/latentmeta/zerum/tree/main/packaging) (PyPI, Homebrew). Config for multi-channel scaffolding: [`Sastri.toml`](https://github.com/latentmeta/zerum/blob/main/Sastri.toml).

---

## License

MIT — see [LICENSE](https://github.com/latentmeta/zerum/blob/main/LICENSE).