|
1 | | -# ⭐ diff-risk-dashboard — APV → Risk Summary (Python CLI) |
| 1 | +# Diff Risk Dashboard |
2 | 2 |
|
3 | | -A lean, production-grade **Python CLI** that ingests **ai-patch-verifier (APV)** JSON and outputs a clear **risk summary** (table / JSON / Markdown). |
4 | | -Designed for **always-green CI**, with strict checks and exit codes per risk level to gate merges professionally. |
5 | | - |
6 | | -<div align="center"> |
7 | | - |
8 | | -[](https://github.com/CoderDeltaLAN/diff-risk-dashboard/actions/workflows/build.yml) |
9 | | -[](https://github.com/CoderDeltaLAN/diff-risk-dashboard/actions/workflows/codeql.yml) |
10 | | -[](https://github.com/CoderDeltaLAN/diff-risk-dashboard/releases) |
11 | | - |
12 | | -[](LICENSE) |
13 | | -[](https://www.paypal.com/donate/?hosted_button_id=YVENCBNCZWVPW) |
14 | | - |
15 | | -</div> |
16 | | - |
17 | | ---- |
18 | | - |
19 | | -## Repo layout |
20 | | - |
21 | | -```text |
22 | | -. |
23 | | -├── examples/ |
24 | | -│ └── sample_apv.json # APV sample for demos/tests |
25 | | -├── src/diff_risk_dashboard/ |
26 | | -│ ├── __main__.py # module entry |
27 | | -│ ├── cli.py # CLI |
28 | | -│ ├── core.py # summarization logic |
29 | | -│ └── report.py # Markdown generator |
30 | | -├── tests/ # pytest |
31 | | -└── .github/workflows/ # CI + CodeQL + Release Drafter |
32 | | -``` |
33 | | - |
34 | | ---- |
35 | | - |
36 | | -## 🚀 Quick Start (end users) |
| 3 | +Summarizes AI Patch Verifier (APV) JSON into a clean, professional terminal table, text bars, JSON, or Markdown report. |
37 | 4 |
|
38 | 5 | <!-- diff-risk:usage:start --> |
39 | 6 |
|
40 | | -## 🚀 Usage (short aliases) |
41 | | - |
42 | | -### CLI (recommended colorful table) |
43 | | -```bash |
44 | | -# green panel (empty sample) |
45 | | -./bin/drt examples/sample_apv.empty.json |
| 7 | +## 🚀 Usage |
46 | 8 |
|
47 | | -# real example with findings |
48 | | -./bin/drt examples/sample_apv.json |
49 | | -``` |
| 9 | +### Short commands |
| 10 | +- `drt <apv.json | raw-json>` — color table (TTY) |
| 11 | +- `drb <apv.json | raw-json>` — text bars (logs) |
| 12 | +- `drj <apv.json | raw-json>` — JSON (CI) |
| 13 | +- `drmd <apv.json | raw-json>` — Markdown (stdout) |
50 | 14 |
|
51 | | -Other formats: |
52 | 15 | ```bash |
53 | | -./bin/drb examples/sample_apv.json # text bars |
54 | | -./bin/drj examples/sample_apv.json # JSON (CI/machines) |
55 | | -./bin/drmd examples/sample_apv.json _intel/report.md # Markdown file |
56 | | -``` |
57 | | - |
58 | | -Tip: to call aliases without `./bin/` temporarily: |
59 | | -```bash |
60 | | -export PATH="$PWD/bin:$PATH" |
| 16 | +# Demo (bundled sample) |
61 | 17 | drt examples/sample_apv.json |
62 | | -``` |
63 | | - |
64 | | -**Exit codes**: `0=green`, `1=yellow`, `2=red` (`--no-exit-by-risk` forces `0` for demos). |
65 | | - |
66 | | -<!-- diff-risk:usage:end --> |
67 | | - |
68 | | - |
69 | | -> Sin cambios en tu sistema ni shell. Usa el proyecto como **app Python** con su comando **`diff-risk`** tras instalarlo. |
70 | | -
|
71 | | -```bash |
72 | | -# 1) Clonar |
73 | | -git clone https://github.com/CoderDeltaLAN/diff-risk-dashboard.git |
74 | | -cd diff-risk-dashboard |
75 | | - |
76 | | -# 2) Instalar como paquete (aislado con pipx, o pip estándar) |
77 | | -# Opción A (recomendada): pipx |
78 | | -pipx install . |
79 | | -# Opción B: pip usuario |
80 | | -python -m pip install --user . |
81 | | - |
82 | | -# 3) Usar el comando instalado |
83 | | -diff-risk examples/sample_apv.json --format md --output report.md |
84 | | -``` |
85 | | - |
86 | | -### CLI usage |
87 | | - |
88 | | -```bash |
89 | | -diff-risk -h |
90 | | -``` |
91 | | - |
92 | | -``` |
93 | | -usage: diff_risk_dashboard [-h] [-f {table,json,md}] [-o OUTPUT] |
94 | | - [--no-exit-by-risk] |
95 | | - input |
96 | | -
|
97 | | -Diff Risk Dashboard (APV JSON -> summary) |
98 | | -
|
99 | | -positional arguments: |
100 | | - input Path o texto JSON de ai-patch-verifier |
101 | | -
|
102 | | -options: |
103 | | - -h, --help show this help message and exit |
104 | | - -f {table,json,md}, --format {table,json,md} |
105 | | - Formato de salida |
106 | | - -o OUTPUT, --output OUTPUT |
107 | | - Archivo de salida; '-' = stdout |
108 | | - --no-exit-by-risk No ajustar el exit code por nivel de riesgo |
109 | | -``` |
110 | | - |
111 | | -#### Examples |
112 | | - |
113 | | -Table (por defecto, al stdout): |
114 | | - |
115 | | -```bash |
116 | | -diff-risk examples/sample_apv.json |
117 | | -``` |
118 | | - |
119 | | -JSON (ideal para piping/automatización): |
120 | | - |
121 | | -```bash |
122 | | -diff-risk examples/sample_apv.json -f json |
123 | | -``` |
124 | | - |
125 | | -Markdown a archivo (para adjuntar en PRs/Wikis): |
126 | | - |
127 | | -```bash |
128 | | -diff-risk examples/sample_apv.json -f md -o report.md |
129 | | -``` |
130 | | - |
131 | | -Salida Markdown de ejemplo: |
132 | 18 |
|
133 | | -```md |
134 | | -# Diff Risk Dashboard 🔴 — Worst: **HIGH** |
| 19 | +# Inline JSON (single quotes outside, double quotes inside) |
| 20 | +drt '{"by_severity":{"CRITICAL":0,"HIGH":1,"MEDIUM":1,"LOW":1,"INFO":0}}' |
135 | 21 |
|
136 | | -| Severity | Count | |
137 | | -|---|---:| |
138 | | -| CRITICAL | 0 | |
139 | | -| HIGH | 1 | |
140 | | -| MEDIUM | 1 | |
141 | | -| LOW | 1 | |
142 | | -| INFO | 0 | |
143 | | -| **TOTAL** | **3** | |
| 22 | +# Your real file |
| 23 | +APV="/absolute/path/to/your_apv.json"; drt "$APV" |
144 | 24 |
|
145 | | -> Generated by diff-risk-dashboard CLI |
146 | | -``` |
147 | | - |
148 | | ---- |
149 | | - |
150 | | -## 📦 What the tool expects (APV JSON) |
151 | | - |
152 | | -- Entrada: JSON con findings tipo APV, ej. objetos que incluyen `predicted_risk` (`low|medium|high`). |
153 | | -- El sumario **normaliza mayúsculas/minúsculas** y calcula: |
154 | | - - `total` |
155 | | - - `by_severity` (claves `CRITICAL|HIGH|MEDIUM|LOW|INFO` y también minúsculas) |
156 | | - - `worst` |
157 | | - - `risk_level` (`red|yellow|green`) |
158 | | - |
159 | | -Ejemplo de salida `-f json`: |
160 | | - |
161 | | -```json |
162 | | -{ |
163 | | - "total": 3, |
164 | | - "by_severity": { |
165 | | - "critical": 0, |
166 | | - "high": 1, |
167 | | - "medium": 1, |
168 | | - "low": 1, |
169 | | - "info": 0, |
170 | | - "CRITICAL": 0, |
171 | | - "HIGH": 1, |
172 | | - "MEDIUM": 1, |
173 | | - "LOW": 1, |
174 | | - "INFO": 0 |
175 | | - }, |
176 | | - "worst": "HIGH", |
177 | | - "risk_level": "red" |
178 | | -} |
179 | | -``` |
180 | | - |
181 | | ---- |
182 | | - |
183 | | -## ⛳ Exit codes (CI gating) |
184 | | - |
185 | | -- `green` → **0** |
186 | | -- `yellow` → **1** |
187 | | -- `red` → **2** |
188 | | - |
189 | | -Por defecto, el proceso **sale** con el código según `risk_level`. |
190 | | -Para desactivar este comportamiento (p.ej., en local o cuando solo generas reportes): |
191 | | - |
192 | | -```bash |
193 | | -diff-risk examples/sample_apv.json --no-exit-by-risk |
194 | | -``` |
195 | | - |
196 | | ---- |
197 | | - |
198 | | -## 🧪 Local Developer Workflow (mirrors CI) |
199 | | - |
200 | | -```bash |
201 | | -# Requisitos de desarrollo |
202 | | -python -m pip install --upgrade pip |
203 | | -pip install poetry |
204 | | - |
205 | | -# Instalar deps |
206 | | -poetry install --no-interaction |
207 | | - |
208 | | -# Gates locales |
209 | | -poetry run ruff check . |
210 | | -poetry run black --check . |
211 | | -PYTHONPATH=src poetry run pytest -q |
212 | | -poetry run mypy src |
213 | | -``` |
214 | | - |
215 | | ---- |
216 | | - |
217 | | -## 🔧 CI (GitHub Actions) |
218 | | - |
219 | | -- Matriz **Python 3.11 / 3.12** alineada con los gates locales. |
220 | | -- **CodeQL** en PRs y `main`. |
221 | | -- **Release Drafter** para changelog/release notes. |
222 | | -- **Branch protection** y merges seguros (historial lineal via squash). |
223 | | - |
224 | | -Fragmento típico del job Python: |
| 25 | +# Other formats with the same input |
| 26 | +drb "$APV" # bars (logs) |
| 27 | +drj "$APV" # JSON (CI) |
| 28 | +mkdir -p _intel && drmd "$APV" > _intel/report.md # Markdown to file |
225 | 29 |
|
226 | | -```yaml |
227 | | -- run: python -m pip install --upgrade pip |
228 | | -- run: pip install poetry |
229 | | -- run: poetry install --no-interaction |
230 | | -- run: poetry run ruff check . |
231 | | -- run: poetry run black --check . |
232 | | -- env: |
233 | | - PYTHONPATH: src |
234 | | - run: poetry run pytest -q |
235 | | -- run: poetry run mypy src |
236 | | -# Ejemplo de uso del CLI en CI: |
237 | | -- run: poetry run python -m pip install . |
238 | | -- run: diff-risk examples/sample_apv.json -f md -o report.md |
| 30 | +# Force colors for recordings |
| 31 | +script -qfc "drt $APV" /dev/null |
239 | 32 | ``` |
240 | 33 |
|
241 | | ---- |
| 34 | +> Exit codes: `0=green`, `1=yellow`, `2=red`. Use `--no-exit-by-risk` to force `0` in demos. |
242 | 35 |
|
243 | | -## 🗺 When to Use This Project |
244 | | -
|
245 | | -- Necesitas **resumen de riesgo** claro y portable a partir de **APV**. |
246 | | -- Quieres **bloquear merges** cuando el riesgo supera el umbral (exit codes). |
247 | | -- Buscas **reportes en Markdown/JSON** para PRs, auditorías y tableros. |
248 | | -
|
249 | | ---- |
250 | | -
|
251 | | -## 🧩 Customization |
252 | | -
|
253 | | -- Genera tus propios APV JSON y pásalos como `input`. |
254 | | -- Cambia el formato con `--format` (**table/json/md**) y redirige a archivo con `--output`. |
255 | | -- Integra el JSON de salida con otras herramientas o dashboards. |
256 | | - |
257 | | ---- |
258 | | - |
259 | | -## 🔒 Security |
260 | | - |
261 | | -- Sin cambios en tu shell o sistema: **no** requiere editar `.zshrc` ni configuración del usuario. |
262 | | -- CodeQL activo; se recomienda usar repos **privados** para datos sensibles. |
263 | | -- No subas JSON con información confidencial a PRs públicos. |
264 | | - |
265 | | ---- |
266 | | - |
267 | | -## 🙌 Contributing |
268 | | - |
269 | | -- PRs pequeños y atómicos, estilo **Conventional Commits**. |
270 | | -- Mantén los **gates** verdes antes de solicitar revisión. |
271 | | -- Activa **auto-merge** cuando pasen los checks. |
272 | | - |
273 | | ---- |
274 | | - |
275 | | -## 💚 Donations & Sponsorship |
276 | | - |
277 | | -If this project saves you time, consider supporting ongoing maintenance. Thank you! |
278 | | -[](https://www.paypal.com/donate/?hosted_button_id=YVENCBNCZWVPW) |
279 | | - |
280 | | ---- |
281 | | - |
282 | | -## 🔎 SEO Keywords |
283 | | - |
284 | | -apv risk summary cli, ai patch verifier json, diff risk dashboard python, |
285 | | -markdown security report, always green ci python, ruff black pytest mypy, |
286 | | -github actions codeql release drafter, branch protection required checks, |
287 | | -console scripts professional cli ux |
288 | | - |
289 | | ---- |
290 | | - |
291 | | -## 👤 Author |
292 | | - |
293 | | -**CoderDeltaLAN (Yosvel)** |
294 | | -GitHub: https://github.com/CoderDeltaLAN |
295 | | - |
296 | | ---- |
297 | | - |
298 | | -## 📄 License |
299 | | - |
300 | | -Released under the **MIT License**. See [LICENSE](LICENSE). |
301 | | - |
302 | | ---- |
303 | | - |
304 | | -**Download this README**: This same file can be downloaded from the chat link. |
| 36 | +<!-- diff-risk:usage:end --> |
0 commit comments