---
title: "Pipeline Telemetry"
format:
  html:
    toc: true
    toc-expand: 2
    toc-location: left
    code-fold: true
    code-summary: "Show code"
vignette: >
  %\VignetteIndexEntry{Pipeline Telemetry}
  %\VignetteEngine{quarto::html}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
#| echo: false
#| results: asis
in_pkgdown <- nzchar(Sys.getenv("IN_PKGDOWN"))
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = TRUE,
  message = FALSE,
  warning = FALSE,
  fig.width = 8,
  fig.height = 6
)
if (!in_pkgdown) library(targets)

# Shared vignette utilities (safe_tar_read, show_target, render helpers)
utils_path <- system.file("vignette_utils.R", package = "coMMpass")
if (utils_path == "") {
  utils_path <- if (file.exists("../inst/vignette_utils.R")) "../inst/vignette_utils.R"
  else if (file.exists("inst/vignette_utils.R")) "inst/vignette_utils.R"
  else stop("Cannot find vignette_utils.R")
}
source(utils_path, local = TRUE)
```

```{r pkgdown-banner}
#| results: asis
#| eval: !expr in_pkgdown
#| echo: false
cat("::: {.callout-note}\n## Online documentation\nThis vignette displays pre-computed results. Run the targets pipeline locally for interactive analysis.\n:::\n")
```

Pipeline build telemetry from `targets::tar_meta()`. All outputs are
pre-computed targets reading the `_targets/meta/meta` CSV.

## Build Timing

Targets ordered by build duration. Long-running targets are candidates
for caching optimization or parallel execution via `crew`.

```{r timing-table}
#| echo: false
#| results: asis
show_target("vig_timing_table")
```

## Build Status Summary

High-level pipeline health metrics: target counts, build time, and storage size.

```{r status-table}
#| echo: false
#| results: asis
show_target("vig_build_status")
```

## Errors and Warnings

Targets that produced errors or warnings during the most recent pipeline run.

```{r errors}
#| echo: false
#| results: asis
show_target("vig_errors_table")
```

## Outdated Targets

Targets that need rebuilding due to changed code or upstream dependencies.

```{r outdated}
#| echo: false
#| results: asis
show_target("vig_outdated_list")
```

## Size Distribution

Distribution of target serialized sizes, identifying large objects that dominate storage.

```{r size-plot, fig.height=5}
#| echo: false
#| results: asis
show_target("vig_size_plot")
```

## Git Activity

### Commit Velocity

Weekly commit counts colored by conventional-commit type (feat, fix, docs, etc.)
across the last 200 commits.

```{r commit-velocity, fig.height=5}
#| echo: false
#| results: asis
show_target("vig_commit_velocity")
```

### Changes by Type

Commits grouped by conventional-commit prefix, with total lines added and removed.

```{r changes-by-type}
#| echo: false
#| results: asis
show_target("vig_changes_by_type")
```

### Changes by File Category

How often each file category (R Source, Tests, Vignettes, CI/CD, etc.) was
touched across the last 200 commits.

```{r changes-by-file-category}
#| echo: false
#| results: asis
show_target("vig_changes_by_file_category")
```

### Recent Commits

Full 20-commit changelog with lines added, files changed, and change categories.

```{r recent-commits}
#| echo: false
#| results: asis
show_target("vig_git_changelog")
```

## GitHub Activity

### Issues & Pull Requests

Open/closed issue and merged PR counts from the GitHub API.

```{r github-activity}
#| echo: false
#| results: asis
show_target("vig_github_activity_table")
```

### Codebase Metrics

R files, test files, exports, lines of code, and package version.

```{r codebase-metrics}
#| echo: false
#| results: asis
show_target("vig_codebase_metrics")
```

## Chunk-Target Audit

Mapping of every R code chunk across all vignettes to its pipeline target.
Exceptions are infrastructure chunks (setup, banners, sessionInfo) or violations.

```{r chunk-audit}
#| echo: false
#| results: asis
show_target("vig_chunk_audit_table")
```

## Reproducibility

<details>
<summary>Session Info (click to expand)</summary>

```{r session-info, eval=TRUE}
sessionInfo()
```

</details>
