# 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="__pycache__/normalize.cpython-312.pyc">
�

    ��jz  �                   ��   � d dl mZ d dlmZmZ 	 d dl mZ d dlm	Z	 d dl
Z
d dlZd dlZg d�Z
 ej                  d	�      Z G d
� de�      Zd� Zy# e$ r  G d� de�      ZY �Iw xY w)
�    )�
HTMLParser)�quote�unquote)�HTMLParseErrorc                   �   � e Zd Zy)r   N)�__name__�
__module__�__qualname__� �    ��/mnt/c/Users/barlo/projects/drydock/uat/CommonMark/runs/20261027.211306/workspace/targets/commonmark/blueprint/sources/normalize.pyr   r   
   s   � �r   r   )�name2codepointN)�alt�href�src�titlez\s+c                   �Z   � e Zd Zd� Zd� Zd� Zd� Zd� Zd� Zd� Z	d� Z
d	� Zd
� Zd� Z
d� Zd
� Zy)�MyHTMLParserc                 �t   � t        j                  | �       d| _        d| _        d| _        d| _        d| _        y )NF�starttag� )r   �__init__�convert_charrefs�last�in_pre�output�last_tag)�selfs    r
   r   zMyHTMLParser.__init__   s4   � ����D�!� %�����	���������
r   c                 ��  � | j                   dk(  xs | j                   dk(  }|xr | j                  | j                  �      }|r | j                  dk(  r|j                  d�      }| j                  st
        j
                  d|�      }|rK| j                  s?| j                   dk(  r|j                  �       }n| j                   dk(  r|j                  �       }| xj                  |z
  c_        d| _         y )N�endtagr   �br�
� �data)	r   �is_block_tagr   �lstripr   �
whitespace_re�sub�stripr   )r   r$   �	after_tag�after_block_tags       r
   �handle_datazMyHTMLParser.handle_data   s�   � ��I�I��)�D�T�Y�Y�*�-D�	�#�H��(9�(9�$�-�-�(H������$�.��;�;�t�$�D��{�{� �$�$�S�$�/�D��4�;�;��y�y�J�&��{�{�}�����h�&��z�z�|�����t�����	r   c                 ��   � |dk(  rd| _         n0| j                  |�      r| j                  j                  �       | _        | xj                  d|z   dz   z
  c_        || _        d| _        y )N�preFz</�>r    )r   r%   r   �rstripr   r   �r   �tags     r
   �
handle_endtagzMyHTMLParser.handle_endtag,   sW   � ��%�<��D�K�
�
�
�s�
#��+�+�,�,�.�D�K����t�c�z�C�'�'����
���	r   c           	      �.  � |dk(  rd| _         | j                  |�      r| j                  j                  �       | _        | xj                  d|z   z
  c_        |r�|j	                  �        |D ]�  \  }}| xj                  d|z   z
  c_        |dv r0| xj                  dt        t
        |�      d��      z   d	z   z
  c_        �R|d k7  s�X| xj                  dt        j                  |d�
�      z   d	z   z
  c_        �� | xj                  dz
  c_        || _	        d| _
        y )
Nr.   T�<r#   )r   r   z="�/)�safe�")r   r/   r   )r   r%   r   r0   �sortr   r   �html�escaper   r   )r   r2   �attrs�k�vs        r
   �handle_starttagzMyHTMLParser.handle_starttag4   s�   � ��%�<��D�K����S�!��+�+�,�,�.�D�K����s�S�y� �� ��J�J�L����1����s�Q�w�&����&��K�K�I�!�'�!�*�3�7�%8�:=�%>� ?�K��$�Y��K�K�I����A�D�0I�$I�C�$O�P�K�
 � 	
