# Materialize a diagnostic workspace

Create a bounded local workspace:

```bash
cofactor external-run debug materialize <run-id>
```

The default downloads run logs plus first-failure screenshots and DOM evidence
for failed/flaky scenarios. Video is excluded by default because it is large:

```text
--include-video
--artifacts none|failures|all
--out <directory>
```

The output directory must be new or empty; the command refuses to overwrite an
existing workspace.

Narrow the workspace when one scenario or one area is under investigation:

```bash
cofactor external-run debug materialize <run-id> --item <item-id-or-text>
cofactor external-run debug materialize <run-id> --area <label|index>
```

Every selected scenario with a Playwright trace gets a full diagnostic
workspace under `traces/<scenario>/`: `timeline/test-steps.jsonl` (the test's step
tree with times, source locations and the failing step's error),
`browser/actions.jsonl` with a DOM, screenshot and accessibility snapshot after
each call, `browser/error-context.md` (Playwright's page snapshot at the failure),
`logs/test-output.jsonl` (stdout/stderr), `source/`, and the raw `browser/trace.zip`.

For one test's trace alone:

```bash
cofactor external-run trace <run-id> --item <item-id-or-text> [--out <dir>]
```

Only retried attempts are traced unless the suite records every attempt, so a
test that failed without retrying has no trace; work from its error, steps,
logs and video.

The workspace contains `summary.md`, `manifest.json`, JSONL result rows, folded
scenarios, skip explanations, lifecycle telemetry, scenario histories,
diagnostics, and an artifact manifest. Downloads are best-effort: a retained row
whose artifact has expired is recorded as unavailable instead of aborting the
whole materialization.

A scenario whose test reported its own stdout, stderr, or a text attachment
(tags and source location included) gets `output/<scenario>.txt` — Playwright's
primary-source capture of what the test itself printed, distinct from the
container's `run.log` under `logs/`.
