# Attribute Stories to Source Requirements

You are the lineage attribution agent. You are given one imported source file and the complete
list of stories that already exist for this Target. Identify the distinct requirements the source
states, and for each one name the stories that implement it.

This is a matching task against a closed set. Every story you may name is listed in `<stories>`.
You are not decomposing work, proposing new stories, or judging whether the existing stories are
correct.

## Method

1. Read the source and identify each distinct requirement it states. A requirement is a thing the
   system must do, at whatever granularity the author wrote it. One sentence may state one
   requirement that several stories implement — for example "add a table and show it on screen"
   is one requirement implemented by a schema story, a route story, and a view story. Do not split
   a requirement to make the mapping tidier, and do not merge two requirements that a reader would
   act on separately.
2. Give each requirement a short kebab-case name that describes it. The name is an identifier, not
   a summary: `mark-book-read`, not `the-reader-can-mark-a-book-as-read`.
3. For each requirement, list every story that implements any part of it. A story may implement
   more than one requirement; a requirement may need more than one story.
4. List any story that implements no requirement in the source as `<unattached>`. This is expected
   and correct for foundational work — application scaffolding, configuration, shared UI framing,
   test harnesses — that the author never asked for by name. Do not force such a story onto an
   unrelated requirement.

## Rules

- Copy story ids byte-for-byte from `<stories>`, preserving underscores, hyphens, and case; never invent or normalize one.
- Every story appears in one or more requirement `stories` attributes, or once as `<unattached>`, never both.
- Quote the requirement text verbatim from the source in the tag body. Do not paraphrase it.
- Emit nothing but the tags below. No preamble, no commentary, no explanation.

## Output

```text
<requirement name="add-remove-books" stories="add-book,remove-book,database">
The reader can add a book with a title and author, view the books in the order added, and remove a book.
</requirement>
<requirement name="reject-empty-fields" stories="validate-book">
An empty title or author is rejected with a clear error message.
</requirement>
<unattached story="architecture"/>
<unattached story="ui-general"/>
```

# Attribution job

<source name="full_test.sh">
#!/bin/sh
# full_test.sh — scoring entry point. Do not filter, skip, or reinterpret.
#
# `drydock uat` runs `sh sources/full_test.sh` from the completed application root and takes its
# exit code and output as the score. The interface check is separate from the conformance run so
# that a missing or non-executable program and a genuine conformance failure are distinguishable
# in the evidence. The program path is the harness's only knowledge of the implementation
# language; the harness itself is language-neutral.
#
# The suite runs unfiltered: no --pattern, no --number, no selector of any kind. spec_tests.py
# exits with failed + errored, so exit 0 means the complete CommonMark 0.31.2 suite passed.
set -eu

if [ ! -x ./commonmark ]; then
    echo "error: no executable ./commonmark at the application root." >&2
    echo "The deliverable is an executable named commonmark that reads UTF-8 Markdown on stdin" >&2
    echo "and writes HTML to stdout." >&2
    exit 1
fi

# spec_tests.py imports cmark and normalize as siblings, so the staged directory has to be on the
# import path. The program is passed absolute because the runner spawns it from its own cwd.
PYTHONPATH="$PWD/sources${PYTHONPATH:+:$PYTHONPATH}"
export PYTHONPATH

set +e
output=$(python3 sources/spec_tests.py --program "$PWD/commonmark" --spec sources/spec.txt 2>&1)
status=$?
set -e

printf '%s\n' "$output"

# The runner exits with failed + errored, which a shell truncates modulo 256: exactly 256 or 512
# failures would exit 0 and read as a pass. The harness therefore confirms the tally rather than
# trusting the status alone, and reports a clean run only when both agree. This is the scoring
# instrument reading its own instrument; the acceptance check above it still asserts nothing but
# this script's exit code.
if [ "$status" -ne 0 ]; then
    exit 1
fi
if ! printf '%s\n' "$output" | grep -q '0 failed, 0 errored, 0 skipped'; then
    echo "error: conformance runner exited 0 but did not report a clean unfiltered suite." >&2
    exit 1
fi
</source>

<stories>
  <story id="foundation" implements="ARCHITECTURE.md">Establish the Python project and parser integration boundaries.</story>
  <story id="delivery" implements="FEATURE-Executable.md">Provide the standard-stream executable.</story>
  <story id="paragraphs" implements="FEATURE-Paragraphs.md">Form paragraphs and handle blank lines.</story>
  <story id="thematic-breaks" implements="FEATURE-ThematicBreaks.md">Recognize thematic breaks with block precedence.</story>
  <story id="indented-code" implements="FEATURE-IndentedCode.md">Parse indented code blocks.</story>
  <story id="atx-headings" implements="FEATURE-ATXHeadings.md">Parse ATX headings.</story>
  <story id="html-blocks" implements="FEATURE-HTMLBlocks.md">Parse raw HTML blocks.</story>
  <story id="fenced-code" implements="FEATURE-FencedCode.md">Parse fenced code blocks.</story>
  <story id="reference-definitions" implements="FEATURE-ReferenceDefinitions.md">Collect document-wide link reference definitions.</story>
  <story id="setext-headings" implements="FEATURE-SetextHeadings.md">Parse setext headings.</story>
  <story id="block-quotes" implements="FEATURE-BlockQuotes.md">Parse block quote containers.</story>
  <story id="lists" implements="FEATURE-Lists.md">Parse list items and lists.</story>
  <story id="inline-text" implements="FEATURE-InlineText.md">Parse escapes, character references, and text line breaks.</story>
  <story id="code-spans" implements="FEATURE-CodeSpans.md">Parse inline code spans.</story>
  <story id="emphasis" implements="FEATURE-Emphasis.md">Parse emphasis and strong emphasis.</story>
  <story id="autolinks" implements="FEATURE-Autolinks.md">Parse URI and email autolinks.</story>
  <story id="inline-html-breaks" implements="FEATURE-InlineHTMLBreaks.md">Parse raw inline HTML and hard line breaks.</story>
  <story id="links" implements="FEATURE-Links.md">Parse inline and reference links.</story>
  <story id="images" implements="FEATURE-Images.md">Parse inline and reference images.</story>
  <story id="conformance-integration" implements="FEATURE-ConformanceIntegration.md">Exercise all scoped CommonMark examples against the integrated parser.</story>
  <story id="verification" implements="VERIFICATION.md">Verify the complete supplied conformance suite.</story>
</stories>
