This repository has been archived on 2026-09-16. You can view files and clone it, but cannot push or open issues or pull requests.
typst_reporter/modules/diagnostics-model.typ

366 lines
18 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#import "@preview/primaviz:0.10.0": progress-bar
#let get(dict, key, default) = if key in dict and dict.at(key) != none { dict.at(key) } else { default }
#let color(theme, key) = rgb(str(get(theme, key, "#000000")))
#let ink(theme) = color(theme, "ink")
#let muted(theme) = color(theme, "muted")
#let accent(theme) = color(theme, "accent")
#let line-color(theme) = color(theme, "line")
#let soft(theme) = color(theme, "paper_soft")
#let severity-color(theme, severity) = {
let value = lower(str(severity))
if value == "critical" or value == "high" { color(theme, "critical") }
else if value == "warning" or value == "medium" { color(theme, "warning") }
else if value == "success" or value == "ok" { color(theme, "success") }
else if value == "unanalysed" { color(theme, "info") }
else { color(theme, "info") }
}
#let badge(body, fill) = box(
inset: (x: 5pt, y: 2pt), radius: 2pt,
fill: fill.lighten(86%), stroke: .5pt + fill.lighten(50%),
text(size: 7pt, weight: "bold", fill: fill)[#upper(str(body))],
)
#let heading(theme, body) = block(above: 10pt, below: 5pt, width: 100%)[
#text(size: 14pt, weight: "bold", fill: accent(theme))[#body]
#v(2pt)
#line(length: 100%, stroke: .7pt + line-color(theme))
]
#let part-title(theme, number, body, description: none) = block(width: 100%, below: 10pt)[
#text(size: 7.5pt, weight: "bold", fill: muted(theme))[SECTION #number]
#v(2pt)
#text(size: 19pt, weight: "bold", fill: accent(theme))[#body]
#if description != none { v(2pt); text(size: 8.5pt, fill: muted(theme))[#description] }
#v(4pt)
#line(length: 100%, stroke: .8pt + line-color(theme))
]
#let panel(theme, body, stroke: none, fill: none) = block(
width: 100%, inset: 8pt, radius: 3pt,
fill: if fill == none { soft(theme) } else { fill },
stroke: .5pt + if stroke == none { line-color(theme) } else { stroke },
body,
)
#let metric(theme, title, value, note: none, tone: none) = {
let tone = if tone == none { accent(theme) } else { tone }
block(width: 100%, inset: 7pt, radius: 3pt, fill: tone.lighten(91%), stroke: .5pt + tone.lighten(60%))[
#text(size: 7pt, weight: "bold", fill: muted(theme))[#upper(title)]
#v(2pt)
#text(size: 16pt, weight: "bold", fill: tone)[#value]
#if note != none { v(1pt); text(size: 7pt, fill: muted(theme))[#note] }
]
}
#let header(theme, data, logo) = {
grid(columns: (1fr, auto), align: (left, right + horizon),
text(size: 7.5pt, weight: "bold", fill: muted(theme))[
Beffroi — Windows diagnostics
],
image(logo, height: 8mm, fit: "contain"),
)
v(3pt)
line(length: 100%, stroke: .5pt + line-color(theme))
}
#let footer(theme, data) = grid(
columns: (1fr, auto), align: (left, right),
text(size: 7pt, fill: muted(theme))[#get(data, "computer", "Unknown") · #get(data, "generated", "Unknown")],
text(size: 7pt, fill: muted(theme))[Page #context counter(page).display()],
)
#let short-text(value, limit: 400) = {
let text = str(value)
if text.len() > limit { text.slice(0, limit) + "… [excerpt; full text in source JSON]" } else { text }
}
#let finding-target(index) = label("diagnostic-finding-" + str(index))
#let finding-card(theme, finding, show-remediation: true, target-index: none, link-index: none) = {
let tone = severity-color(theme, get(finding, "severity", "info"))
if target-index != none { [#metadata("finding") #finding-target(target-index)] }
block(width: 100%, breakable: true, inset: 7pt, radius: 3pt,
stroke: (left: 2.5pt + tone, top: .5pt + line-color(theme), right: .5pt + line-color(theme), bottom: .5pt + line-color(theme)),
)[
#grid(columns: (1fr, auto), gutter: 6pt,
text(weight: "bold", fill: ink(theme))[#get(finding, "title", "Finding")],
[#badge(get(finding, "severity", "info"), tone) #h(3pt) #badge(str(get(finding, "confidence", 50)) + "% confidence", tone)],
)
#v(3pt)
#text(size: 8.5pt, fill: ink(theme))[#get(finding, "detail", "")]
#if show-remediation and get(finding, "evidence", "") != "" {
v(2pt)
text(size: 7.5pt, fill: muted(theme))[Evidence: #short-text(finding.evidence)]
}
#if show-remediation and get(finding, "watch_id", none) != none {
v(2pt)
text(size: 7.5pt, fill: accent(theme))[#link(label("watchlist-" + finding.watch_id))[View known-issue list →]]
}
#if link-index != none {
v(3pt)
text(size: 7.5pt, weight: "bold", fill: accent(theme))[
#link(finding-target(link-index))[View resolution →]
]
}
#if get(finding, "fading", false) and get(finding, "weight_factor", 1.0) < 1.0 {
v(2pt)
let pct = calc.round(get(finding, "weight_factor", 1.0) * 100)
text(size: 7pt, style: "italic", fill: muted(theme))[Age-adjusted to #pct% weight at #get(finding, "age_days", 0) days old; never reduced below 50%.]
}
#if show-remediation and (get(finding, "resolution_steps", ()).len() > 0 or get(finding, "remediation", "") != "") {
v(4pt)
text(size: 7.5pt, weight: "bold", fill: tone)[RESOLUTION PATH]
v(2pt)
let steps = get(finding, "resolution_steps", ())
if steps.len() > 0 {
for (index, step) in steps.enumerate() {
grid(columns: (10pt, 1fr), gutter: 3pt, text(size: 7.8pt, weight: "bold", fill: tone)[#str(index + 1).], text(size: 8pt, fill: ink(theme))[#step])
v(1.5pt)
}
} else {
grid(columns: (10pt, 1fr), gutter: 3pt, text(size: 7.8pt, weight: "bold", fill: tone)[1.], text(size: 8pt, fill: ink(theme))[#get(finding, "remediation", "")])
}
let url = get(finding, "reference_url", "")
if url != "" { v(2pt); text(size: 7.5pt, fill: accent(theme))[#link(url)[#get(finding, "reference_label", "Reference guidance") ↗]] }
}
#if get(finding, "count", 0) > 1 {
v(2pt)
text(size: 7.5pt, fill: muted(theme))[Observed #get(finding, "count", 0) times in the captured window.]
}
]
v(5pt)
}
#let evidence(theme, item) = block(width: 100%, breakable: get(item, "text", "").len() > 2000, below: 6pt)[
#let tone = severity-color(theme, get(item, "severity", "info"))
#text(size: 9pt, weight: "bold", fill: tone)[#get(item, "title", "Evidence")]
#v(3pt)
#block(width: 100%, inset: 6pt, radius: 2pt, fill: tone.lighten(94%), stroke: (left: 2pt + tone, top: .4pt + line-color(theme), right: .4pt + line-color(theme), bottom: .4pt + line-color(theme)))[
#text(font: get(theme, "mono_font", "DejaVu Sans Mono"), size: 6.8pt, fill: ink(theme))[
#get(item, "text", "")
]
]
]
#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),
)
set text(font: get(theme, "font", "DejaVu Sans"), size: 9pt, fill: ink(theme), lang: "en")
set par(leading: .55em, spacing: .5em)
let findings = get(data, "findings", ())
let priority-findings = findings.filter(item => {
let title = get(item, "title", "")
title.contains("System-file") or title.contains("Firewall")
})
priority-findings += findings.filter(item => {
let title = get(item, "title", "")
not title.contains("System-file") and not title.contains("Firewall")
})
let counts = get(data, "issue_counts", (:))
let critical = get(counts, "critical", 0)
let warnings = get(counts, "warning", 0)
let system = get(data, "system", (:))
let ram-total = get(system, "ram_total_gb", 0)
let ram-free = get(system, "ram_free_gb", 0)
let disks = get(data, "disk_free", ())
let health-score = get(data, "health_score", 0)
let analysis-confidence = get(data, "analysis_confidence", 50)
let assessment-tone = if critical > 0 { color(theme, "critical") } else if warnings > 0 { color(theme, "warning") } else { color(theme, "success") }
let health-tone = if get(data, "collection_incomplete", false) { color(theme, "warning") } else if health-score < 50 { color(theme, "critical") } else if health-score < 75 { color(theme, "warning") } else { color(theme, "success") }
// Page 1: deliberately short and decision-oriented.
text(size: 7.5pt, weight: "bold", fill: muted(theme))[SECTION 01 · EXECUTIVE OVERVIEW]
v(3pt)
block(below: 8pt)[
#text(size: 22pt, weight: "bold", fill: accent(theme))[Windows diagnostic assessment]
#v(3pt)
#text(size: 10.5pt, fill: muted(theme))[
#get(data, "computer", "Unknown computer") · #get(data, "mode", "Unknown") collection · Administrator: #get(data, "administrator", "Unknown")
]
]
panel(theme, stroke: assessment-tone, fill: assessment-tone.lighten(92%))[
#text(size: 8pt, weight: "bold", fill: assessment-tone)[OVERALL ASSESSMENT]
#v(3pt)
#text(size: 17pt, weight: "bold", fill: assessment-tone)[#get(data, "health", "Unknown")]
#v(3pt)
#text(size: 8.5pt)[Generated #get(data, "generated", "Unknown") · Reviewed by #author]
]
v(7pt)
grid(columns: (1fr, 1fr, 1fr, 1fr), gutter: 5pt,
metric(theme, "Critical", str(critical), tone: color(theme, "critical")),
metric(theme, "Warnings", str(warnings), tone: color(theme, "warning")),
metric(theme, "RAM maximum", str(ram-total) + " GB"),
metric(theme, "Analysis confidence", str(analysis-confidence) + "%"),
)
v(5pt)
if get(data, "collection_incomplete", false) {
text(size: 8pt, weight: "bold", fill: color(theme, "warning"))[Collection is partial. The score covers observed signals only; unavailable checks cannot establish health. Confidence is capped at 50%.]
}
v(7pt)
panel(theme, stroke: health-tone)[
#grid(columns: (1fr, auto),
[#text(size: 8pt, weight: "bold", fill: ink(theme))[#if get(data, "collection_incomplete", false) { [OBSERVED SIGNAL SCORE · PARTIAL COLLECTION] } else { [HEALTH ANALYSIS] }]],
[#text(size: 15pt, weight: "bold", fill: health-tone)[#health-score / 100]],
)
#v(4pt)
#block(width: 100%, height: 7pt, radius: 3.5pt, fill: line-color(theme))[
#block(width: health-score * 1%, height: 100%, radius: 3.5pt, fill: health-tone)
]
#v(3pt)
#text(size: 7pt, fill: muted(theme))[Heuristic score: 100 − 8 per critical − 2 per warning − 1 per unanalysed signal, with approved age fading. Analysis confidence: #analysis-confidence%. Neither value is a failure probability.]
]
heading(theme, "Priority findings")
if findings.len() == 0 {
panel(theme)[No actionable exceptions were detected. This is not proof that the system is fault-free.]
} else {
for finding in priority-findings.slice(0, calc.min(4, priority-findings.len())) {
let finding-index = findings.position(item => item == finding)
finding-card(theme, finding, show-remediation: false, link-index: finding-index)
}
}
if disks.len() > 0 {
heading(theme, "Storage headroom")
block(width: 100%, inset: 7pt, radius: 3pt, fill: soft(theme), stroke: .5pt + line-color(theme))[
#for disk in disks.slice(0, calc.min(4, disks.len())) {
let free-percent = get(disk, "free_percent", 0)
let disk-tone = if free-percent < 10 { color(theme, "critical") } else if free-percent < 20 { color(theme, "warning") } else { color(theme, "success") }
grid(columns: (15mm, 1fr, 34mm), gutter: 5pt, align: (left + horizon, left + horizon, right + horizon),
text(size: 8pt, weight: "bold")[#get(disk, "drive", "Disk")],
progress-bar(free-percent, width: 100%, height: 7pt, show-value: false, color: disk-tone, background: line-color(theme), theme: (background: soft(theme))),
text(size: 7.5pt, fill: muted(theme))[#str(get(disk, "free_gb", 0)) GB · #str(free-percent)% free],
)
v(3pt)
}
#text(size: 7pt, fill: muted(theme))[Free capacity is shown rather than used capacity; low headroom is the actionable condition.]
]
}
pagebreak()
part-title(theme, "02", "Findings requiring attention", description: "Actionable exceptions and the event evidence that supports them.")
heading(theme, "Resolution plan")
for (index, finding) in findings.enumerate() { finding-card(theme, finding, target-index: index) }
pagebreak()
heading(theme, "Correlated event evidence")
[Requested history: #get(get(data, "parameters", (:)), "event_log_days", 7) days; configured maximum: #get(get(data, "parameters", (:)), "max_event_errors", 100) per log. Returned Windows levels: #get(data, "event_counts", (:)).pairs().map(pair => pair.at(0) + ": " + str(pair.at(1))).join(", "). Counts describe captured records; see coverage for truncation and unavailable logs.]
v(5pt)
let event-groups = get(data, "event_groups", ())
let contextual = event-groups.filter(event => get(event, "severity", "info") == "info")
if contextual.len() > 0 {
text(size: 8pt)[Contextual events are summarized below; full messages remain in the JSON.]
table(columns: (1fr, auto, auto, 1.4fr), inset: 3pt, stroke: .3pt + line-color(theme),
table.header([Provider], [ID], [Count], [Interpretation]),
..contextual.map(event => ([#event.provider], [#event.id], [#str(event.count)], [#event.rationale])).flatten(),
)
v(6pt)
}
[Actionable groups show one representative message (up to 600 characters). All occurrence counts and latest timestamps are retained; other message variants remain in source JSON. Reliability history supplements events missing from the bounded logs.]
v(4pt)
for event in event-groups.filter(event => get(event, "severity", "info") != "info") {
let tone = severity-color(theme, get(event, "severity", "info"))
block(width: 100%, breakable: true, below: 5pt, inset: 6pt, fill: tone.lighten(95%), stroke: (left: 2.5pt + tone, top: .4pt + line-color(theme), right: .4pt + line-color(theme), bottom: .4pt + line-color(theme)), radius: 2pt)[
#grid(columns: (1fr, auto), gutter: 5pt,
[*#get(event, "provider", "Unknown")* · Event #get(event, "id", "?")],
[#badge(get(event, "severity", "info"), tone) #h(3pt) #badge(str(get(event, "count", 1)) + "×", tone)],
)
#v(2pt)
#text(size: 8pt)[#short-text(get(event, "messages", (get(event, "message", ""),)).first(), limit: 600)]
#if get(event, "rationale", "") != "" { v(2pt); text(size: 7.5pt, style: "italic", fill: tone)[#get(event, "rationale", "")] }
#v(1pt)
#text(size: 7pt, fill: muted(theme))[Log: #get(event, "log", "Unknown") · Windows level: #str(get(event, "level", "Unknown")) (#get(event, "level_display", "Unknown")) · Latest captured: #get(event, "display_time", get(event, "time", "Unknown"))]
]
}
pagebreak()
part-title(theme, "03", "Technical evidence", description: "System context, selected source evidence, and an audit of collector coverage.")
heading(theme, "System profile")
table(
columns: (32mm, 1fr, 32mm, 1fr), inset: 5pt, stroke: .4pt + line-color(theme),
fill: (x, y) => if calc.rem(y, 2) == 0 { soft(theme) } else { none },
[Computer], [#get(data, "computer", "Unknown")], [Administrator], [#get(data, "administrator", "Unknown")],
[Operating system], [#get(system, "os", "Unknown")], [Build], [#get(system, "build", "Unknown")],
[CPU], [#get(system, "cpu", "Unknown")], [Cores / threads], [#get(system, "cores", "?") / #get(system, "threads", "?")],
[Memory], [#str(ram-total) GB total], [Free at capture], [#str(ram-free) GB],
)
if disks.len() > 0 {
heading(theme, "Storage capacity")
for disk in disks {
let used = 100 - get(disk, "free_percent", 0)
panel(theme)[
#grid(columns: (1fr, auto), [*#get(disk, "drive", "Disk")*], [#str(get(disk, "free_gb", 0)) GB free of #str(get(disk, "size_gb", 0)) GB])
#v(4pt)
#block(width: 100%, height: 5pt, radius: 2.5pt, fill: line-color(theme))[
#block(width: used * 1%, height: 100%, radius: 2.5pt, fill: if used > 90 { color(theme, "critical") } else if used > 80 { color(theme, "warning") } else { accent(theme) })
]
]
v(4pt)
}
}
heading(theme, "Inventory summary")
let inventory = get(data, "inventory", ())
table(
columns: (1fr, 22mm), inset: 4pt, stroke: .4pt + line-color(theme),
table.header([Category], [Count]),
..inventory.map(item => ([#get(item, "label", "")], [#get(item, "count", 0)])).flatten(),
)
heading(theme, "Selected source evidence")
[Selected evidence shows up to three records and 1,200 characters per expanded section. Routine service/driver inventories, successful native command dumps and update successes are summarized. Complete data remains in the source JSON.]
v(5pt)
for item in get(data, "excerpts", ()) { evidence(theme, item) }
heading(theme, "Known-issue watchlist")
let watchlist = get(data, "watchlist", (:))
text(size: 8pt)[Reviewed #get(watchlist, "reviewed", "Unknown"). Matches raise review warnings; they do not establish crash causation. This curated list is not an exhaustive vulnerability scan. Advisory warnings add no score penalty; observed failures retain their event penalties.]
v(3pt)
text(size: 8pt, fill: accent(theme))[#link(get(watchlist, "driver_list_url", ""))[Microsoft vulnerable driver list ↗]]
v(4pt)
table(columns: (20mm, 1fr, 27mm), inset: 4pt, stroke: .3pt + line-color(theme),
table.header([Type], [Known issue], [Reference]),
..get(watchlist, "entries", ()).map(entry => (
[#entry.category],
[#metadata("watchlist") #label("watchlist-" + entry.id) #entry.title],
[#link(get(entry, "list_url", entry.reference_url))[Source ↗]],
)).flatten(),
)
pagebreak()
heading(theme, "Analysis coverage")
[Every supplied WinDiagnostics JSON section is accounted for. This table records how each section contributed without reproducing low-value bulk data.]
v(4pt)
table(
columns: (1fr, 1fr, 15mm), inset: 4pt, stroke: none,
fill: (x, y) => if y == 0 { soft(theme) } else {
let item = get(data, "coverage", ()).at(y - 1, default: (:))
severity-color(theme, get(item, "severity", "info")).lighten(92%)
},
table.header([Collector section], [Treatment], [Records]),
..get(data, "coverage", ()).map(item => (
[#get(item, "section", "")], [#get(item, "use", "")], [#if get(item, "records", 0) == "Unavailable" { [—] } else { get(item, "records", 0) }],
)).flatten(),
)
v(3pt)
text(size: 7pt, fill: muted(theme))[— = unavailable record count.]
v(8pt)
text(size: 7pt, fill: muted(theme))[
Source: #get(data, "source", "Unknown"). This synthesis is heuristic: it prioritizes exceptions and suppresses routine inventory, but does not replace targeted diagnosis.
]
}