diff --git a/Jenkinsfile b/Jenkinsfile index a221931..7f12255 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -96,9 +96,9 @@ pipeline { sh ''' set -eu # Only clear generated build outputs, never source PDFs. - rm -rf build "${CI_ARTIFACT_DIR}" - ./render.sh --all - ./render-diagnostics.sh --all "${DIAGNOSTICS_AUTHOR}" + rm -rf "${CI_ARTIFACT_DIR}" + ./render.sh --clean --all + ./render-diagnostics.sh --clean --all "${DIAGNOSTICS_AUTHOR}" ''' } } diff --git a/README.md b/README.md index b2acd2f..944abc5 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,20 @@ The PDF is written to `build/my-report.pdf`. To render every report recursively: ./render.sh --all ``` +Subfolders are preserved: `reports/customer/report.yaml` produces +`build/customer/report.pdf`, including in ZIP exports. `build/diagnostics/` +is reserved for diagnostic PDFs. + +Remove old PDFs before regenerating all reports: + +```bash +./render.sh --clean --all +./render-diagnostics.sh --clean --all "Your Name" +``` + +Each command cleans only its own report category. With a single input, +`--clean` removes only that input's PDF. Other files are retained. + Set the report's purpose explicitly: ```yaml @@ -86,8 +100,9 @@ typst compile \ ```text report.typ Typst entry point -model.typ Shared layout and YAML renderer +modules/ Shared Typst layouts and diagnostics normalization render.sh Convenience build script +config/ Shared YAML themes, diagnostics rules, and watchlist assets/ Logos and other static assets reports/ Authoritative YAML report sources build/ Generated PDFs @@ -108,7 +123,7 @@ docs/ Detailed documentation and examples ## Core principle YAML files are the authoritative report sources. Keep content and report state -in YAML, and keep visual presentation in `model.typ`. For example, prefer +in YAML, and keep visual presentation in `modules/model.typ`. For example, prefer `severity: high` over fields that specify colors or fonts. Generated PDFs are reproducible artifacts suitable for email, handoff, @@ -124,7 +139,7 @@ See [LICENSE](LICENSE). Jenkins renders YAML reports and JSON diagnostics, validates the PDFs, and publishes encrypted archives to the same `/mnt/books` mount used by the books: -- `/mnt/books/Reports/Reports.zip`: YAML report PDFs. +- `/mnt/books/Reports/Reports.zip`: YAML report PDFs, preserving subfolders. - `/mnt/books/Reports/Diagnostics.zip`: diagnostic PDFs, preserving subfolders. Only the ZIPs are archived as Jenkins artifacts. The agent needs `uv` and Python 3, access to PyPI, diff --git a/diagnostics-rules.yaml b/config/diagnostics-rules.yaml similarity index 100% rename from diagnostics-rules.yaml rename to config/diagnostics-rules.yaml diff --git a/diagnostics-watchlist.yaml b/config/diagnostics-watchlist.yaml similarity index 100% rename from diagnostics-watchlist.yaml rename to config/diagnostics-watchlist.yaml diff --git a/themes.yaml b/config/themes.yaml similarity index 100% rename from themes.yaml rename to config/themes.yaml diff --git a/diagnostics.typ b/diagnostics.typ index e7cfcdd..411d832 100644 --- a/diagnostics.typ +++ b/diagnostics.typ @@ -1,5 +1,5 @@ -#import "diagnostics-model.typ": diagnostics-model -#import "diagnostics-normalize.typ": normalize, datetime-day +#import "modules/diagnostics-model.typ": diagnostics-model +#import "modules/diagnostics-normalize.typ": normalize, datetime-day #let diagnostics-file = sys.inputs.at("diagnostics", default: none) #let author = sys.inputs.at("author", default: none) @@ -36,7 +36,7 @@ ) } -#let rules = yaml("diagnostics-rules.yaml") +#let rules = yaml("config/diagnostics-rules.yaml") #let data = normalize(source, rules: rules, source-name: diagnostics-file) #if datetime-day(source.at("generated_at", default: "")) == none { @@ -46,7 +46,7 @@ ) } -#let themes = yaml("themes.yaml") +#let themes = yaml("config/themes.yaml") #let theme-name = lower(str(sys.inputs.at("theme", default: "default"))) #if theme-name not in themes { @@ -60,5 +60,5 @@ data: data, author: author, theme: themes.at(theme-name), - logo: "assets/beffroi.png", + logo: "/assets/beffroi.png", ) diff --git a/docs/advanced-setup.md b/docs/advanced-setup.md index 0d36511..bfdb17c 100644 --- a/docs/advanced-setup.md +++ b/docs/advanced-setup.md @@ -19,6 +19,16 @@ templates/ └── incident.yaml ``` +PDFs and exported ZIPs preserve the path beneath `reports/`, so +`reports/2026/incidents/api-latency.yaml` becomes +`build/2026/incidents/api-latency.pdf`. The top-level `diagnostics/` output +folder is reserved; use another name for YAML report groups. + +Use `./render.sh --clean --all` to remove old report PDFs before rebuilding. +Diagnostic PDFs are cleaned separately with +`./render-diagnostics.sh --clean --all "Your Name"`. +With a single input, `--clean` removes only its output PDF. + To avoid rendering template YAML during `--all`, keep reusable templates outside `reports/`, for example in a top-level `templates/` directory. @@ -26,7 +36,7 @@ outside `reports/`, for example in a top-level `templates/` directory. - Replace `assets/beffroi.png` with your logo, or update the `logo` argument in `report.typ`. -- Change colors, typography, spacing, and components in `model.typ`. +- Change colors, typography, spacing, and components in `modules/model.typ`. - Keep report-specific content out of the Typst model so historical YAML files remain reusable with later design changes. @@ -44,7 +54,7 @@ A report selects its theme by name: theme: eridani ``` -All themes live in the top-level `themes.yaml` registry. The built-in choices +All themes live in the `config/themes.yaml` registry. The built-in choices are `default`, `cic`, and `eridani`. To add one, copy an existing mapping, give it a new key, and adjust its values: @@ -66,7 +76,7 @@ my_theme: Color values use hexadecimal RGB notation. Fonts must be installed wherever the report is compiled; keeping the supplied DejaVu families is the most -portable option for this repository. After editing `themes.yaml`, compile at +portable option for this repository. After editing `config/themes.yaml`, compile at least one representative report with each affected theme. ### Image sources @@ -101,7 +111,7 @@ A minimal CI job only needs to install Typst and execute: Treat any non-zero exit code as a failed build. Pin the Typst version in CI if reproducible output is important, and use the same version locally when changing -`model.typ`. +`modules/model.typ`. For a lightweight local pre-commit check: diff --git a/docs/diagnostics.md b/docs/diagnostics.md index 9d85aa9..fec4b61 100644 --- a/docs/diagnostics.md +++ b/docs/diagnostics.md @@ -46,11 +46,11 @@ message. ## Pipeline -1. `diagnostics-normalize.typ` reads WinDiagnostics schema versions 1 and 2 JSON, +1. `modules/diagnostics-normalize.typ` reads WinDiagnostics schema versions 1 and 2 JSON, deduplicates event records, classifies signals, and builds normalized data entirely inside Typst. 2. `diagnostics.typ` validates the inputs and selected YAML theme. -3. `diagnostics-model.typ` renders the final PDF and uses PrimaViz for the +3. `modules/diagnostics-model.typ` renders the final PDF and uses PrimaViz for the summary visualization. No Python conversion or external normalization step is required for native captures. Typst reads @@ -128,7 +128,7 @@ Routine evidence is conditional: ## Upgradeable event heuristics -Event interpretation lives in `diagnostics-rules.yaml`, separate from the Typst +Event interpretation lives in `config/diagnostics-rules.yaml`, separate from the Typst parser and layout. Each rule matches an exact provider and event ID and defines its severity, rationale, and a heuristic confidence estimate: @@ -160,7 +160,7 @@ the arithmetic mean of displayed finding confidence values. The health graph is deliberately simple and reproducible: it begins at 100, subtracts 8 points per critical finding, 2 per warning, and 1 per unanalysed signal, then clamps the result to 0–100. Change those weights in -`diagnostics-normalize.typ` if operational experience calls for different +`modules/diagnostics-normalize.typ` if operational experience calls for different priorities. ## Closing findings safely @@ -228,7 +228,7 @@ and unknown events. Those signals may be persistent, intermittent, or unsafe to treat as resolved merely because no newer event was captured. The defaults can be overridden per safe rule with `fade_after_days` and -`fade_to_half_days` in `diagnostics-rules.yaml`. +`fade_to_half_days` in `config/diagnostics-rules.yaml`. A DISM result of `repairable` is classified as a warning, not a critical finding. Microsoft distinguishes it from a non-repairable image and provides @@ -272,7 +272,7 @@ typst compile \ ``` Available themes are `default`, `cic`, and `eridani` and are defined in -`themes.yaml`. +`config/themes.yaml`. ## Input expectations @@ -363,7 +363,7 @@ Explicit unhealthy disk states and IsSigned=false also receive review findings; missing fields do not establish either problem. The maintained [known-issue list](known-issues.md) explains matching and sources. -Its machine-readable rules live in `diagnostics-watchlist.yaml`. Warnings link to +Its machine-readable rules live in `config/diagnostics-watchlist.yaml`. Warnings link to the PDF watchlist and vendor advice; the PDF also links Microsoft's driver list. The watchlist is curated and offline, not an exhaustive or automatically updated vulnerability database. Compilation makes no network requests for advisories. diff --git a/docs/known-issues.md b/docs/known-issues.md index f6804a7..104a2a3 100644 --- a/docs/known-issues.md +++ b/docs/known-issues.md @@ -1,7 +1,7 @@ # Known driver, software and feature issues Reviewed: **2026-09-15**. The executable list is -[diagnostics-watchlist.yaml](../diagnostics-watchlist.yaml). It flags documented +[config/diagnostics-watchlist.yaml](../config/diagnostics-watchlist.yaml). It flags documented risks and compatibility conditions, not old release dates or vendor reputation. Every match becomes a warning with an advisory link and an internal link to the PDF's list. It adds no score penalty; independent event findings still do. diff --git a/diagnostics-model.typ b/modules/diagnostics-model.typ similarity index 99% rename from diagnostics-model.typ rename to modules/diagnostics-model.typ index 8650aa2..1837a7d 100644 --- a/diagnostics-model.typ +++ b/modules/diagnostics-model.typ @@ -144,7 +144,7 @@ ] ] -#let diagnostics-model(data: (:), author: "", theme: (:), logo: "assets/beffroi.png", body) = { +#let diagnostics-model(data: (:), author: "", theme: (:), logo: "/assets/beffroi.png", body) = { set page( paper: "a4", margin: (top: 18mm, bottom: 17mm, left: 18mm, right: 18mm), header: context header(theme, data, logo), footer: context footer(theme, data), diff --git a/diagnostics-normalize.typ b/modules/diagnostics-normalize.typ similarity index 99% rename from diagnostics-normalize.typ rename to modules/diagnostics-normalize.typ index ac07d94..a48d426 100644 --- a/diagnostics-normalize.typ +++ b/modules/diagnostics-normalize.typ @@ -202,7 +202,7 @@ item.insert("severity", if rule == none and get(event, "level", none) in (4, 5) { "info" } else if rule == none { get(rules, "unknown_event_severity", "unanalysed") } else { get(rule, "severity", "unanalysed") }) item.insert("rationale", if rule == none and get(event, "level", none) in (4, 5) { "Informational record retained without a reviewed interpretation; no fault inferred." } else if rule == none { "No reviewed interpretation is available for this event." } else { get(rule, "rationale", "") }) item.insert("remediation", if rule == none { "Add a reviewed provider/ID rule before attempting cleanup." } else { get(rule, "remediation", "") }) - item.insert("resolution_steps", if rule == none { ("Review the raw event and add a rule to diagnostics-rules.yaml.", "Re-run the report after the rule has been reviewed.") } else { get(rule, "resolution_steps", ()) }) + item.insert("resolution_steps", if rule == none { ("Review the raw event and add a rule to config/diagnostics-rules.yaml.", "Re-run the report after the rule has been reviewed.") } else { get(rule, "resolution_steps", ()) }) item.insert("reference_url", if rule == none { "" } else { get(rule, "reference_url", "") }) item.insert("reference_label", if rule == none { "" } else { get(rule, "reference_label", "Microsoft guidance") }) item.insert("confidence", if rule == none { 20 } else { get(rule, "confidence", 70) }) @@ -258,7 +258,7 @@ fields.map(pair => pair.at(0) + ": " + if pair.at(1) in ("LastWriteTime", "TimeGenerated", "DriverDate") { display-time(get(item, pair.at(1), "Unknown")) } else { value-text(get(item, pair.at(1), "Unknown")) }).join("\n", default: "") } -#let watchlist-catalog = yaml("diagnostics-watchlist.yaml") +#let watchlist-catalog = yaml("../config/diagnostics-watchlist.yaml") #let watch-matches(report, matcher) = { let name = matcher.section diff --git a/model.typ b/modules/model.typ similarity index 99% rename from model.typ rename to modules/model.typ index 82571bf..28ba00e 100644 --- a/model.typ +++ b/modules/model.typ @@ -666,7 +666,7 @@ #let report-model( report: (:), theme: (:), - logo: "assets/beffroi.png", + logo: "/assets/beffroi.png", body, ) = { set page( diff --git a/render-diagnostics.sh b/render-diagnostics.sh index 3d38169..5f6f9ae 100755 --- a/render-diagnostics.sh +++ b/render-diagnostics.sh @@ -5,11 +5,13 @@ ROOT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" DIAGNOSTICS_DIR="${ROOT_DIR}/diagnostics" BUILD_DIR="${ROOT_DIR}/build/diagnostics" +CLEAN=0 + usage() { cat <<'EOF_USAGE' Usage: - ./render-diagnostics.sh REPORT.json "Author Name" [theme] - ./render-diagnostics.sh --all "Author Name" [theme] + ./render-diagnostics.sh [--clean] REPORT.json "Author Name" [theme] + ./render-diagnostics.sh [--clean] --all "Author Name" [theme] Examples: ./render-diagnostics.sh diagnostics/windows_system_report_PC.json "Jane Doe" @@ -17,6 +19,9 @@ Examples: ./render-diagnostics.sh --all "Jane Doe" ./render-diagnostics.sh --all "Jane Doe" eridani +--clean removes old PDFs before rendering: all PDFs in this category with +--all, or only the selected output with a single input. Other files are kept. + The theme is optional and defaults to "default". Available themes: default, cic, eridani EOF_USAGE @@ -53,6 +58,10 @@ render_diagnostics() { local output="${BUILD_DIR}/${relative_output}" mkdir -p "$(dirname -- "$output")" + if [[ "$CLEAN" -eq 1 ]]; then + rm -f -- "$output" + fi + echo "Rendering: $input_typst" echo " -> ${output#"$ROOT_DIR/"}" @@ -75,6 +84,10 @@ render_all() { [[ -d "$DIAGNOSTICS_DIR" ]] \ || die "diagnostics directory not found: $DIAGNOSTICS_DIR" + if [[ "$CLEAN" -eq 1 && -d "$BUILD_DIR" ]]; then + find "$BUILD_DIR" -type f -name '*.pdf' -exec rm -f -- {} + + fi + while IFS= read -r -d '' input; do found=1 render_diagnostics "$input" "$author" "$theme" @@ -89,6 +102,15 @@ render_all() { } main() { + local args=() + for arg in "$@"; do + case "$arg" in + --clean) CLEAN=1 ;; + -h|--help) usage; return ;; + *) args+=("$arg") ;; + esac + done + set -- "${args[@]}" command -v typst >/dev/null 2>&1 || die "typst was not found" [[ $# -ge 2 && $# -le 3 ]] || { usage; exit 1; } diff --git a/render.sh b/render.sh index fc560cc..313d714 100755 --- a/render.sh +++ b/render.sh @@ -4,21 +4,25 @@ set -euo pipefail ROOT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" REPORT_DIR="${ROOT_DIR}/reports" BUILD_DIR="${ROOT_DIR}/build" +CLEAN=0 ENTRYPOINT="${ROOT_DIR}/report.typ" usage() { cat <<'EOF' Usage: - ./render.sh PATH - ./render.sh --all + ./render.sh [--clean] PATH + ./render.sh [--clean] --all Examples: ./render.sh reports/2026-09-04-clevo-handoff.yaml - ./render.sh --all + ./render.sh --clean --all Outputs PDFs into: ./build/ +--clean removes old PDFs before rendering: all PDFs in this category with +--all, or only the selected output with a single input. Other files are kept. + Requirements: - typst must be available in PATH EOF @@ -54,9 +58,19 @@ render_report() { filename="$(basename -- "$input")" basename="${filename%.*}" - output="${BUILD_DIR}/${basename}.pdf" + local relative="$basename" + if [[ "$input" == "$REPORT_DIR/"* ]]; then + relative="${input#"$REPORT_DIR/"}" + relative="${relative%.*}" + fi + [[ "$relative" != diagnostics && "$relative" != diagnostics/* ]] \ + || die "reports/diagnostics is reserved for diagnostic PDF output" + output="${BUILD_DIR}/${relative}.pdf" - mkdir -p "$BUILD_DIR" + mkdir -p "$(dirname -- "$output")" + if [[ "$CLEAN" -eq 1 ]]; then + rm -f -- "$output" + fi echo "Rendering: $input" echo " -> $output" @@ -86,6 +100,10 @@ render_all() { mkdir -p "$BUILD_DIR" + if [[ "$CLEAN" -eq 1 ]]; then + find "$BUILD_DIR" -path "$BUILD_DIR/diagnostics" -prune -o -type f -name '*.pdf' -exec rm -f -- {} + + fi + local found=0 while IFS= read -r -d '' report; do @@ -109,6 +127,15 @@ render_all() { } main() { + local args=() + for arg in "$@"; do + case "$arg" in + --clean) CLEAN=1 ;; + -h|--help) usage; return ;; + *) args+=("$arg") ;; + esac + done + set -- "${args[@]}" check_dependencies [[ $# -eq 1 ]] || { diff --git a/report.typ b/report.typ index 403bb1b..477bdec 100644 --- a/report.typ +++ b/report.typ @@ -1,4 +1,4 @@ -#import "model.typ": report-model +#import "modules/model.typ": report-model #let report-file = sys.inputs.at("report", default: none) @@ -28,7 +28,7 @@ ) } -#let themes = yaml("themes.yaml") +#let themes = yaml("config/themes.yaml") #let theme-name = lower(str(report.at("theme", default: "default"))) #if theme-name not in themes { @@ -44,5 +44,5 @@ #show: report-model.with( report: report, theme: theme, - logo: "assets/beffroi.png", + logo: "/assets/beffroi.png", ) diff --git a/tools/check-diagnostics.typ b/tools/check-diagnostics.typ index 9b612a5..4eafa41 100644 --- a/tools/check-diagnostics.typ +++ b/tools/check-diagnostics.typ @@ -1,6 +1,6 @@ -#import "../diagnostics-normalize.typ": normalize, value-text, datetime-day, date-index, datetime-second, catalog-correlation, group-events, display-time +#import "../modules/diagnostics-normalize.typ": normalize, value-text, datetime-day, date-index, datetime-second, catalog-correlation, group-events, display-time -#let rules = yaml("../diagnostics-rules.yaml") +#let rules = yaml("../config/diagnostics-rules.yaml") #let fixture = json("fixtures/windiagnostics-v1.json") #let data = normalize(fixture, rules: rules, source-name: "tools/fixtures/windiagnostics-v1.json") @@ -163,7 +163,7 @@ Diagnostics JSON regression checks passed. #assert.eq(captured-v2.event_groups.find(item => item.provider == "Microsoft-Windows-CodeIntegrity" and item.id == "3099").severity, "info") #assert(captured-v2.findings.any(item => item.at("watch_id", default: "") == "intel-wifi-observed")) #assert(not captured-v2.findings.any(item => item.at("watch_id", default: "") == "obs-overlay")) -#import "../diagnostics-normalize.typ": watchlist-findings, reliability-events +#import "../modules/diagnostics-normalize.typ": watchlist-findings, reliability-events #let watch-report = json("fixtures/windiagnostics-watchlist.json") #let watch = normalize(watch-report, rules: rules) #let watch-ids = watch.findings.filter(f => "watch_id" in f).map(f => f.watch_id) diff --git a/tools/package-reports.sh b/tools/package-reports.sh index e726450..ae7bdb2 100755 --- a/tools/package-reports.sh +++ b/tools/package-reports.sh @@ -16,7 +16,7 @@ for category in Reports Diagnostics; do mkdir -p "$staging_dir/$category" if [[ "$category" == Reports ]]; then source_dir="$build_dir" - depth=(-maxdepth 1) + depth=(-path "$build_dir/diagnostics" -prune -o) else source_dir="$build_dir/diagnostics" depth=()