---
name: yad-defects
description: 'Report a thread''s defects by the gate that should have caught them, and by root cause. Never a gate. Use when the user says "show the defect report", "where are our quality gaps", "generate the bug report for this epic", or "which gate is leaking defects".'
---

# SDLC — Quality-Gap Report (Phase 6, output enrichment)

<!-- generated: yad-cli — from cli/skill-yad-cli.mjs by scripts/skill-yad-cli.mjs; do not edit by hand -->

**This skill needs the `yad` command.** Before its first `yad …` command, run `command -v yad` (in PowerShell, `(Get-Command yad -ErrorAction SilentlyContinue).Source`). When it prints nothing, the yadflow CLI is not installed on this machine: stop there, and tell the person:

- Install it with `npm install -g yadflow@latest`, or run each command as `npx -y yadflow@4 …` in place of `yad …`.
- It is needed because the CLI is what enforces the approvals. Without it, a step could only ask you to wait; it could not check that a person approved.

Go on only when that check prints a path, or when the person chooses `npx -y yadflow@4`. A command this skill already writes as `npx -y yadflow@4 …` runs without the install.

<!-- end: yad-cli -->

**Goal:** Turn the thread's defects into a **systemic quality signal**. Because every defect is a
first-class `defect`-type change-epic carrying an `escape_stage` (the gate that *should* have caught it)
and a `root_cause`, this report can show not just *what* broke but *where the SDLC let it through* — so
the team fixes the originating stage (weak test design, an under-specified story, a missed architecture
risk), not just the symptom. It is an **output enrichment**, exactly like `yad-docs` — **never a gate**.

## Conventions

- `{project-root}` resolves from the Product.
- Reuses the **`yad-docs` shell** verbatim (`../yad-docs/templates/app/`) — generated `src/data/*.ts`,
  themed; build-only / markdown-only (`yad docs deploy` does not build `defects-site/` yet).
- Per **epic** (one epic's defects) and per **thread** (the whole feature; the thread report lives under
  the genesis epic, since `thread == genesis id`). The thread is derived from `parent:` frontmatter.
- Deterministic generation, like `yad-docs` (stable sort, fixed key order, no timestamps in data).

## Inputs

- `epic` — scope to one epic's defects, OR `thread` — `EP-<genesis>` for the whole feature. Ask if
  neither is given; default to the thread.
- `action` — `generate` (default) | `deploy`.

## On Activation

### Step 1 — Collect the defects
Resolve the scope (`yad thread <id> --json` for a thread). Collect, across the scoped epic(s):
- every `defect` (and `hotfix`) type change-epic + its `.sdlc/change.json` `defect` block
  (`origin`, `severity`, `escape_stage`, `root_cause`);
- the shipped regression fixes from each epic's build ledger (the fix that closed the defect, linking
  the change-epic → its regression story/test);
- open reconcile debt (a hotfix whose Shape truth is not yet restored).

The build ledger is **shard-then-fold**: read it as the **union** of the folded `.sdlc/build-log.json`
`ships` PLUS every loose `.sdlc/build-log/` shard, deduped by `(story, task, repo)` — a shard WINS over a
folded ship of the same key. Reading `build-log.json` alone drops every ship not yet folded by
`yad tidy up` (including every `yad checkpoint --retro-ship` backfill, and every ship on a story still at
`in-build`, which `tidy up` never folds), which would under-count the very fixes this report attributes.

### Step 2 — Attribute each defect to the gate that should have caught it
A defect is attributed to its **earliest** responsible SDLC stage. Use `change.json.escape_stage`
(human-set at intake), cross-checked against the fix's shape: a missing negative test → `test-cases`; a
wrong/absent contract field → `architecture`; an unstated acceptance criterion → `stories`; a missed
market/requirement → `discovery`/`epic`. Record the attribution per defect.

### Step 3 — Aggregate the quality signal
Compute, for the scope:
- **defects per escape-stage** (count + **% of scope defects** — the headline "X% escaped at the
  `<stage>` gate");
- **defects per root_cause**;
- **severity mix** and **genesis→defect age** (how long after ship the defect surfaced);
- an **escape rate** per gate = defects attributed to a stage ÷ artifacts that passed that stage (a
  normalized "how leaky is this gate").

### Step 4 — Render the report (yad-docs shell)
Generate the site into `epics/<scope>/defects-site/` (themed as `yad-docs` does, then
`yad docs brand epics/<scope>/defects-site` when the Product has `.sdlc/brand.json`) with sections:
1. **Summary** — total defects, severity mix, escape rate.
2. **Escape-stage breakdown** — the bar/heat view of where defects leak (the actionable headline).
3. **Root-cause breakdown.**
4. **Per-defect detail** — each defect linked to its change-epic and its regression test.
5. **Severity & age.**
6. **Recommendations** — which originating stage to harden, derived from the top escape-stages.

Also write a plain `epics/<scope>/DEFECTS.md` mirror. On `action: deploy`, note that
`yad docs deploy` does not build this folder yet (it builds only the epic `docs-site/` and the overview) — build it with `npm ci` (or `npm install` when it has no lockfile) and `npm run build` inside the folder, and report it as build-only; a failed npm build is reported as a failure, never as a deploy.

## Hard rules

- **Never a gate.** No writes to `state.json`, `approvals.json`, or any `contract-lock.json`. It reads
  defect data and renders it.
- **Attribute honestly.** Use the recorded `escape_stage`; when it is absent or contradicted by the fix,
  cross-check and say so — do not invent an attribution.
- **Derived + deterministic.** Re-running on unchanged data yields byte-identical output.
- **Degrade gracefully.** No docs target → `DEFECTS.md` only; never fail because a tool is absent.

## Reference
- The defect data: `.sdlc/change.json` `defect` blocks + the build ledger, read as the folded
  `build-log.json` unioned with every `.sdlc/build-log/` shard
  (`../yad-epic/references/state-schema.md`, Phase 6; `../yad-engineer-review/references/ship-and-record.md`).
- The shell + deterministic generation it reuses: `../yad-docs/SKILL.md`, `../yad-docs/references/data-mapping.md`.
- The companion evolution view: `../yad-timeline/SKILL.md`.
- The intake that records `escape_stage` + `root_cause`: `../yad-change/SKILL.md`.
