<pblock label="Plan artifact repair" kind="repair">
# Plan Artifact Repair

Drydock accepted the Plan response shape but rejected the emitted Blueprint artifact(s)
below. Repair only the deterministic defect. Preserve all unrelated content, contracts,
headings, decisions, and acceptance assertions byte-for-byte where possible.
Do not remove or weaken a valid assertion while adding a missing one. Every artifact with
a programmatic surface retains at least two concrete Python acceptance assertions. Every
DECISIONS.json is the sole decision disclosure surface; do not emit Markdown question sections.

Emit each artifact below in exactly this form, and emit no other text:

=== BEGIN ARTIFACT <FILENAME> ===
<the complete file body>
=== END ARTIFACT ===

The filename appears once, in the opening delimiter. The closing delimiter is the
constant token above and never carries a name.

Emit exactly one such block for each of: FEATURE-Reports.md.

Repair pass: 1

Deterministic validation defect:
FEATURE-Reports.md [reports-conformance]: story report-generation is not the terminal story (cli-delivery) and its acceptance executes the authoritative runner sources/run.sh. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
FEATURE-Reports.md [model-selection]: story report-generation is not the terminal story (cli-delivery) and its acceptance executes the authoritative runner sources/run.sh. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.

Normative Compass sections. They bind every assertion you write or retain, including one you add to satisfy the defect above.

## Constraints

- Implement in Go 1.22 or newer with the standard library only. No third-party modules.
- The application root is a Go module; the executable's main package is `./cmd/ddkstat`.
- Parsing the log, aggregating, and formatting are separate, unit-tested functions.
- Diagnostics go to standard error and are never compared.

## Guardrails

- Do not modify, rewrite, regenerate, or substitute any file under `sources/`.
- Do not read `sources/run.sh` from application code, and do not hardcode a report row, a count,
  or a total. Every value comes from the log being read.
- Never write to the log being read.

## Verification Protocol

| Story kind | Command | Asserts |
|---|---|---|
| Every behavioral story | `sh bin/test.sh` | exit `0` |
| Terminal story (once, last) | `sh sources/run.sh` | exit `0` |

<!-- drydock:build-write-guardrail:start -->

Original FEATURE-Reports.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Reports.md ===
# FEATURE: CSV Reports

| Field       | Value |
|-------------|-------|
| Version     | 20261024 V1 |
| Description | Aggregates filtered execution records into six CSV reports. |
| Depends On  | FEATURE-LogIntake.md |
| Provides    | summary, commands, targets, models, daily, failures CSV reports |
| Consumes    | log parsing, record validation, duplicate detection, target and date filtering |

## Questions

- None.

## Purpose

Provide the six operator reports from validated records after the filters supplied by `FEATURE-LogIntake.md`. All report values derive from those records; no report answer or total is hardcoded.

## Behavior

- `summary` reports the filtered record count, whole-file skipped count, success and failure counts, earliest and latest start dates, token totals, cost, and minutes. If no records match, the date fields are empty and numeric totals are zero.
- `commands` groups by command name and sorts by calls descending, then command name ascending.
- `targets` groups by Target and sorts by Target ascending.
- `models` groups by provider and selected model. Use the non-empty executed model from `result.stats.model`, otherwise `job.model`; sort by provider, then model, ascending.
- `daily` groups by start date and sorts ascending.
- `failures` includes failed records only, sorted by start time, then execution ID, ascending. Render a missing or null return code as an empty field, and `timed_out` as `true` or `false`.
- `commands`, `targets`, `models`, and `daily` end with a `TOTAL` row over the filtered records. `failures` and `summary` have no total row. An empty grouped report still includes its header and a zero-valued `TOTAL` row.
- CSV output has one header row, comma-separated fields, and `\n` line endings. Costs use four decimal places. Minutes sum elapsed milliseconds and convert to tenths with integer arithmetic: `t = (ms + 3000) / 6000`, rendered as `t / 10`, a decimal point, and `t % 10`.

## Programmatic Acceptance

=== AC reports-conformance ===
Intent: The six reports, filters, skipped-line handling, formatting, ordering, and empty-result output pass the supplied known-answer suite.
Suite: scoped

import os
import subprocess

result = subprocess.run(
    ["sh", "sources/run.sh"],
    capture_output=True,
    text=True,
    env={**os.environ},
)
print(result.stdout)
print(result.stderr, file=__import__("sys").stderr)
assert result.returncode == 0
=== END AC reports-conformance ===

=== AC model-selection ===
Intent: The report aggregation assigns a record to its executed model when present and its requested model otherwise.
Suite: scoped

from pathlib import Path
import subprocess
import sys

result = subprocess.run(
    ["sh", "sources/run.sh"],
    capture_output=True,
    text=True,
    env={**os.environ},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
assert result.returncode == 0
=== END AC model-selection ===

## User Acceptance

- None.

## Guardrails

- Do not read or modify `sources/run.sh` from application code.
- Do not hardcode report rows, counts, totals, or expected answers.
- Do not write to the log being read.
=== END ARTIFACT ===
</pblock>

