|
1 | | -# Diff Risk Dashboard — Manual |
2 | | - |
3 | | -This manual complements **docs/USAGE.md** with project context. |
4 | | -- Quick usage & CLI examples: see **docs/USAGE.md**. |
5 | | -- Short wrappers: drt/drb/drj/drmd (file or inline JSON). |
6 | | -- Exit codes: 0 (green), 1 (yellow), 2 (red). Use `--no-exit-by-risk` to force 0. |
7 | | - |
8 | | -More sections to expand: |
9 | | -1) Installation & environment |
10 | | -2) Input format (APV JSON) |
11 | | -3) Output formats (table, bar, json, md) |
12 | | -4) CI usage & exit codes |
13 | | -5) Troubleshooting |
| 1 | +# Diff Risk Dashboard — User Manual |
| 2 | + |
| 3 | +> **Version:** v0.4.x • **Scope:** Complete guide for end‑users and maintainers |
| 4 | +> **Project:** `diff-risk-dashboard` — APV → Risk Summary (Python CLI) |
| 5 | +
|
| 6 | +--- |
| 7 | + |
| 8 | +## Table of Contents |
| 9 | +- [1. What is this?](#1-what-is-this) |
| 10 | +- [2. Who is it for](#2-who-is-it-for) |
| 11 | +- [3. Installation](#3-installation) |
| 12 | +- [4. Quick Start](#4-quick-start) |
| 13 | +- [5. Inputs (APV JSON)](#5-inputs-apv-json) |
| 14 | +- [6. Output formats](#6-output-formats) |
| 15 | +- [7. Exit codes & CI gating](#7-exit-codes--ci-gating) |
| 16 | +- [8. Short wrappers](#8-short-wrappers) |
| 17 | +- [9. CLI reference](#9-cli-reference) |
| 18 | +- [10. CI/CD integration (GitHub Actions)](#10-cicd-integration-github-actions) |
| 19 | +- [11. Color/TTY tips](#11-colortty-tips) |
| 20 | +- [12. Troubleshooting](#12-troubleshooting) |
| 21 | +- [13. FAQ](#13-faq) |
| 22 | +- [14. Security & Privacy](#14-security--privacy) |
| 23 | +- [15. Contributing](#15-contributing) |
| 24 | +- [16. Versioning & Releases](#16-versioning--releases) |
| 25 | +- [17. Support](#17-support) |
| 26 | +- [18. License](#18-license) |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +## 1. What is this? |
| 31 | +`diff-risk-dashboard` is a lean, production‑grade **Python CLI** that ingests |
| 32 | +**ai‑patch‑verifier (APV)** JSON and emits a **risk summary** in **table**, **JSON**, |
| 33 | +or **Markdown**. It is designed for **always‑green CI**, providing clear **exit codes** |
| 34 | +to gate merges by risk level. |
| 35 | + |
| 36 | +### Key capabilities |
| 37 | +- Normalize APV severities (`CRITICAL|HIGH|MEDIUM|LOW|INFO`, case‑insensitive). |
| 38 | +- Summaries: `total`, `by_severity`, `worst`, and aggregate `risk_level`. |
| 39 | +- Output suitable for **terminals**, **bots**, **PR comments**, and **dashboards**. |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +## 2. Who is it for |
| 44 | +- **Developers & DevOps**: need deterministic summaries to automate merge gates. |
| 45 | +- **Security/QA**: require exportable JSON/Markdown for audits and reporting. |
| 46 | +- **Team leads**: want a quick “is it safe to merge?” signal in CI. |
| 47 | + |
| 48 | +--- |
| 49 | + |
| 50 | +## 3. Installation |
| 51 | + |
| 52 | +### Option A — pipx (recommended) |
| 53 | +```bash |
| 54 | +pipx install . # run in project root, or: pipx install git+https://github.com/CoderDeltaLAN/diff-risk-dashboard.git |
| 55 | +``` |
| 56 | + |
| 57 | +### Option B — pip (user site) |
| 58 | +```bash |
| 59 | +python -m pip install --user . |
| 60 | +``` |
| 61 | + |
| 62 | +### Option C — development (Poetry) |
| 63 | +```bash |
| 64 | +pip install poetry |
| 65 | +poetry install --no-interaction |
| 66 | +``` |
| 67 | + |
| 68 | +> After installing, the `diff-risk` command is available on your PATH. |
| 69 | +
|
| 70 | +--- |
| 71 | + |
| 72 | +## 4. Quick Start |
| 73 | + |
| 74 | +Run with the bundled sample: |
| 75 | +```bash |
| 76 | +diff-risk examples/sample_apv.json -f table |
| 77 | +``` |
| 78 | + |
| 79 | +Generate Markdown to a file: |
| 80 | +```bash |
| 81 | +diff-risk examples/sample_apv.json -f md -o report.md |
| 82 | +``` |
| 83 | + |
| 84 | +Inline JSON (single quotes outside, double inside): |
| 85 | +```bash |
| 86 | +diff-risk '{"by_severity":{"CRITICAL":0,"HIGH":1,"MEDIUM":1,"LOW":1,"INFO":0}}' -f table |
| 87 | +``` |
| 88 | + |
| 89 | +--- |
| 90 | + |
| 91 | +## 5. Inputs (APV JSON) |
| 92 | + |
| 93 | +The tool accepts either: |
| 94 | +1) **File path** to JSON, or |
| 95 | +2) **Inline JSON** text (starting with `{` or `[`). |
| 96 | + |
| 97 | +Minimum shapes supported: |
| 98 | +- **Aggregated**: |
| 99 | + ```json |
| 100 | + { "by_severity": { "HIGH": 1, "MEDIUM": 2, "LOW": 3 } } |
| 101 | + ``` |
| 102 | +- **Flat list** (each item has a severity/level field): |
| 103 | + ```json |
| 104 | + [ |
| 105 | + {"severity":"high", "title":"..."}, |
| 106 | + {"predicted_risk":"medium", "id": 42} |
| 107 | + ] |
| 108 | + ``` |
| 109 | + |
| 110 | +The CLI normalizes severities and computes: |
| 111 | +- `total` |
| 112 | +- `by_severity` (both UPPER and lower keys are included for convenience) |
| 113 | +- `worst` (string) |
| 114 | +- `risk_level`: `"red" | "yellow" | "green"` |
| 115 | + |
| 116 | +--- |
| 117 | + |
| 118 | +## 6. Output formats |
| 119 | + |
| 120 | +### Table (TTY‑friendly) |
| 121 | +```bash |
| 122 | +diff-risk input.json -f table |
| 123 | +``` |
| 124 | + |
| 125 | +### JSON (machines/CI) |
| 126 | +```bash |
| 127 | +diff-risk input.json -f json |
| 128 | +``` |
| 129 | + |
| 130 | +Example JSON: |
| 131 | +```json |
| 132 | +{ |
| 133 | + "total": 3, |
| 134 | + "by_severity": { |
| 135 | + "CRITICAL": 0, "HIGH": 1, "MEDIUM": 1, "LOW": 1, "INFO": 0, |
| 136 | + "critical": 0, "high": 1, "medium": 1, "low": 1, "info": 0 |
| 137 | + }, |
| 138 | + "worst": "HIGH", |
| 139 | + "risk_level": "red" |
| 140 | +} |
| 141 | +``` |
| 142 | + |
| 143 | +### Markdown (reports/PRs) |
| 144 | +```bash |
| 145 | +diff-risk input.json -f md -o _intel/report.md |
| 146 | +``` |
| 147 | + |
| 148 | +--- |
| 149 | + |
| 150 | +## 7. Exit codes & CI gating |
| 151 | + |
| 152 | +Default behavior (raw CLI): |
| 153 | +- `green` → exit **0** |
| 154 | +- `yellow` → exit **1** |
| 155 | +- `red` → exit **2** |
| 156 | + |
| 157 | +To force **always 0** (useful locally or for non‑blocking jobs): |
| 158 | +```bash |
| 159 | +diff-risk input.json --no-exit-by-risk |
| 160 | +``` |
| 161 | + |
| 162 | +--- |
| 163 | + |
| 164 | +## 8. Short wrappers |
| 165 | + |
| 166 | +Convenience scripts (installed in `bin/`): |
| 167 | +- `drt <apv.json | raw-json>` — colored table (TTY) |
| 168 | +- `drb <apv.json | raw-json>` — bars (logs) |
| 169 | +- `drj <apv.json | raw-json>` — JSON (CI) |
| 170 | +- `drmd <apv.json | raw-json>` — Markdown (stdout) |
| 171 | + |
| 172 | +Examples: |
| 173 | +```bash |
| 174 | +drt examples/sample_apv.json |
| 175 | +drt '{"by_severity":{"CRITICAL":0,"HIGH":1,"MEDIUM":1,"LOW":1,"INFO":0}}' |
| 176 | +APV="/absolute/path/to/your_apv.json"; drt "$APV" |
| 177 | +``` |
| 178 | + |
| 179 | +Add to PATH: |
| 180 | +```bash |
| 181 | +mkdir -p ~/.local/bin && ln -sf "$PWD/bin/"* ~/.local/bin/ && hash -r |
| 182 | +``` |
| 183 | + |
| 184 | +--- |
| 185 | + |
| 186 | +## 9. CLI reference |
| 187 | + |
| 188 | +```bash |
| 189 | +diff-risk -h |
| 190 | +``` |
| 191 | + |
| 192 | +Options (common): |
| 193 | +- `-f, --format {table,json,md,bar}` — output format |
| 194 | +- `-o, --output` — file path; `-` = stdout |
| 195 | +- `--no-exit-by-risk` — disable exit code gating |
| 196 | + |
| 197 | +--- |
| 198 | + |
| 199 | +## 10. CI/CD integration (GitHub Actions) |
| 200 | + |
| 201 | +Minimal job (Python 3.11 / 3.12): |
| 202 | +```yaml |
| 203 | +- uses: actions/checkout@v4 |
| 204 | +- uses: actions/setup-python@v5 |
| 205 | + with: |
| 206 | + python-version: '3.12' |
| 207 | +- run: python -m pip install --upgrade pip |
| 208 | +- run: pip install poetry |
| 209 | +- run: poetry install --no-interaction |
| 210 | +- run: poetry run ruff check . |
| 211 | +- run: poetry run black --check . |
| 212 | +- env: |
| 213 | + PYTHONPATH: src |
| 214 | + run: poetry run pytest -q |
| 215 | +- run: poetry run mypy src |
| 216 | +# Smoke: |
| 217 | +- run: | |
| 218 | + poetry build |
| 219 | + poetry run python -m pip install . |
| 220 | + diff-risk examples/sample_apv.json -f md -o _intel/report.md |
| 221 | +``` |
| 222 | +
|
| 223 | +Upload report artifact: |
| 224 | +```yaml |
| 225 | +- uses: actions/upload-artifact@v4 |
| 226 | + with: |
| 227 | + name: sample-report |
| 228 | + path: _intel/report.md |
| 229 | +``` |
| 230 | +
|
| 231 | +--- |
| 232 | +
|
| 233 | +## 11. Color/TTY tips |
| 234 | +
|
| 235 | +To force colorized output in recordings/CI logs: |
| 236 | +```bash |
| 237 | +script -qfc "drt examples/sample_apv.json" /dev/null |
| 238 | +``` |
| 239 | + |
| 240 | +--- |
| 241 | + |
| 242 | +## 12. Troubleshooting |
| 243 | + |
| 244 | +- **JSONDecodeError**: Your argument is neither a readable file nor valid JSON. |
| 245 | + Use a valid path or wrap inline JSON like: `'{"by_severity":{"HIGH":1}}'`. |
| 246 | + |
| 247 | +- **Exit code > 0 unexpectedly**: You likely used the raw CLI without |
| 248 | + `--no-exit-by-risk`. The wrappers already add it for you. |
| 249 | + |
| 250 | +- **Command not found**: Ensure the package is installed and/or PATH updated |
| 251 | + when using wrappers. |
| 252 | + |
| 253 | +--- |
| 254 | + |
| 255 | +## 13. FAQ |
| 256 | + |
| 257 | +**Q:** Can I feed arbitrary JSON? |
| 258 | +**A:** Provide either the aggregated `by_severity` or a list with `severity`/`predicted_risk` keys. |
| 259 | + |
| 260 | +**Q:** Why duplicate lower & upper keys in `by_severity`? |
| 261 | +**A:** Convenience for consumers with strict schemas. |
| 262 | + |
| 263 | +--- |
| 264 | + |
| 265 | +## 14. Security & Privacy |
| 266 | + |
| 267 | +- No credentials required. Do **not** upload sensitive JSON to public PRs. |
| 268 | +- CodeQL runs in CI; keep dependencies updated. |
| 269 | + |
| 270 | +--- |
| 271 | + |
| 272 | +## 15. Contributing |
| 273 | + |
| 274 | +- Follow **Conventional Commits**. |
| 275 | +- Keep **ruff/black/pytest/mypy** green before requesting review. |
| 276 | +- Prefer small PRs with auto‑merge enabled after checks. |
| 277 | + |
| 278 | +--- |
| 279 | + |
| 280 | +## 16. Versioning & Releases |
| 281 | + |
| 282 | +- Tags `vMAJOR.MINOR.PATCH`. Release notes are drafted automatically. |
| 283 | +- Use GitHub Releases to fetch artifacts and changelog. |
| 284 | + |
| 285 | +--- |
| 286 | + |
| 287 | +## 17. Support |
| 288 | + |
| 289 | +- Open Issues or Discussions on GitHub. |
| 290 | +- For commercial support, contact the repository owner. |
| 291 | + |
| 292 | +--- |
| 293 | + |
| 294 | +## 18. License |
| 295 | + |
| 296 | +Released under the **MIT License**. See [LICENSE](../LICENSE). |
| 297 | + |
| 298 | +--- |
| 299 | + |
| 300 | +> **Tip:** The README “Manual” badge links to this page. |
0 commit comments