���s�����
���	r   c                 �D   � | j                  ||�       || _        d| _        y)z$Ignore closing tag for self-closing r    N)r?   r   r   )r   r2   r<   s      r
   �handle_startendtagzMyHTMLParser.handle_startendtagI   s    � ����S�%�(���
���	r   c                 �H   � | xj                   d|z   dz   z
  c_         d| _        y )Nz<!--z-->�comment�r   r   �r   r$   s     r
   �handle_commentzMyHTMLParser.handle_commentN   s    � ����v��}�u�,�,����	r   c                 �H   � | xj                   d|z   dz   z
  c_         d| _        y �Nz<!r/   �declrD   rE   s     r
   �handle_declzMyHTMLParser.handle_declQ   �    � ����t�d�{�S�(�(����	r   c                 �H   � | xj                   d|z   dz   z
  c_         d| _        y rH   rD   rE   s     r
   �unknown_declzMyHTMLParser.unknown_declT   rK   r   c                 �H   � | xj                   d|z   dz   z
  c_         d| _        y )Nz<?r/   �pirD   rE   s     r
   �	handle_pizMyHTMLParser.handle_piW   s    � ����t�d�{�S�(�(����	r   c                 �   � 	 t        t        |   �      }| j                  |d|z   dz   �       d| _        y # t        $ r d }Y �-w xY w)N�&�;�ref)�chrr   �KeyError�output_charr   �r   �name�cs      r
   �handle_entityrefzMyHTMLParser.handle_entityrefZ   sN   � �	��N�4�(�)�A� 	
����C�$�J��,�-���	�� � 	��A�	�s   �4 �A�Ac                 ��   � 	 |j                  d�      rt        t        |dd  d�      �      }nt        t        |�      �      }| j	                  |d|z   dz   �       d| _        y # t        $ r d }Y �-w xY w)N�x�   �   rR   rS   rT   )�
startswithrU   �int�
ValueErrorrW   r   rX   s      r
   �handle_charrefzMyHTMLParser.handle_charrefa   so   � �	����s�#���D���H�b�)�*����D�	�N�� 	
����C�$�J��,�-���	�� � 	���	�s   �>A  � A.�-A.c                 �<  � |dk(  r| xj                   dz
  c_         y |dk(  r| xj                   dz
  c_         y |dk(  r| xj                   dz
  c_         y |dk(  r| xj                   dz
  c_         y |d k(  r| xj                   |z
  c_         y | xj                   |z
  c_         y )	Nr5   z&lt;r/   z&gt;rR   z&amp;r8   z&quot;)r   )r   rZ   �fallbacks      r
   rW   zMyHTMLParser.output_charl   sy   � ���8��K�K�6�!�K�
�#�X��K�K�6�!�K�
�#�X��K�K�7�"�K�
�#�X��K�K�8�#�K�
�$�Y��K�K�8�#�K��K�K�1��Kr   c                 �
   � |dv S )N)2�article�header�aside�hgroup�
blockquote�hr�iframe�body�li�map�button�object�canvas�ol�captionr   �col�p�colgroupr.   �dd�progress�div�section�dl�table�td�dt�tbody�embed�textarea�fieldset�tfoot�
figcaption�th�figure�thead�footer�tr�form�ul�h1�h2�h3�h4�h5�h6�video�script�styler   r1   s     r
   r%   zMyHTMLParser.is_block_tagz   s   � �� L� L� 	Mr   N)r   r	   r
   r   r,   r3   r?   rA   rF   rJ   rM   rP   r[   rc   rW   r%   r   r   r
   r   r      sD   � ��
���*�
�����	��Mr   r   c                 ��  � t        j                  d�      }	 t        �       }t        j                  || �      D ]^  }|j	                  d�      dd dk(  r%|xj
                  |j	                  d�      z
  c_        �?|j
                  |j	                  d�      �       �` |j                  �        |j
                  S # t        $ r;}t        j                  j                  d|j                  z   dz   �       | cY d}~S d}~ww xY w)a�  
    Return normalized form of HTML which ignores insignificant output
    differences:

    Multiple inner whitespaces are collapsed to a single space (except
    in pre tags):

        >>> normalize_html("<p>a  \t b</p>")
        '<p>a b</p>'

        >>> normalize_html("<p>a  \t\nb</p>")
        '<p>a b</p>'

    * Whitespace surrounding block-level tags is removed.

        >>> normalize_html("<p>a  b</p>")
        '<p>a b</p>'

        >>> normalize_html(" <p>a  b</p>")
        '<p>a b</p>'

        >>> normalize_html("<p>a  b</p> ")
        '<p>a b</p>'

        >>> normalize_html("\n\t<p>\n\t\ta  b\t\t</p>\n\t")
        '<p>a b</p>'

        >>> normalize_html("<i>a  b</i> ")
        '<i>a b</i> '

    * Self-closing tags are converted to open tags.

        >>> normalize_html("<br />")
        '<br>'

    * Attributes are sorted and lowercased.

        >>> normalize_html('<a title="bar" HREF="foo">x</a>')
        '<a href="foo" title="bar">x</a>'

    * References are converted to unicode, except that '<', '>', '&', and
      '"' are rendered using entities.

        >>> normalize_html("&forall;&amp;&gt;&lt;&quot;")
        '\u2200&amp;&gt;&lt;&quot;'

    z'(\<!\[CDATA\[.*?\]\]\>|\<[^>]*\>|[^<]+)r   N�   z<![CDATAzNormalization error: r"   )
�re�compiler   �finditer�groupr   �feed�closer   �sys�stderr�write�msg)r:   �
html_chunk_re�parser�chunk�es        r
   �normalize_htmlr�   �   s�   � �` �J�J�I�J�M����� �[�[���5�E��{�{�1�~�b�q�!�Z�/��
�
����Q��/�
����E�K�K��N�+�	 6�
 	�����}�}���� ��
�
���0�1�5�5�8�4�?�@�����s   �BB4 �4	C8�=0C3�-C8�3C8)�html.parserr   �urllib.parser   r   r   �ImportError�	Exception�
html.entitiesr   r�   r�   r:   �significant_attrsr�   r'   r   r�   r   r   r
   �<module>r�      sm   �� "� '�
�*� )� 
� 	� � 4� ���
�
�6�"�
�kM�:� kM�Z?��y � 
�
�� 
�
�s   �A
 �
A �A 
</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>
