Skip to content

feat(trends): HTML trend report with SVG dot charts#306

Merged
decko merged 5 commits into
mainfrom
soda/280
May 20, 2026
Merged

feat(trends): HTML trend report with SVG dot charts#306
decko merged 5 commits into
mainfrom
soda/280

Conversation

@decko
Copy link
Copy Markdown
Owner

@decko decko commented May 20, 2026

Summary

Implements an HTML trend report for raki trends with interactive SVG dot-chart timelines, tier grouping, zone-colour coding, and config-break markers. Adds --html FILE and -o/--output FILE flags to the trends subcommand.

What was built

Task 1 — Data layer (TrendChartData + build_trends_template_data()):

  • TrendChartData frozen dataclass with dot_positions, zone_color, config_break_indices, delta_badge
  • build_trends_template_data() converts MetricTrend → TrendChartData with SVG coordinates
  • _compute_dot_positions(): maps values to SVG pixel space (y-axis inverted for SVG)
  • _zone_color_for_trend(): reuses existing html_color_for_score() thresholds
  • _detect_config_breaks(): compares adjacent config_hash values

Task 2 — HTML template (trends.html.j2):

  • Dark-themed, self-contained HTML with inline CSS
  • SVG polyline + circle dot charts per metric
  • Tier groups: Operational → Knowledge → Analytical
  • Config-break dashed vertical lines, delta badges, direction indicators
  • Empty-state for no data

Task 3 — HTML renderer (write_trends_html_report() + build_summary_sentence()):

  • Auto-creates parent directories
  • build_summary_sentence() counts improving/declining/stable metrics

Task 4 — CLI wiring:

  • --html FILE: writes HTML trends report, with path traversal guard
  • -o/--output FILE: companion to --json for file output
  • Hint line: "Tip: use --html FILE…" after the table when --html not given

Task 5changes/280.feature towncrier fragment
Task 6 — New "Trends report" section in docs/comparing-runs.md

Acceptance Criteria

  • TrendChartData dataclass with dot_positions, zone_color, config_break_indices, delta_badge
  • build_trends_template_data() converts MetricTrend to SVG coordinates
  • trends.html.j2 dark-themed template with SVG dot charts and tier grouping
  • write_trends_html_report() renderer with auto-directory creation
  • --html FILE CLI flag with path traversal guard
  • -o/--output FILE companion flag for JSON file output
  • Hint line in table output when --html not given
  • Towncrier changelog fragment (changes/280.feature)
  • Documentation in docs/comparing-runs.md
  • 1750 tests passing

Review Results

Finding 1 — IMPORTANT (python-specialist, rag-specialist)

File: src/raki/cli.py:1390
Issue: Missing path traversal guard for --json -o FILE. The --html path has a traversal check (resolved_html.relative_to(project_root)), but the --json -o code path at lines 1390–1394 writes to any user-supplied path without validation. raki trends --json -o /etc/cron.d/evil would write outside the project.
Suggestion: Add the same Path(output_path).resolve().relative_to(Path.cwd().resolve()) guard before the JSON file write, raising click.UsageError on failure. Consider extracting a shared _validate_output_path(path: str) -> Path helper.

Finding 2 — MINOR (python-specialist)

File: docs/comparing-runs.md:249
Issue: Documentation incorrectly claims the y-axis flips for lower_is_better metrics. In reality, _compute_dot_positions() always maps higher values to higher visual positions regardless of higher_is_better.
Suggestion: Simplify to: "Higher values always map to higher dot positions. Use the zone colour and direction indicator to determine whether a value is good or bad for a given metric."

Finding 3 — MINOR (python-specialist, rag-specialist)

File: src/raki/cli.py:1324
Issue: -o FILE without --json silently produces HTML output because line 1324 aliases -o to --html when json_output is False. A user running raki trends -o report.txt may not expect HTML content. Also, when both --html a.html and -o b.html are given, -o is silently ignored.
Suggestion: Either (a) require --html or --json to be explicit when -o is used, or (b) clarify the help text to read "Alias for --html when --json is not given; companion to --json for file output".

Finding 4 — MINOR (rag-specialist)

File: src/raki/cli.py:1388
Issue: --json --html FILE silently ignores the --html flag due to the early return on line 1397. The user gets no warning that their HTML report was skipped.
Suggestion: Either emit a warning when both --json and --html/effective_html_path are set, or write both outputs (JSON first, then HTML).


Refs #280

Assisted-by: Claude Opus 4.6 (1M context) noreply@anthropic.com
Assigned-by: decko

decko added 5 commits May 20, 2026 13:15
Add SVG-ready data layer for the HTML trends report:
- TrendChartData frozen dataclass with dot_positions (SVG coords),
  zone_color (CSS color class), config_break_indices, and delta_badge
- build_trends_template_data() converts MetricTrend → TrendChartData
- _compute_dot_positions(): maps values to SVG pixel coordinates
- _zone_color_for_trend(): CSS color based on current value + thresholds
- _detect_config_breaks(): finds runs where config_hash changed
- 18 tests covering SVG coords, zone colors, config-break detection,
  delta badges

Ticket-280
New Jinja2 template for the HTML trends report:
- Dark-themed, self-contained HTML (no external deps)
- SVG dot charts with polyline trend lines per metric
- Tier grouping: Operational → Knowledge → Analytical sections
- Zone-colour coded dots (green/yellow/red/white) matching run report
- Config-break dashed vertical lines at hash-change boundaries
- Delta badge (positive/negative/neutral styling)
- Direction badge (▲ improving / ▼ declining / = stable / — n/a)
- Empty-state handling when no trend data is available
- 5 template tests (SVG elements, tiers, zones, names, summary)

Ticket-280
Add two new flags to the trends command:
- --html FILE: write a self-contained HTML dot-chart trends report
- -o / --output FILE: companion to --json, writes JSON to a file
  instead of stdout

Also:
- Path traversal guard on --html: rejects paths outside project root
- Hint line: 'Tip: use --html FILE…' is printed after the table when
  --html is not given but trend data exists
- 7 new CLI tests covering all flag combinations

Ticket-280
Document the new --html and --json -o flags for 'raki trends':
- HTML report generation with --html FILE
- JSON file output with --json -o FILE
- Chart anatomy: dot chart, zone colours, config-break markers,
  delta badge, direction indicator
- Tier grouping table (Operational → Knowledge → Analytical)
- Combined usage with --since / --last time filters

Ticket-280
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted Implemented with AI assistance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant