Skip to content

Commit 770ece1

Browse files
committed
fix(cli): robust input detection (file/JSON), typed summary, polished TTY & MD zero-state
1 parent 003cb9a commit 770ece1

File tree

12 files changed

+295
-520
lines changed

12 files changed

+295
-520
lines changed

README.md

Lines changed: 21 additions & 289 deletions
Original file line numberDiff line numberDiff line change
@@ -1,304 +1,36 @@
1-
# ⭐ diff-risk-dashboard — APV → Risk Summary (Python CLI)
1+
# Diff Risk Dashboard
22

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-
[![CI / build](https://github.com/CoderDeltaLAN/diff-risk-dashboard/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/CoderDeltaLAN/diff-risk-dashboard/actions/workflows/build.yml)
9-
[![CodeQL Analysis](https://github.com/CoderDeltaLAN/diff-risk-dashboard/actions/workflows/codeql.yml/badge.svg?branch=main)](https://github.com/CoderDeltaLAN/diff-risk-dashboard/actions/workflows/codeql.yml)
10-
[![Release](https://img.shields.io/github/v/release/CoderDeltaLAN/diff-risk-dashboard?display_name=tag)](https://github.com/CoderDeltaLAN/diff-risk-dashboard/releases)
11-
![Python 3.11|3.12](https://img.shields.io/badge/Python-3.11%20|%203.12-3776AB?logo=python)
12-
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
13-
[![Donate](https://img.shields.io/badge/Donate-PayPal-0070ba?logo=paypal&logoColor=white)](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.
374

385
<!-- diff-risk:usage:start -->
396

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
468

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)
5014

51-
Other formats:
5215
```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)
6117
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:
13218

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}}'
13521

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"
14424

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
22529

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
23932
```
24033

241-
---
34+
> Exit codes: `0=green`, `1=yellow`, `2=red`. Use `--no-exit-by-risk` to force `0` in demos.
24235
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-
[![Donate](https://img.shields.io/badge/Donate-PayPal-0070ba?logo=paypal&logoColor=white)](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 -->

README.md.tmp

Whitespace-only changes.

README_USAGE_BLOCK.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!-- diff-risk:usage:start -->
2+
3+
## 🚀 Usage
4+
5+
### Short commands (recommended)
6+
7+
```bash
8+
# Demo incluida (color bonito)
9+
drt examples/sample_apv.json
10+
11+
# JSON inline (comilla simple afuera, dobles adentro)
12+
drt '{"by_severity":{"CRITICAL":0,"HIGH":1,"MEDIUM":1,"LOW":1,"INFO":0}}'
13+
14+
# Tu archivo real
15+
APV="/ruta/real/a/tu_apv.json"; drt "$APV"
16+
```
17+
18+
**Otros formatos**
19+
```bash
20+
drb "$APV" # barras (logs)
21+
drj "$APV" # JSON (CI)
22+
drmd "$APV" > report.md # Markdown a archivo
23+
```
24+
25+
**Forzar color en capturas**
26+
```bash
27+
script -qfc 'drt "$APV"' /dev/null
28+
```
29+
30+
**Añadir wrappers al PATH (opcional)**
31+
```bash
32+
mkdir -p ~/.local/bin && ln -sf "$PWD/bin/"* ~/.local/bin/ && hash -r
33+
```
34+
35+
**CLI crudo (equivalentes)**
36+
```bash
37+
poetry run diff-risk examples/sample_apv.json -f table --no-exit-by-risk
38+
poetry run diff-risk examples/sample_apv.json -f bar --no-exit-by-risk
39+
poetry run diff-risk examples/sample_apv.json -f json --no-exit-by-risk
40+
poetry run diff-risk examples/sample_apv.json -f md --no-exit-by-risk > report.md
41+
```
42+
43+
<!-- diff-risk:usage:end -->

bin/_dr_common.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
arg="${1-}"
4+
if [[ -z "$arg" ]]; then echo "Usage: $0 <apv.json | raw-json>"; exit 2; fi
5+
if [[ -f "$arg" ]]; then SRC="$arg"
6+
elif [[ "$arg" =~ ^[[:space:]]*\{ || "$arg" =~ ^[[:space:]]*\[ ]]; then
7+
TMP="$(mktemp)"; printf '%s\n' "$arg" > "$TMP"; SRC="$TMP"
8+
else
9+
echo "✗ Not found and not JSON: $arg" >&2; exit 66
10+
fi
11+
echo "$SRC"

bin/drb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
3-
if [ $# -lt 1 ]; then echo "Usage: drb <apv.json | raw-json>"; exit 2; fi
4-
arg="$1"
5-
if [[ "$arg" == \{* || "$arg" == \[* ]]; then tmp="$(mktemp)"; printf '%s' "$arg" > "$tmp"; trap 'rm -f "$tmp"' EXIT; exec poetry run diff-risk "$tmp" -f bar --no-exit-by-risk; fi
6-
exec poetry run diff-risk "$arg" -f bar --no-exit-by-risk
3+
SRC="$(bin/_dr_common.sh "${1-}")"
4+
exec poetry run diff-risk "$SRC" -f bar --no-exit-by-risk

bin/drj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
3-
if [ $# -lt 1 ]; then echo "Usage: drj <apv.json | raw-json>"; exit 2; fi
4-
arg="$1"
5-
if [[ "$arg" == \{* || "$arg" == \[* ]]; then tmp="$(mktemp)"; printf '%s' "$arg" > "$tmp"; trap 'rm -f "$tmp"' EXIT; exec poetry run diff-risk "$tmp" -f json --no-exit-by-risk; fi
6-
exec poetry run diff-risk "$arg" -f json --no-exit-by-risk
3+
SRC="$(bin/_dr_common.sh "${1-}")"
4+
exec poetry run diff-risk "$SRC" -f json --no-exit-by-risk

0 commit comments

Comments
 (0)