You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@magpie.apache.org by po...@apache.org on 2026/10/18 16:07:57 UTC
(magpie) 02/08: feat(body-field-contract): a normative body-field parser contract with a shared conformance suite
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch feat/body-field-contract
in repository https://gitbox.apache.org/repos/asf/magpie.git
commit fd1b0fac119fd5aa1aba95d7de41fcd62b9aee4a
Author: Jarek Potiuk <po...@apache.org>
AuthorDate: Sun Oct 18 14:54:37 2026 +0200
feat(body-field-contract): a normative body-field parser contract with a shared conformance suite
How a tracker body's `### <Name>` fields are found was stated only in
prose spread over the GitHub tool's README, the issue-template doc and
the parser's docstring, so a second implementation (another language, a
local parser for a custom report format) had nothing to check itself
against.
tools/body-field-contract/ states the rules once, language-neutral, in
RFC 2119 terms, each with a `BF-*` identifier: line endings, field
boundaries (every column-0 `###` line ends a field, code block or not),
names, closed code blocks, which copy of a heading is the field (the one
outside every closed block; a field quoted only inside closed blocks is
absent), the container-heading and mid-line Jira macro
(`macro-ambiguous`) decisions, the four operations with their inputs,
outputs and errors, and what a writer of untrusted text must escape
(escape text, escape body).
conformance/cases.jsonl holds 98 cases, each naming the clause it tests;
a test checks every clause has one and every case names a real clause.
tools/github-body-field/tests/test_conformance.py runs every case
against the reference parser, the vetted-ops copy, the local-files
tracker and the Jira bridge (reads and writes through their own entry
points, lenient name lookup opting out of the exact-name cases), and the
writer cases against the local-files tracker, the Jira bridge and the
import's inert block. The byte-identical copy pins stay; the copies are
re-synced for the parser docstring's new pointer.
The taxonomy gains `contract:body-field` (validator capability set,
labels doc, generated labeler config and vendor-neutrality score), the
implementing tools declare it, and the issue-template doc, READMEs and
specs point at the contract.
Part of #1672
Generated-by: Claude Opus 5
---
.github/labeler.yml | 9 +
docs/labels-and-capabilities.md | 8 +-
docs/vendor-neutrality.md | 3 +-
plugins/magpie-vetted-ops/tools/jira/README.md | 4 +-
.../jira/src/jira_bridge/body_field_format.py | 2 +-
.../tools/local-tracker/README.md | 4 +-
.../src/magpie_local_tracker/body_field_format.py | 2 +-
.../vetted-ops/src/vetted_ops/body_field_format.py | 2 +-
tools/body-field-contract/README.md | 40 ++++
tools/body-field-contract/conformance/cases.jsonl | 98 +++++++++
tools/body-field-contract/contract.md | 157 ++++++++++++++
tools/github-body-field/README.md | 4 +-
.../src/github_body_field/parser.py | 2 +-
tools/github-body-field/tests/test_conformance.py | 233 +++++++++++++++++++++
tools/github/issue-template.md | 18 +-
tools/jira/README.md | 4 +-
tools/jira/src/jira_bridge/body_field_format.py | 2 +-
tools/local-tracker/README.md | 4 +-
.../src/magpie_local_tracker/body_field_format.py | 2 +-
.../src/skill_and_tool_validator/__init__.py | 1 +
tools/spec-loop/specs/adapters.md | 4 +-
tools/spec-loop/specs/security-issue-lifecycle.md | 6 +-
.../src/vendor_neutrality_score/__init__.py | 1 +
.../vetted-ops/src/vetted_ops/body_field_format.py | 2 +-
24 files changed, 579 insertions(+), 33 deletions(-)
diff --git a/.github/labeler.yml b/.github/labeler.yml
index 2dce2bcb..a8fc3a09 100644
--- a/.github/labeler.yml
+++ b/.github/labeler.yml
@@ -418,6 +418,15 @@ family:utilities:
- 'tools/skill-evals/evals/skill-reconciler/**'
- 'tools/skill-evals/evals/write-skill/**'
+contract:body-field:
+ - any:
+ - changed-files:
+ - any-glob-to-any-file:
+ - 'tools/body-field-contract/**'
+ - 'tools/github-body-field/**'
+ - 'tools/jira/**'
+ - 'tools/local-tracker/**'
+
contract:change-request:
- any:
- changed-files:
diff --git a/docs/labels-and-capabilities.md b/docs/labels-and-capabilities.md
index 9560221b..493af9d2 100644
--- a/docs/labels-and-capabilities.md
+++ b/docs/labels-and-capabilities.md
@@ -145,6 +145,7 @@ framework substrate:
| `contract:typed-decision` | contract | Provider-agnostic typed decision backend (Choice / Score / Noul). |
| `contract:people` | contract | Forge / tracker accounts: profile lookup, repository collaborators, team membership (one confirmed write). Distinct from `contract:project-metadata`, which reads an organization's governance rosters. |
| `contract:security-tracker` | contract | Where the security skills keep embargoed reports: body fields, status rollup, attachments, a confidentiality guard, and a publish step for working-copy backends (GitHub, local files, private Jira). |
+| `contract:body-field` | contract | How the `### <Name>` fields of a tracker issue body are found, read and rewritten: field boundaries, closed code blocks, the refusals, and a language-neutral conformance suite every implementation passes. |
| `substrate:analytics` | substrate | Read-only metrics / dashboards / renderers. |
| `substrate:sandbox` | substrate | Agent isolation, egress control, settings audit. |
| `substrate:action-guard` | substrate | Deterministic pre-tool-use command guards. |
@@ -336,10 +337,10 @@ or a contract-free mix of substrates (e.g. `tools/spec-inventory` is
| [`tools/fossil`](../tools/fossil/) | `contract:tracker` + `contract:source-control` | Fossil SCM forge bridge: integrates local SQLite-backed ticket tracking, wiki, and forum reads with the version-control shim |
| [`tools/github`](../tools/github/) | `contract:tracker` + `contract:source-control` + `contract:change-request` + `contract:people` | GitHub REST / GraphQL tracker substrate (called by every lifecycle phase) plus the Git source-control binding documented in [`source-control.md`](../tools/github/source-control.md) (runnable backend in [`tools/vcs`](../tools/vcs/)), the pull-request review/merge gate (`change-request`; the ASF default backend, alongside `tools/jira-patch/` and `tools/mai [...]
| [`tools/gitlab`](../tools/gitlab/) | `contract:tracker` + `contract:source-control` + `contract:change-request` | Coverage: `partial`. GitLab REST API v4 forge bridge foundation for repository metadata context under `contract:source-control`, issue listing/fetching under `contract:tracker`, and merge request discovery, diffs, commits, and CI pipeline status under `contract:change-request`. The `partial` qualifier means this tool implements named contract operations but does not satisfy [...]
-| [`tools/github-body-field`](../tools/github-body-field/) | `contract:tracker` | Read or rewrite one `### Field` section of a GitHub issue body without bringing the body into agent context — substrate helper for the security-sync skills |
+| [`tools/github-body-field`](../tools/github-body-field/) | `contract:tracker` + `contract:body-field` | Reference implementation of the body-field contract. Read or rewrite one `### Field` section of a GitHub issue body without bringing the body into agent context — substrate helper for the security-sync skills |
| [`tools/github-rollup`](../tools/github-rollup/) | `contract:tracker` | Append to (or create) the status-rollup comment on a GitHub issue without bringing the rollup body into agent context — substrate helper for every status-update-emitting skill |
| [`tools/gmail`](../tools/gmail/) | `contract:mail-source` + `contract:mail-create` + `contract:mail-archive` | Gmail API substrate — inbound report intake (`mail-source`), thread / archive reads (`mail-archive`), plus outbound courtesy-reply drafting (`mail-create`); read + draft only, never sends |
-| [`tools/jira`](../tools/jira/) | `contract:tracker` + `contract:people` + `contract:security-tracker` | JIRA REST substrate (general-tracker writes in the Groovy bridge, tracked in [#301](https://github.com/apache/magpie/issues/301)); the tracker's contributor-activity reads run in the `jira` backend of `tools/contributor-metrics`, and `people` provides profile lookup only (display name, existence). `magpie-jira-tracker` is the private-Jira security-tracker backend: `create` always set [...]
+| [`tools/jira`](../tools/jira/) | `contract:tracker` + `contract:people` + `contract:security-tracker` + `contract:body-field` | JIRA REST substrate (general-tracker writes in the Groovy bridge, tracked in [#301](https://github.com/apache/magpie/issues/301)); the tracker's contributor-activity reads run in the `jira` backend of `tools/contributor-metrics`, and `people` provides profile lookup only (display name, existence). `magpie-jira-tracker` is the private-Jira security-tracker back [...]
| [`tools/jira-patch`](../tools/jira-patch/) | `contract:change-request` | JIRA-patch change-request backend: patches attached to JIRA issues as the proposal, reviewed via JIRA comments, landed via `contract:source-control` (`svn patch` + `svn commit`). Composes `tools/jira/` (REST) + `tools/asf-svn/` (land). Implements the `tools/change-request/` contract |
| [`tools/chat`](../tools/chat/) | `contract:chat` | Adapter contract for project chat (Slack, Discord): public-channel reads for community signals. Pure interface spec. |
| [`tools/chat-slack`](../tools/chat-slack/) | `contract:chat` | Slack adapter for the `tools/chat/` contract, over the Slack MCP; public channels only, never posts. |
@@ -383,8 +384,9 @@ or a contract-free mix of substrates (e.g. `tools/spec-inventory` is
| [`tools/vcs`](../tools/vcs/) | `contract:source-control` | Backend-dispatching implementation of the source-control (VCS) capability ([`tools/github/source-control.md`](../tools/github/source-control.md)); complete Git, Mercurial (Hg), Fossil, and Subversion (SVN) backends |
| [`tools/sourcehut`](../tools/sourcehut/) | `contract:tracker` + `contract:source-control` + `contract:mail-archive` | SourceHut (sr.ht) forge bridge: todo.sr.ht, lists.sr.ht, builds.sr.ht, and git/hg repository reads |
| [`tools/tracker`](../tools/tracker/) | `contract:tracker` | Interface spec for the tracker contract's read-only contributor-activity queries (issues filed, triaged and commented on; issues created; first maintainer reply). Pure interface spec; GitHub and Jira implement it, and the rest of the contract is described by `tools/github/tool.md` |
+| [`tools/body-field-contract`](../tools/body-field-contract/) | `contract:body-field` | The body-field contract: how every reader and writer finds a tracker body's `### <Name>` fields, with a language-neutral conformance suite run against every implementation. Pure interface spec; implementations: `tools/github-body-field/` (reference), `tools/vetted-ops/`, `tools/local-tracker/`, `tools/jira/` |
| [`tools/security-tracker`](../tools/security-tracker/) | `contract:security-tracker` | Adapter contract for the security tracker the `security-*` skills read and write, selected by `tracker.platform`. Pure interface spec; backends: `tools/github/` (default), `tools/local-tracker/`, `tools/jira/` |
-| [`tools/local-tracker`](../tools/local-tracker/) | `contract:security-tracker` | Security tracker as Markdown files in a private Git or SVN working copy; learns an existing report layout, refuses writes until access is human-confirmed, and commits and pushes on confirmation |
+| [`tools/local-tracker`](../tools/local-tracker/) | `contract:security-tracker` + `contract:body-field` | Security tracker as Markdown files in a private Git or SVN working copy; learns an existing report layout, refuses writes until access is human-confirmed, and commits and pushes on confirmation |
| [`tools/typed-decision`](../tools/typed-decision/) | `contract:typed-decision` | Provider-agnostic typed decision tool contract (Choice / Score / Noul) with TypeSafe Jev API as initial backend |
A tool's capability is the **interface it provides**, not which skills
diff --git a/docs/vendor-neutrality.md b/docs/vendor-neutrality.md
index 528d07c6..0191bf48 100644
--- a/docs/vendor-neutrality.md
+++ b/docs/vendor-neutrality.md
@@ -581,7 +581,7 @@ generated block below.
<!-- BEGIN vendor-neutrality-score — generated by `uv run --project tools/vendor-neutrality-score vendor-neutrality-score --markdown`; do not edit by hand -->
-**Overall vendor-neutrality score: 15/16 capability contracts (94%).** Generated by [`tools/vendor-neutrality-score`](../tools/vendor-neutrality-score/); re-run it to refresh this section.
+**Overall vendor-neutrality score: 16/17 capability contracts (94%).** Generated by [`tools/vendor-neutrality-score`](../tools/vendor-neutrality-score/); re-run it to refresh this section.
| Capability contract | Neutral? | Class | Backends today | Basis |
|---|---|---|---|---|
@@ -601,6 +601,7 @@ generated block below.
| `contract:typed-decision` | ✅ | vendor-backed | TypeSafe, self-hosted OpenAI-compatible | 2 backend vendors: TypeSafe, self-hosted OpenAI-compatible |
| `contract:people` | ✅ | vendor-backed | Atlassian, GitHub | 2 backend vendors: Atlassian, GitHub |
| `contract:security-tracker` | ✅ | vendor-backed | Atlassian, agnostic | 2 backend vendors: Atlassian, agnostic |
+| `contract:body-field` | ✅ | agnostic | Atlassian, GitHub, agnostic | vendor-neutral by construction — one spec serves every backend |
**Per-skill assessment: 80/80 skills carry no vendor lock-in.** A skill is *capability-pure* when it names no backend at all, *portable* when every backend it names has an alternative (its contract is green), and *vendor-coupled* only when it reaches for a backend that is the sole implementation of a capability.
diff --git a/plugins/magpie-vetted-ops/tools/jira/README.md b/plugins/magpie-vetted-ops/tools/jira/README.md
index b38abcfd..9877daa2 100644
--- a/plugins/magpie-vetted-ops/tools/jira/README.md
+++ b/plugins/magpie-vetted-ops/tools/jira/README.md
@@ -35,7 +35,7 @@
# JIRA bridge
-**Capability:** contract:tracker + contract:people + contract:security-tracker
+**Capability:** contract:tracker + contract:people + contract:security-tracker + contract:body-field
**Kind:** implementation
@@ -316,7 +316,7 @@ Under vetted-ops the URL, project and level are pinned by the policy's `[tracker
| `pending` / `publish` | No-ops: Jira writes are immediate. |
| `doctor` | URL, project, confirmed token, configured level, `/myself`, project reachability, and whether the level exists (403/404 on the listing reports *unverified*). |
-**Storage.** Body fields are `h3. <Heading>` wiki-markup sections of the description (markdown `###` sections are read too), read and written through a byte-identical copy of [`github-body-field`](https://github.com/apache/magpie/blob/main/tools/github-body-field/README.md)'s parser (`body_field_format.py`, kept exact by a test), so they follow the [body-field contract](https://github.com/apache/magpie/blob/main/tools/github/issue-template.md):
+**Storage.** Body fields are `h3. <Heading>` wiki-markup sections of the description (markdown `###` sections are read too), read and written through a byte-identical copy of [`github-body-field`](https://github.com/apache/magpie/blob/main/tools/github-body-field/README.md)'s parser (`body_field_format.py`, kept exact by a test), so they follow the [body-field contract](https://github.com/apache/magpie/blob/main/tools/body-field-contract/contract.md):
every column-0 `###` line ends a field, code block or not, a heading inside a closed code block is never a field, and a `{code}` / `{noformat}` macro opened mid-line before field headings is refused as ambiguous.
A wiki heading of level 1 to 3 outside closed blocks reads as `### <Heading>`; closed blocks are CommonMark fence pairs and `{code}` / `{code:…}` / `{noformat}` blocks opened at the start of a line and closed on the bare macro, and a block left open marks nothing.
`create` and `edit` escape every `###` line inside a closed block with a leading `\`, so quoted text never becomes a field copy. Names match with case and inner whitespace ignored; `field-get` and `field-set` exit `4` on a duplicate or disputed field, and `field-set` on a value that would add, hide or move a field heading.
diff --git a/plugins/magpie-vetted-ops/tools/jira/src/jira_bridge/body_field_format.py b/plugins/magpie-vetted-ops/tools/jira/src/jira_bridge/body_field_format.py
index 4e6e37b6..e10b42f5 100644
--- a/plugins/magpie-vetted-ops/tools/jira/src/jira_bridge/body_field_format.py
+++ b/plugins/magpie-vetted-ops/tools/jira/src/jira_bridge/body_field_format.py
@@ -21,7 +21,7 @@ each followed by the field's value. This module exposes a pure
parser/replacer so the CLI can run without ever bringing the body
into the agent's context, and so the (numerous) tricky edge cases
can be unit-tested in isolation. It is the one implementation of the
-body-field contract (tools/github/issue-template.md): every reader and
+body-field contract (tools/body-field-contract/contract.md): every reader and
writer of a field, generate-cve-json included, goes through it.
The contract:
diff --git a/plugins/magpie-vetted-ops/tools/local-tracker/README.md b/plugins/magpie-vetted-ops/tools/local-tracker/README.md
index fef07310..e0f76fde 100644
--- a/plugins/magpie-vetted-ops/tools/local-tracker/README.md
+++ b/plugins/magpie-vetted-ops/tools/local-tracker/README.md
@@ -20,7 +20,7 @@
# Local file tracker
-**Capability:** contract:security-tracker
+**Capability:** contract:security-tracker + contract:body-field
**Kind:** implementation
@@ -78,7 +78,7 @@ It records:
| `title_source` | `key`, or `h1` when the title is the report's first `# ` heading. |
| `id` | `prefix`, zero-pad `width`, and `slug` when names carry a title slug (`2024-007-xss-in-login`). |
| `state` | `mode: field` (a metadata value) or `mode: directory` (a sub-folder per state, such as `open/` and `closed/`), and the values or folder names that count as open and closed. |
-| `field_heading_level` | The heading level of body fields (`###` by default). At `###` the [body-field contract](https://github.com/apache/magpie/blob/main/tools/github/issue-template.md) applies: every column-0 `###` line ends a field, code block or not, a heading inside a closed code block is never a field, a duplicate or disputed field is refused (exit `4`), and a field value has every line that would end a field escaped with a leading `\`; a whole report (`create`, `edit`) has every [...]
+| `field_heading_level` | The heading level of body fields (`###` by default). At `###` the [body-field contract](https://github.com/apache/magpie/blob/main/tools/body-field-contract/contract.md) applies: every column-0 `###` line ends a field, code block or not, a heading inside a closed code block is never a field, a duplicate or disputed field is refused (exit `4`), and a field value has every line that would end a field escaped with a leading `\`; a whole report (`create`, `edit`) ha [...]
| `comments_mode`, `rollup_mode` | `file` (beside the report) or `section` (a `## ` heading at the end of the report). |
| `url_template` | Optional private browse URL, for example a ViewVC or gitweb address. Without it, the `url` field is the path relative to the working copy. |
| `access_restricted` | The human-confirmed access check that unlocks writes. |
diff --git a/plugins/magpie-vetted-ops/tools/local-tracker/src/magpie_local_tracker/body_field_format.py b/plugins/magpie-vetted-ops/tools/local-tracker/src/magpie_local_tracker/body_field_format.py
index 4e6e37b6..e10b42f5 100644
--- a/plugins/magpie-vetted-ops/tools/local-tracker/src/magpie_local_tracker/body_field_format.py
+++ b/plugins/magpie-vetted-ops/tools/local-tracker/src/magpie_local_tracker/body_field_format.py
@@ -21,7 +21,7 @@ each followed by the field's value. This module exposes a pure
parser/replacer so the CLI can run without ever bringing the body
into the agent's context, and so the (numerous) tricky edge cases
can be unit-tested in isolation. It is the one implementation of the
-body-field contract (tools/github/issue-template.md): every reader and
+body-field contract (tools/body-field-contract/contract.md): every reader and
writer of a field, generate-cve-json included, goes through it.
The contract:
diff --git a/plugins/magpie-vetted-ops/tools/vetted-ops/src/vetted_ops/body_field_format.py b/plugins/magpie-vetted-ops/tools/vetted-ops/src/vetted_ops/body_field_format.py
index 4e6e37b6..e10b42f5 100644
--- a/plugins/magpie-vetted-ops/tools/vetted-ops/src/vetted_ops/body_field_format.py
+++ b/plugins/magpie-vetted-ops/tools/vetted-ops/src/vetted_ops/body_field_format.py
@@ -21,7 +21,7 @@ each followed by the field's value. This module exposes a pure
parser/replacer so the CLI can run without ever bringing the body
into the agent's context, and so the (numerous) tricky edge cases
can be unit-tested in isolation. It is the one implementation of the
-body-field contract (tools/github/issue-template.md): every reader and
+body-field contract (tools/body-field-contract/contract.md): every reader and
writer of a field, generate-cve-json included, goes through it.
The contract:
diff --git a/tools/body-field-contract/README.md b/tools/body-field-contract/README.md
new file mode 100644
index 00000000..ce06a6b3
--- /dev/null
+++ b/tools/body-field-contract/README.md
@@ -0,0 +1,40 @@
+<!-- START doctoc generated TOC please keep comment here to allow auto update -->
+<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
+**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
+
+- [`tools/body-field-contract/`](#toolsbody-field-contract)
+ - [Prerequisites](#prerequisites)
+
+<!-- END doctoc generated TOC please keep comment here to allow auto update -->
+
+<!-- SPDX-License-Identifier: Apache-2.0
+ https://www.apache.org/licenses/LICENSE-2.0 -->
+
+# `tools/body-field-contract/`
+
+**Capability:** contract:body-field
+
+**Kind:** interface
+
+**Vendor:** agnostic
+
+How every reader and writer finds the `### <Name>` fields of a tracker issue body, stated once and independent of language:
+what a field boundary is, which code blocks count, which heading is the field, what is ambiguous and must be refused,
+the four operations an implementation provides (list fields, extract, replace, normalise) with their refusals,
+and the two writer operations (escape text, escape body) that keep untrusted text from ever becoming a field.
+
+See [`contract.md`](contract.md) for the rules and [`conformance/cases.jsonl`](conformance/cases.jsonl) for the shared conformance cases,
+which `tools/github-body-field/tests/test_conformance.py` runs against every implementation in the repository.
+
+| Implementation | Language |
+|---|---|
+| [`tools/github-body-field/`](../github-body-field/README.md) | Python (reference) |
+| [`tools/vetted-ops/`](../vetted-ops/README.md) | Python (byte-identical copy) |
+| [`tools/local-tracker/`](../local-tracker/README.md) | Python (byte-identical copy; escape text and escape body) |
+| [`tools/jira/`](../jira/README.md) | Python (byte-identical copy, after mapping wiki headings; escape body) |
+| [`tools/security-management/`](../security-management/README.md) | Python (writer only: escape text, the import's inert block) |
+
+## Prerequisites
+
+- **Runtime:** None — this directory is a Markdown contract and JSON Lines fixtures; no executable code ships here.
+- **CLIs / credentials / network:** None. The conformance runner lives in `tools/github-body-field/tests/` and runs offline under its pytest.
diff --git a/tools/body-field-contract/conformance/cases.jsonl b/tools/body-field-contract/conformance/cases.jsonl
new file mode 100644
index 00000000..de972ef1
--- /dev/null
+++ b/tools/body-field-contract/conformance/cases.jsonl
@@ -0,0 +1,98 @@
+{"id": "crlf-extract", "clause": "BF-LINE-1", "op": "extract", "body": "### Severity\r\n\r\nLow\r\n", "args": {"name": "Severity"}, "tags": [], "expect": {"value": "Low\r\n"}}
+{"id": "lone-cr-lines", "clause": "BF-LINE-1", "op": "list_fields", "body": "### A\r\rone\r### B\rtwo", "args": {}, "tags": [], "expect": {"value": ["A", "B"]}}
+{"id": "u2028-is-not-a-line-end", "clause": "BF-LINE-2", "op": "list_fields", "body": "### A\n\nx\u2028### B\n", "args": {}, "tags": [], "expect": {"value": ["A"]}}
+{"id": "formfeed-is-not-a-line-end", "clause": "BF-LINE-2", "op": "extract", "body": "### A\n\nx\f### B\n", "args": {"name": "A"}, "tags": [], "expect": {"value": "x\f### B\n"}}
+{"id": "fenced-heading-ends-the-field", "clause": "BF-BOUND-2", "op": "extract", "body": "### A\n\n```\n### B\n```\n", "args": {"name": "A"}, "tags": [], "expect": {"value": "```\n"}}
+{"id": "not-boundaries", "clause": "BF-BOUND-3", "op": "list_fields", "body": "### A\n####B\n#### C\n###x\n ### D\n\t### E\n### F\n", "args": {}, "tags": [], "expect": {"value": ["A", "F"]}}
+{"id": "bare-hashes-end-a-field", "clause": "BF-BOUND-1", "op": "extract", "body": "### A\n\na\n###\nb\n", "args": {"name": "A"}, "tags": [], "expect": {"value": "a\n"}}
+{"id": "tab-after-hashes", "clause": "BF-BOUND-1", "op": "extract", "body": "###\tSeverity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"value": "Low\n"}}
+{"id": "two-space-heading", "clause": "BF-NAME-1", "op": "extract", "body": "### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"value": "Low\n"}}
+{"id": "closing-hashes", "clause": "BF-NAME-1", "op": "extract", "body": "### Severity ##\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"value": "Low\n"}}
+{"id": "hash-in-name-kept", "clause": "BF-NAME-1", "op": "list_fields", "body": "### C#\n\nx\n### Only ### \n\ny\n", "args": {}, "tags": [], "expect": {"value": ["C#", "Only"]}}
+{"id": "names-are-case-sensitive", "clause": "BF-NAME-2", "op": "extract", "body": "### severity\n\nLow\n", "args": {"name": "Severity"}, "tags": ["case-sensitive"], "expect": {"error": "not_found"}}
+{"id": "case-variants-are-different-fields", "clause": "BF-NAME-2", "op": "extract", "body": "### Severity\n\nLow\n\n### severity\n\nHigh\n", "args": {"name": "Severity"}, "tags": ["case-sensitive"], "expect": {"value": "Low\n"}}
+{"id": "inner-whitespace-is-exact", "clause": "BF-NAME-2", "op": "extract", "body": "### Short summary\n\nx\n", "args": {"name": "Short summary"}, "tags": ["inner-whitespace"], "expect": {"error": "not_found"}}
+{"id": "backtick-info-with-backtick-is-not-a-fence", "clause": "BF-BLOCK-1", "op": "extract", "body": "### A\n\n``` a`b\n### Severity\n```\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"error": "duplicate"}}
+{"id": "tilde-info-may-hold-backticks", "clause": "BF-BLOCK-1", "op": "extract", "body": "### A\n\n~~~ a`b\n### Severity\n~~~\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"value": "Low\n"}}
+{"id": "four-space-indent-is-not-a-fence", "clause": "BF-BLOCK-1", "op": "extract", "body": "### A\n\n ```\n### Severity\n ```\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"error": "duplicate"}}
+{"id": "three-space-indent-is-a-fence", "clause": "BF-BLOCK-1", "op": "extract", "body": "### A\n\n ```\n### Severity\n ```\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"value": "Low\n"}}
+{"id": "shorter-fence-does-not-close-a-longer", "clause": "BF-BLOCK-2", "op": "extract", "body": "### A\n\n````\n```\n### Severity\n```\n````\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"value": "Low\n"}}
+{"id": "longer-closer-closes", "clause": "BF-BLOCK-2", "op": "extract", "body": "### A\n\n```\n### Severity\n`````\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"value": "Low\n"}}
+{"id": "tildes-do-not-close-backticks", "clause": "BF-BLOCK-2", "op": "extract", "body": "### A\n\n```\n~~~\n### Severity\n```\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"value": "Low\n"}}
+{"id": "closer-must-be-bare", "clause": "BF-BLOCK-2", "op": "extract", "body": "### A\n\n```\n``` x\n### Severity\n```\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"value": "Low\n"}}
+{"id": "jira-code-block", "clause": "BF-BLOCK-3", "op": "extract", "body": "### A\n\n{code}\n### Severity\nCritical\n{code}\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"value": "Low\n"}}
+{"id": "jira-code-with-language", "clause": "BF-BLOCK-3", "op": "extract", "body": "### A\n\n{code:java}\n### Severity\n{code}\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"value": "Low\n"}}
+{"id": "jira-noformat", "clause": "BF-BLOCK-3", "op": "extract", "body": "### A\n\n {noformat}\n### Severity\n{noformat}\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"value": "Low\n"}}
+{"id": "jira-macro-mid-line-is-ambiguous", "clause": "BF-MACRO-1", "op": "extract", "body": "### A\n\nsee {code} here\n### Severity\nx\n{code}\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"error": "ambiguous"}}
+{"id": "jira-macro-closed-on-its-line-opens-nothing", "clause": "BF-BLOCK-3", "op": "extract", "body": "### A\n\n{code}x{code}\n### Severity\nx\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"error": "duplicate"}}
+{"id": "nothing-opens-inside-a-block", "clause": "BF-BLOCK-4", "op": "extract", "body": "### A\n\n```\n{code}\n```\n### Severity\nx\n{code}\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"error": "duplicate"}}
+{"id": "unclosed-fence-marks-nothing", "clause": "BF-BLOCK-5", "op": "extract", "body": "### A\n\n```\n### Severity\nfake\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"error": "duplicate"}}
+{"id": "unclosed-macro-marks-nothing", "clause": "BF-BLOCK-5", "op": "extract", "body": "### A\n\n{noformat}\n### Severity\n\nHigh\n", "args": {"name": "Severity"}, "tags": [], "expect": {"value": "High\n"}}
+{"id": "jira-macro-mid-line-hides-enclosing-field", "clause": "BF-MACRO-1", "op": "extract", "body": "### A\n\ntext {code}\n### Severity\nCritical\n{code}\n\n### CWE\n\nx\n", "args": {"name": "A"}, "tags": [], "expect": {"error": "ambiguous"}}
+{"id": "jira-macro-mid-line-other-field-readable", "clause": "BF-MACRO-1", "op": "extract", "body": "### A\n\ntext {code}\n### Severity\nCritical\n{code}\n\n### CWE\n\nx\n", "args": {"name": "CWE"}, "tags": [], "expect": {"value": "x\n"}}
+{"id": "jira-macro-mid-line-never-closed", "clause": "BF-MACRO-1", "op": "extract", "body": "### A\n\ntext {noformat}\n### Severity\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"value": "Low\n"}}
+{"id": "jira-macro-left-open-after-pairs", "clause": "BF-MACRO-1", "op": "extract", "body": "### A\n\n{code} a {code} b {code}\n### Severity\nLow\n{code}\n", "args": {"name": "Severity"}, "tags": [], "expect": {"error": "ambiguous"}}
+{"id": "normalise-macro-ambiguous", "clause": "BF-NORM-5", "op": "normalise", "body": "### A\n\ntext {code}\n### Severity\nCritical\n{code}\n\n### CWE\n\nx\n", "args": {"known_fields": ["Severity"]}, "tags": [], "expect": {"value": {"text": "### A\n\ntext {code}\n### Severity\nCritical\n{code}\n\n### CWE\n\nx\n", "changes": [], "needs_decision": [{"field": "Severity", "kind": "macro-ambiguous", "lines": [3, 4]}]}}}
+{"id": "replace-value-opens-macro-before-a-field", "clause": "BF-REP-5", "op": "replace", "body": "### A\n\na\n\n### B\n\nb\n\n### C\n\n{code}\n", "args": {"name": "A", "value": "see {code}"}, "tags": [], "expect": {"error": "ambiguous"}}
+{"id": "outside-copy-wins", "clause": "BF-SEL-1", "op": "extract", "body": "### A\n\n```\n### Severity\nCritical\n```\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"value": "Low\n"}}
+{"id": "in-block-copy-alone-is-absent", "clause": "BF-SEL-1", "op": "extract", "body": "### A\n\n```\n### Severity\nCritical\n```\n", "args": {"name": "Severity"}, "tags": [], "expect": {"error": "not_found"}}
+{"id": "in-block-copies-only-are-absent", "clause": "BF-SEL-1", "op": "extract", "body": "### A\n\n```\n### Severity\nOne\n```\n\n~~~\n### Severity\nTwo\n~~~\n", "args": {"name": "Severity"}, "tags": [], "expect": {"error": "not_found"}}
+{"id": "two-outside-copies-are-a-duplicate", "clause": "BF-SEL-2", "op": "extract", "body": "### Severity\n\nLow\n\n### Severity\n\nHigh\n", "args": {"name": "Severity"}, "tags": [], "expect": {"error": "duplicate"}}
+{"id": "identical-outside-copies-are-a-duplicate", "clause": "BF-SEL-2", "op": "extract", "body": "### Severity\n\nLow\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"error": "duplicate"}}
+{"id": "missing-field", "clause": "BF-EXT-1", "op": "extract", "body": "### A\n\na\n", "args": {"name": "Severity"}, "tags": [], "expect": {"error": "not_found"}}
+{"id": "spacer-lines", "clause": "BF-SEL-3", "op": "extract", "body": "### A\n\n\nx\n\n\n### B\n", "args": {"name": "A"}, "tags": [], "expect": {"value": "\nx\n\n"}}
+{"id": "empty-value", "clause": "BF-SEL-3", "op": "extract", "body": "### A\n\n### B\n\nb\n", "args": {"name": "A"}, "tags": [], "expect": {"value": ""}}
+{"id": "preamble-is-no-field", "clause": "BF-SEL-4", "op": "list_fields", "body": "intro\n\n### A\n\na\n", "args": {}, "tags": [], "expect": {"value": ["A"]}}
+{"id": "list-fields-skips-block-headings-keeps-repeats", "clause": "BF-SEL-4", "op": "list_fields", "body": "### A\n\n```\n### B\n```\n\n### A\n\n### C\n", "args": {}, "tags": [], "expect": {"value": ["A", "A", "C"]}}
+{"id": "private-merge-fenced", "clause": "BF-SEL-1", "op": "extract", "body": "### Summary\n\n```\nsee\n\n### Security mailing list thread\n\nprivate\n\n```\n", "args": {"name": "Summary"}, "tags": [], "expect": {"value": "```\nsee\n"}}
+{"id": "private-merge-spanning-fence", "clause": "BF-SEL-1", "op": "extract", "body": "### Summary\n\n```\n\n### Security mailing list thread\n\nprivate\n\n### CVE tool link\n\n```\n", "args": {"name": "Summary"}, "tags": [], "expect": {"value": "```\n"}}
+{"id": "private-merge-spanning-fence-thread", "clause": "BF-SEL-1", "op": "extract", "body": "### Summary\n\n```\n\n### Security mailing list thread\n\nprivate\n\n### CVE tool link\n\n```\n", "args": {"name": "Security mailing list thread"}, "tags": [], "expect": {"error": "not_found"}}
+{"id": "private-merge-jira-macro", "clause": "BF-SEL-1", "op": "extract", "body": "### Summary\n\n{code}\n\n### Security mailing list thread\n\nprivate\n", "args": {"name": "Summary"}, "tags": [], "expect": {"value": "{code}\n"}}
+{"id": "normalise-ignores-in-block-copies", "clause": "BF-NORM-4", "op": "normalise", "body": "### Severity\n\nLow\n\n```\n### Severity\nHigh\n```\n", "args": {"known_fields": ["Severity"]}, "tags": [], "expect": {"value": {"text": "### Severity\n\nLow\n\n```\n### Severity\nHigh\n```\n", "changes": [], "needs_decision": []}}}
+{"id": "private-merge-fake-heading-before", "clause": "BF-SEL-2", "op": "extract", "body": "### Summary\n\n### Security mailing list thread\n\nfake\n\n```\n### Security mailing list thread\n\nprivate\n```\n", "args": {"name": "Summary"}, "tags": [], "expect": {"value": ""}}
+{"id": "quoted-heading-is-disputed", "clause": "BF-CONT-1", "op": "extract", "body": "### A\n\n> ### Severity\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"error": "ambiguous"}}
+{"id": "list-heading-is-disputed", "clause": "BF-CONT-1", "op": "extract", "body": "### A\n\n- ### Severity\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"error": "ambiguous"}}
+{"id": "indented-heading-is-disputed", "clause": "BF-CONT-1", "op": "extract", "body": "### A\n\n ### Severity\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"error": "ambiguous"}}
+{"id": "container-heading-alone-is-disputed", "clause": "BF-CONT-1", "op": "extract", "body": "### A\n\n> ### Severity\n", "args": {"name": "Severity"}, "tags": [], "expect": {"error": "ambiguous"}}
+{"id": "container-heading-in-fence-is-content", "clause": "BF-CONT-1", "op": "extract", "body": "### A\n\n```\n> ### Severity\n```\n\n### Severity\n\nLow\n", "args": {"name": "Severity"}, "tags": [], "expect": {"value": "Low\n"}}
+{"id": "container-heading-for-another-field", "clause": "BF-CONT-1", "op": "extract", "body": "### A\n\n> ### Severity\n\n### CWE\n\nx\n", "args": {"name": "CWE"}, "tags": [], "expect": {"value": "x\n"}}
+{"id": "replace-basic", "clause": "BF-REP-1", "op": "replace", "body": "### A\n\none\n\n### B\n\ntwo\n", "args": {"name": "A", "value": "uno"}, "tags": [], "expect": {"value": "### A\n\nuno\n\n### B\n\ntwo\n"}}
+{"id": "replace-keeps-crlf", "clause": "BF-REP-1", "op": "replace", "body": "### A\r\n\r\none\r\n\r\n### B\r\n\r\ntwo\r\n", "args": {"name": "A", "value": "uno\n"}, "tags": [], "expect": {"value": "### A\r\n\r\nuno\r\n\r\n### B\r\n\r\ntwo\r\n"}}
+{"id": "replace-last-field", "clause": "BF-REP-1", "op": "replace", "body": "### A\n\none\n\n### B\n\ntwo\n", "args": {"name": "B", "value": "deux\n\n\n"}, "tags": [], "expect": {"value": "### A\n\none\n\n### B\n\ndeux\n"}}
+{"id": "replace-empty-value", "clause": "BF-REP-1", "op": "replace", "body": "### A\n\none\n\n### B\n\ntwo\n", "args": {"name": "A", "value": ""}, "tags": [], "expect": {"value": "### A\n\n### B\n\ntwo\n"}}
+{"id": "replace-keeps-fenced-payload", "clause": "BF-REP-1", "op": "replace", "body": "### PoC\n\n```\nline1\n\n\n\nline2\n```\n\n### Affected versions\n\nold\n", "args": {"name": "Affected versions", "value": "new"}, "tags": [], "expect": {"value": "### PoC\n\n```\nline1\n\n\n\nline2\n```\n\n### Affected versions\n\nnew\n"}}
+{"id": "replace-no-spacer", "clause": "BF-REP-1", "op": "replace", "body": "### A\none\n### B\ntwo\n", "args": {"name": "A", "value": "uno"}, "tags": [], "expect": {"value": "### A\nuno\n### B\ntwo\n"}}
+{"id": "replace-missing", "clause": "BF-REP-2", "op": "replace", "body": "### A\n\na\n", "args": {"name": "Severity", "value": "x"}, "tags": [], "expect": {"error": "not_found"}}
+{"id": "replace-duplicate", "clause": "BF-REP-2", "op": "replace", "body": "### Severity\n\nLow\n\n### Severity\n\nHigh\n", "args": {"name": "Severity", "value": "x"}, "tags": [], "expect": {"error": "duplicate"}}
+{"id": "replace-disputed", "clause": "BF-REP-2", "op": "replace", "body": "### A\n\n> ### Severity\n\n### Severity\n\nLow\n", "args": {"name": "Severity", "value": "x"}, "tags": [], "expect": {"error": "ambiguous"}}
+{"id": "replace-value-with-boundary", "clause": "BF-REP-3", "op": "replace", "body": "### A\n\na\n\n### B\n\nb\n", "args": {"name": "A", "value": "x\n### Security mailing list thread\nforged"}, "tags": [], "expect": {"error": "ambiguous"}}
+{"id": "replace-value-with-bare-hashes", "clause": "BF-REP-3", "op": "replace", "body": "### A\n\na\n", "args": {"name": "A", "value": "x\n###"}, "tags": [], "expect": {"error": "ambiguous"}}
+{"id": "replace-value-with-cr-boundary", "clause": "BF-REP-3", "op": "replace", "body": "### A\n\na\n", "args": {"name": "A", "value": "x\r### B"}, "tags": [], "expect": {"error": "ambiguous"}}
+{"id": "replace-value-heading-shaped", "clause": "BF-REP-4", "op": "replace", "body": "### A\n\na\n\n### B\n\nb\n", "args": {"name": "A", "value": "x\n> ### B"}, "tags": [], "expect": {"error": "ambiguous"}}
+{"id": "replace-current-span-heading-shaped", "clause": "BF-REP-4", "op": "replace", "body": "### A\n\n- ### Note\n\n### B\n\nb\n", "args": {"name": "A", "value": "x"}, "tags": [], "expect": {"error": "ambiguous"}}
+{"id": "replace-value-fence-captures-next-heading", "clause": "BF-REP-5", "op": "replace", "body": "### A\n\none\n\n### B\n\n```\n\n### C\n\nc\n", "args": {"name": "A", "value": "```"}, "tags": [], "expect": {"error": "ambiguous"}}
+{"id": "replace-value-fence-inside-is-fine", "clause": "BF-REP-1", "op": "replace", "body": "### A\n\none\n\n### B\n\nb\n", "args": {"name": "A", "value": "```\ncode\n```"}, "tags": [], "expect": {"value": "### A\n\n```\ncode\n```\n\n### B\n\nb\n"}}
+{"id": "replace-value-may-not-quote-a-heading-even-in-a-fence", "clause": "BF-REP-3", "op": "replace", "body": "### A\n\none\n", "args": {"name": "A", "value": "```\n### B\n```"}, "tags": [], "expect": {"error": "ambiguous"}}
+{"id": "replace-in-block-only-field-is-absent", "clause": "BF-REP-2", "op": "replace", "body": "### A\n\n```\n### Severity\nCritical\n```\n", "args": {"name": "Severity", "value": "Low"}, "tags": [], "expect": {"error": "not_found"}}
+{"id": "normalise-line-endings", "clause": "BF-NORM-1", "op": "normalise", "body": "### A\r\n\r\na\r\n### B\rb\n", "args": {}, "tags": [], "expect": {"value": {"text": "### A\n\na\n### B\nb\n", "changes": [{"line": 1, "kind": "line_endings"}], "needs_decision": []}}}
+{"id": "normalise-headings", "clause": "BF-NORM-3", "op": "normalise", "body": "### Severity ##\n\nLow\n\n###\tCWE\n\nx\n", "args": {}, "tags": [], "expect": {"value": {"text": "### Severity\n\nLow\n\n### CWE\n\nx\n", "changes": [{"line": 1, "kind": "heading"}, {"line": 5, "kind": "heading"}], "needs_decision": []}}}
+{"id": "normalise-known-name", "clause": "BF-NORM-3", "op": "normalise", "body": "### Short public summary\n\nx\n\n### short public summary\n\ny\n", "args": {"known_fields": ["Short public summary"]}, "tags": [], "expect": {"value": {"text": "### Short public summary\n\nx\n\n### short public summary\n\ny\n", "changes": [{"line": 1, "kind": "heading_name"}], "needs_decision": []}}}
+{"id": "normalise-closes-unclosed-fence", "clause": "BF-NORM-2", "op": "normalise", "body": "### A\n\n```\ncode\n\n### B\n\nb\n", "args": {}, "tags": [], "expect": {"value": {"text": "### A\n\n```\ncode\n```\n\n### B\n\nb\n", "changes": [{"line": 3, "kind": "unclosed_fence"}], "needs_decision": []}}}
+{"id": "normalise-leaves-fence-that-would-move-a-heading", "clause": "BF-NORM-2", "op": "normalise", "body": "### A\n\n```\na\n\n### B\n\n~~~\n### C\nx\n~~~\n", "args": {}, "tags": [], "expect": {"value": {"text": "### A\n\n```\na\n\n### B\n\n~~~\n### C\nx\n~~~\n", "changes": [], "needs_decision": []}}}
+{"id": "normalise-drops-identical-duplicate", "clause": "BF-NORM-4", "op": "normalise", "body": "### Severity\n\nLow\n\n### A\n\na\n\n### Severity\n\nLow\n", "args": {}, "tags": [], "expect": {"value": {"text": "### Severity\n\nLow\n\n### A\n\na\n", "changes": [{"line": 9, "kind": "duplicate_dropped"}], "needs_decision": []}}}
+{"id": "normalise-reports-differing-duplicate", "clause": "BF-NORM-4", "op": "normalise", "body": "### Severity\n\nLow\n\n### Severity\n\nHigh\n", "args": {}, "tags": [], "expect": {"value": {"text": "### Severity\n\nLow\n\n### Severity\n\nHigh\n", "changes": [], "needs_decision": [{"field": "Severity", "kind": "duplicate", "lines": [1, 5]}]}}}
+{"id": "normalise-keep-resolves-duplicate", "clause": "BF-NORM-4", "op": "normalise", "body": "### Severity\n\nLow\n\n### Severity\n\nHigh\n", "args": {"keep": {"Severity": 5}}, "tags": [], "expect": {"value": {"text": "### Severity\n\nHigh\n", "changes": [{"line": 1, "kind": "duplicate_resolved"}], "needs_decision": []}}}
+{"id": "normalise-container-heading", "clause": "BF-NORM-5", "op": "normalise", "body": "### A\n\n> ### Severity\n\n### Severity\n\nLow\n", "args": {"known_fields": ["Severity"]}, "tags": [], "expect": {"value": {"text": "### A\n\n> ### Severity\n\n### Severity\n\nLow\n", "changes": [], "needs_decision": [{"field": "Severity", "kind": "container-heading", "lines": [3]}]}}}
+{"id": "normalise-container-heading-unknown-name", "clause": "BF-NORM-5", "op": "normalise", "body": "### A\n\n> ### Note\n", "args": {"known_fields": ["Severity"]}, "tags": [], "expect": {"value": {"text": "### A\n\n> ### Note\n", "changes": [], "needs_decision": []}}}
+{"id": "normalise-never-rewrites-blocks", "clause": "BF-NORM-3", "op": "normalise", "body": "### A\n\n```\n### Severity ##\r\n```\n", "args": {}, "tags": [], "expect": {"value": {"text": "### A\n\n```\n### Severity ##\n```\n", "changes": [{"line": 4, "kind": "line_endings"}], "needs_decision": []}}}
+{"id": "normalise-canonical-is-unchanged", "clause": "BF-NORM-6", "op": "normalise", "body": "### A\n\na\n\n```\nx\n```\n\n### B\n\nb\n", "args": {"known_fields": ["A", "B"]}, "tags": [], "expect": {"value": {"text": "### A\n\na\n\n```\nx\n```\n\n### B\n\nb\n", "changes": [], "needs_decision": []}}}
+{"id": "escape-text-boundary", "clause": "BF-WRITE-1", "op": "escape_text", "body": "see\n### Security mailing list thread\nx\n", "args": {}, "tags": [], "expect": {"value": "see\n\\### Security mailing list thread\nx\n"}}
+{"id": "escape-text-bare-and-tab", "clause": "BF-WRITE-1", "op": "escape_text", "body": "###\n###\tSeverity\n####not\n", "args": {}, "tags": [], "expect": {"value": "\\###\n\\###\tSeverity\n####not\n"}}
+{"id": "escape-text-cr-lines", "clause": "BF-WRITE-1", "op": "escape_text", "body": "a\r### B\r\nc\n", "args": {}, "tags": [], "expect": {"value": "a\r\\### B\r\nc\n"}}
+{"id": "escape-text-loose-headings", "clause": "BF-WRITE-1", "op": "escape_text", "body": "> ### Severity\n- ### CWE\n ### B\n", "args": {}, "tags": ["escape-loose"], "expect": {"value": "\\> ### Severity\n\\- ### CWE\n\\ ### B\n"}}
+{"id": "escape-text-inside-fence", "clause": "BF-WRITE-3", "op": "escape_text", "body": "```\n### Severity\nCritical\n```\n", "args": {}, "tags": [], "expect": {"value": "```\n\\### Severity\nCritical\n```\n"}}
+{"id": "escape-text-inside-jira-macro", "clause": "BF-WRITE-3", "op": "escape_text", "body": "{code}\n### Severity\n{code}\n", "args": {}, "tags": [], "expect": {"value": "{code}\n\\### Severity\n{code}\n"}}
+{"id": "escape-body-quoted-copy", "clause": "BF-WRITE-2", "op": "escape_body", "body": "### A\n\n```\n### Severity\nCritical\n```\n\n### Severity\n\nLow\n", "args": {}, "tags": [], "expect": {"value": "### A\n\n```\n\\### Severity\nCritical\n```\n\n### Severity\n\nLow\n"}}
+{"id": "escape-body-jira-block", "clause": "BF-WRITE-2", "op": "escape_body", "body": "### A\n\n{noformat}\n### CWE\n{noformat}\n", "args": {}, "tags": [], "expect": {"value": "### A\n\n{noformat}\n\\### CWE\n{noformat}\n"}}
+{"id": "escape-body-open-block-marks-nothing", "clause": "BF-WRITE-2", "op": "escape_body", "body": "### A\n\n```\n### B\n\nb\n", "args": {}, "tags": [], "expect": {"value": "### A\n\n```\n### B\n\nb\n"}}
+{"id": "escape-body-leaves-fields-and-loose-lines", "clause": "BF-WRITE-2", "op": "escape_body", "body": "### A\n\n> ### B\n\n### C\r\n\r\nc\r\n", "args": {}, "tags": [], "expect": {"value": "### A\n\n> ### B\n\n### C\r\n\r\nc\r\n"}}
diff --git a/tools/body-field-contract/contract.md b/tools/body-field-contract/contract.md
new file mode 100644
index 00000000..15a9f79f
--- /dev/null
+++ b/tools/body-field-contract/contract.md
@@ -0,0 +1,157 @@
+<!-- SPDX-License-Identifier: Apache-2.0
+ https://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!-- START doctoc generated TOC please keep comment here to allow auto update -->
+<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
+**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
+
+- [Body-field contract](#body-field-contract)
+ - [Lines](#lines)
+ - [Field boundaries](#field-boundaries)
+ - [Names](#names)
+ - [Closed code blocks](#closed-code-blocks)
+ - [Which heading is the field](#which-heading-is-the-field)
+ - [Ambiguity: decisions, never guesses](#ambiguity-decisions-never-guesses)
+ - [Operations](#operations)
+ - [list fields](#list-fields)
+ - [extract](#extract)
+ - [replace](#replace)
+ - [normalise](#normalise)
+ - [What a writer must escape](#what-a-writer-must-escape)
+ - [escape text](#escape-text)
+ - [escape body](#escape-body)
+ - [Implementations](#implementations)
+ - [Conformance suite](#conformance-suite)
+
+<!-- END doctoc generated TOC please keep comment here to allow auto update -->
+
+<!-- SPDX-License-Identifier: Apache-2.0
+ https://www.apache.org/licenses/LICENSE-2.0 -->
+
+# Body-field contract
+
+A tracker issue body is a sequence of named fields, each a `### <Name>` heading followed by its value.
+Every reader and writer of those fields (the GitHub tool, vetted-ops, the local-files tracker, the Jira bridge, the CVE JSON generator, and any implementation in another language) MUST read and write them by the rules below, so that one body gives one set of fields to all of them.
+The rules are written so a reporter's text, however it is formatted, can never become a field or make one field absorb another: in particular, the private mailing-list thread can never be read into the public summary.
+
+The key words MUST, MUST NOT, SHOULD and MAY are to be read as described in [RFC 2119](https://www.rfc-editor.org/rfc/rfc2119).
+Each rule has an identifier (`BF-…`); every case of the [conformance suite](#conformance-suite) names the rule it tests.
+The field roles and names a project uses are described in [`tools/github/issue-template.md`](../github/issue-template.md); this document is the authoritative statement of how fields are found.
+
+## Lines
+
+- **BF-LINE-1.** A line ends at `\n`, `\r\n` or `\r`, or at the end of the body. An implementation MUST keep each line's ending when it splits, so that joining the lines gives the body back byte for byte.
+- **BF-LINE-2.** No other character ends a line: form feed, vertical tab, `U+0085`, `U+2028`, `U+2029` and the like are line content. (Python's `str.splitlines` breaks on them; an implementation MUST NOT use such a splitter.)
+
+## Field boundaries
+
+- **BF-BOUND-1.** A line is a *field boundary* if and only if it starts, at column 0, with `###` followed by a space, a tab or the end of the line. A bare `###` is a boundary with an empty name.
+- **BF-BOUND-2.** Every field boundary ends the field before it and starts a new section, **whether or not it sits inside a code block**. A field's value is always exactly one section of that split; no fence, Jira macro or duplicate heading can extend it past the next boundary.
+- **BF-BOUND-3.** `####`, `###x`, and a `###` line behind indentation, `>` or a list marker are not boundaries. Text before the first boundary is a preamble and belongs to no field.
+
+## Names
+
+- **BF-NAME-1.** A boundary's name is the rest of the line with leading and trailing spaces and tabs removed and then a closing run of `#` removed, when that run stands alone or follows a space or tab (`### Severity ##` names `Severity`; `### C#` names `C#`).
+- **BF-NAME-2.** Names compare exactly: case-sensitive, inner whitespace significant. Only [normalise](#normalise) with known field names collapses inner whitespace (BF-NORM-3). An implementation MAY offer a lenient lookup (case-folded, whitespace-collapsed) as a documented extension, provided two lenient matches outside closed blocks are a duplicate (BF-SEL-2).
+
+## Closed code blocks
+
+A *closed block* is a code block whose opener and closer are both present. Blocks are found by one scan over the whole body, independent of field boundaries.
+
+- **BF-BLOCK-1.** A CommonMark fence opener is a line of up to three spaces, then a run of three or more backticks or three or more tildes, then an info string. A backtick run whose info string holds a backtick is not an opener. Four or more spaces of indentation is not an opener.
+- **BF-BLOCK-2.** A fence is closed by a later line of up to three spaces, then a run of the *same* character at least as long as the opener's, then nothing but spaces or tabs.
+- **BF-BLOCK-3.** A Jira block opener is a line that starts, after spaces or tabs, with `{code}`, `{code:<anything>}` or `{noformat}`, and does not hold a second occurrence of that macro's name. It is closed by the next line holding the bare macro (`{code}` or `{noformat}`) anywhere.
+- **BF-BLOCK-4.** Inside an open block, nothing else opens: a fence inside a `{code}` block, or a `{code}` inside a fence, is content.
+- **BF-BLOCK-5.** A block left open at the end of the body is not a closed block: it marks nothing.
+
+## Which heading is the field
+
+- **BF-SEL-1.** The field named *N* is the one section named *N* whose boundary lies **outside every closed block**. A boundary inside a closed block never starts a field: a field whose only copies are inside closed blocks is absent (not found), never read from the quoted copy.
+- **BF-SEL-2.** Two or more sections named *N* outside closed blocks are a *duplicate*: reading or writing *N* MUST fail, whatever the copies hold.
+- **BF-SEL-3.** A field's value is its section's lines after the boundary, with at most one leading blank line and at most one trailing blank line (when the section has more than one line) removed. Other blank lines are kept.
+- **BF-SEL-4.** The list of a body's fields is the names of the sections outside closed blocks, in document order, repeats included.
+
+## Ambiguity: decisions, never guesses
+
+Some bodies read differently in different renderers. An implementation MUST NOT pick a reading; it reports a *decision* and refuses the field.
+
+- **BF-CONT-1. Container headings.** A heading-shaped line that is not a boundary (`###` behind indentation, `>` or list markers, any number of them) is content. When it names the requested field and sits outside a fence, as a CommonMark reader pairs fences or as a reader that only accepts fences at column 0 does, reading or writing that field MUST fail as ambiguous. [Normalise](#normalise) reports it as a `container-heading` decision for known field names.
+- **BF-MACRO-1. Jira macros opened mid-line.** Jira's renderer opens `{code}` and `{noformat}` anywhere in a line. A line outside closed blocks that, pairing its macros left to right, leaves one open, followed by a later line closing it, with one or more field boundaries between, is a `macro-ambiguous` decision. Reading or writing the field the macro opens in, or any field whose boundary it would hide, MUST fail as ambiguous. A macro opened and closed on the same line is text; one never [...]
+
+## Operations
+
+Every implementation provides these four operations; a writer of untrusted text also provides the [writer operations](#what-a-writer-must-escape). Errors are one of three kinds: `not_found`, `duplicate` (a not-found kind for callers that only distinguish found from not found) and `ambiguous`.
+
+### list fields
+
+- Input: a body. Output: the field names (BF-SEL-4). Never fails.
+
+### extract
+
+- Input: a body and a field name. Output: the field's value (BF-SEL-3), with its own line endings.
+- **BF-EXT-1.** Fails `ambiguous` under BF-CONT-1 or BF-MACRO-1, checked before anything else; `not_found` when the field is absent (BF-SEL-1); `duplicate` under BF-SEL-2.
+
+### replace
+
+- Input: a body, a field name and a new value. Output: the new body.
+- **BF-REP-1.** Everything outside the field's value is preserved byte for byte, the heading line included. The value is written in the line-ending convention of the field's heading line; a run of trailing line endings is reduced to one, and a value with content always ends in one. The blank-line spacer after the heading and before the next field is kept when the old value had it. An empty value leaves one spacer line, or none for the last field. Replacing a value with itself returns the [...]
+- **BF-REP-2.** Fails as [extract](#extract) does for the field.
+- **BF-REP-3.** Fails `ambiguous` when the new value holds a field boundary (BF-BOUND-1) on any line, split by BF-LINE-1 — inside a fence or not.
+- **BF-REP-4.** Fails `ambiguous` when the old or the new value holds a heading-shaped line outside fences (behind any indentation, `>` or list marker).
+- **BF-REP-5. Whole-body preservation.** Fails `ambiguous` unless the rewritten body has the same sections, each boundary inside or outside closed blocks as before, every other section byte-identical, and no `container-heading` or `macro-ambiguous` decision. A value that opens a fence or a macro reaching past its field is refused this way.
+
+### normalise
+
+- Input: a body, optionally known field names and a *keep* map (field name → the input line number of the copy to keep). Output: the canonical text, a list of *changes* `{line, kind}` and a list of *decisions* `{field, kind, lines}`. Line numbers are 1-based lines of the input; changes are ordered by line, then kind. Never fails.
+- **BF-NORM-1.** `\r\n` and lone `\r` become `\n`; one `line_endings` change at the first such line.
+- **BF-NORM-2.** A fence left open is closed in the field it opens in, after the last non-blank line before the next boundary (`unclosed_fence`, at the opener), unless the closer would move a boundary into or out of a closed block; then it stays open.
+- **BF-NORM-3.** A boundary outside closed blocks is rewritten `### <Name>` (`heading`); with known field names, a name equal to one once inner whitespace is collapsed (case kept) takes the known spelling (`heading_name`). Lines inside closed blocks are never rewritten.
+- **BF-NORM-4.** Copies of a field outside closed blocks that hold the same value (after stripping) collapse to the first (`duplicate_dropped`, at each dropped heading). Differing copies stay and give a `duplicate` decision listing their heading lines, unless *keep* names one of them, which is kept (`duplicate_resolved`). Copies inside closed blocks are never counted, dropped or reported.
+- **BF-NORM-5.** `container-heading` decisions (BF-CONT-1, for known names) and `macro-ambiguous` decisions (BF-MACRO-1: the first hidden field; the opener's line, then each hidden boundary's) are reported, never resolved.
+- **BF-NORM-6.** Normalising a normalised body changes nothing.
+
+## What a writer must escape
+
+A writer that puts untrusted text (a report, a comment, a scanner finding) into a body provides one or both of two writer operations, and MUST follow the rules below.
+Escaping is a leading `\` on the line, which renders as the same visible text and is never parsed as structure; nothing else on the line changes.
+
+### escape text
+
+- Input: untrusted text that will become (part of) one field's value. Output: the escaped text. Never fails (a writer MAY refuse text instead of escaping it).
+- **BF-WRITE-1.** Every line of the text that is a field boundary (BF-BOUND-1), split by BF-LINE-1, MUST be escaped. Heading-shaped lines behind indentation, `>` or list markers SHOULD be escaped too, for readers that ignore fences (cases tagged `escape-loose`).
+- **BF-WRITE-3.** The rule holds inside fences and Jira macros: a writer MUST NOT rely on a block to protect text, since blocks only decide which heading is the field (BF-SEL-1), never where a field ends.
+
+### escape body
+
+- Input: a whole body whose own boundaries are its fields (a report a writer stores as is). Output: the escaped body. Never fails.
+- **BF-WRITE-2.** Every field boundary inside a closed block (BF-BLOCK-1 to BF-BLOCK-5) MUST be escaped, so quoted text never becomes a copy of a field; boundaries outside closed blocks, and every other line, MUST be left as they are.
+ A writer SHOULD also close a fence the body leaves open in the field it opens in (as BF-NORM-2 does), never past another field's boundary.
+
+## Implementations
+
+| Implementation | Language | Status | Notes |
+|---|---|---|---|
+| [`tools/github-body-field`](../github-body-field/README.md) (`github_body_field.parser`) | Python | reference | The source every Python copy is pinned to. |
+| [`tools/vetted-ops`](../vetted-ops/README.md) (`vetted_ops.body_field_format`) | Python | byte-identical copy | Pinned by `tests/test_body_field_parity.py`. |
+| [`tools/local-tracker`](../local-tracker/README.md) (`magpie_local_tracker.body_field_format`, used by `sections`) | Python | byte-identical copy | Pinned by `tests/test_vendored_parser.py`; lenient name lookup (BF-NAME-2). Writer: escape text (`sections.escape_field_lines`), escape body (`sections.escape_quoted_fields`). |
+| [`tools/jira`](../jira/README.md) (`jira_bridge.body_field_format`, used by `markup`) | Python | byte-identical copy | Pinned by `tests/test_vendored_parser.py`; reads wiki `h1.`–`h3.` headings outside closed blocks as `### <Heading>` first, lenient name lookup. Writer: escape body (`markup.escape_quoted_fields`). |
+| [`tools/security-management`](../security-management/README.md) (`security_management.shared.body.inert_block`) | Python | writer only | Escape text: the import's inert block, which escapes the lines inside its own fence. |
+
+## Conformance suite
+
+[`conformance/cases.jsonl`](conformance/cases.jsonl) holds the language-neutral cases, one JSON object per line:
+
+```json
+{"id": "outside-copy-wins", "clause": "BF-SEL-1", "op": "extract",
+ "body": "### A\n\n```\n### Severity\nCritical\n```\n\n### Severity\n\nLow\n",
+ "args": {"name": "Severity"}, "tags": [], "expect": {"value": "Low\n"}}
+```
+
+- `op` is `list_fields`, `extract`, `replace`, `normalise`, `escape_text` or `escape_body`; `args` holds `name` (extract, replace), `value` (replace), `known_fields` and `keep` (normalise, optional). The input body or text is `body`.
+- `expect` is `{"value": …}` (a list of names, a value, a body, or `{"text", "changes", "needs_decision"}`) or `{"error": "not_found" | "duplicate" | "ambiguous"}`.
+- `tags` mark cases that depend on an optional behaviour: `case-sensitive` and `inner-whitespace` (exact name matching, BF-NAME-2), which an implementation documenting a lenient lookup skips, and `escape-loose` (the SHOULD of BF-WRITE-1), which a writer that escapes only boundaries skips.
+- An implementation runs the `escape_text` and `escape_body` cases only for the writer operations it provides; a reader provides neither.
+
+`tools/github-body-field/tests/test_conformance.py` runs every case against every implementation in the repository through a thin adapter per implementation, and fails on the first case an implementation gets wrong.
+A new implementation (in another language, say) conforms by providing an adapter that, for each case, calls its own operation and returns the result in the `expect` shape — values compared exactly, errors by kind — and passes every case whose tags it does not opt out of.
+The simplest adapter is a program that reads `cases.jsonl` and prints one JSON object per line, `{"id", "result"}`, which the pytest runner compares; add it to the runner's adapter table with the condition under which it can run (a skip with a reason when its runtime is absent).
diff --git a/tools/github-body-field/README.md b/tools/github-body-field/README.md
index e5f5de12..190da3be 100644
--- a/tools/github-body-field/README.md
+++ b/tools/github-body-field/README.md
@@ -24,7 +24,7 @@
# github-body-field
-**Capability:** contract:tracker
+**Capability:** contract:tracker + contract:body-field
**Kind:** implementation
@@ -130,7 +130,7 @@ The same function is importable as `github_body_field.normalise(body, known_fiel
## Body format assumptions
-This parser is the one implementation of the body-field contract ([`tools/github/issue-template.md`](../github/issue-template.md)):
+This parser is the one implementation of the body-field contract ([`tools/body-field-contract/contract.md`](../body-field-contract/contract.md)):
every reader and writer of a field, `generate-cve-json` and `vetted-ops` (a byte-identical copy) included, goes through it.
- lines end at `\n`, `\r\n` or `\r` — not at the other characters `str.splitlines` breaks on;
diff --git a/tools/github-body-field/src/github_body_field/parser.py b/tools/github-body-field/src/github_body_field/parser.py
index 4e6e37b6..e10b42f5 100644
--- a/tools/github-body-field/src/github_body_field/parser.py
+++ b/tools/github-body-field/src/github_body_field/parser.py
@@ -21,7 +21,7 @@ each followed by the field's value. This module exposes a pure
parser/replacer so the CLI can run without ever bringing the body
into the agent's context, and so the (numerous) tricky edge cases
can be unit-tested in isolation. It is the one implementation of the
-body-field contract (tools/github/issue-template.md): every reader and
+body-field contract (tools/body-field-contract/contract.md): every reader and
writer of a field, generate-cve-json included, goes through it.
The contract:
diff --git a/tools/github-body-field/tests/test_conformance.py b/tools/github-body-field/tests/test_conformance.py
new file mode 100644
index 00000000..72634ae6
--- /dev/null
+++ b/tools/github-body-field/tests/test_conformance.py
@@ -0,0 +1,233 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""The body-field contract's conformance suite, run against every implementation.
+
+The cases are language-neutral (tools/body-field-contract/conformance/cases.jsonl);
+each implementation is reached through a thin adapter that turns a case into a
+call and the call's outcome into the case's ``expect`` shape. See
+tools/body-field-contract/contract.md, "Conformance suite".
+"""
+
+from __future__ import annotations
+
+import importlib
+import importlib.util
+import json
+import sys
+from collections.abc import Callable
+from dataclasses import dataclass
+from pathlib import Path
+from types import ModuleType
+from typing import Any
+
+import pytest
+
+from github_body_field import parser
+
+TOOLS = Path(__file__).resolve().parents[2]
+CASES_FILE = TOOLS / "body-field-contract" / "conformance" / "cases.jsonl"
+CASES: list[dict[str, Any]] = [
+ json.loads(line) for line in CASES_FILE.read_text(encoding="utf-8").split("\n") if line.strip()
+]
+ERROR_KINDS = {
+ "FieldNotFoundError": "not_found",
+ "DuplicateFieldError": "duplicate",
+ "AmbiguousFieldError": "ambiguous",
+}
+
+
+@dataclass(frozen=True)
+class Adapter:
+ """One implementation: the operations it provides (None for one it does not), and how it
+ differs where the contract allows."""
+
+ list_fields: Callable[[str], list[str]] | None = None
+ extract: Callable[[str, str], str | None] | None = None
+ replace: Callable[[str, str, str], str] | None = None
+ normalise: Callable[[str, list[str] | None, dict[str, int] | None], Any] | None = None
+ escape_text: Callable[[str], str] | None = None
+ escape_body: Callable[[str], str] | None = None
+ lenient_names: bool = False # BF-NAME-2's lenient lookup: skips the exact-name cases
+ stripped_values: bool = False # extract returns the value stripped
+ escapes_loose: bool = True # BF-WRITE-1's SHOULD: escapes heading-shaped lines behind containers too
+ lf_only: bool = False # the writer normalises line endings to LF before escaping
+
+
+def _module_from_file(name: str, path: Path) -> ModuleType:
+ if not path.is_file():
+ pytest.skip(f"source tree absent: {path}")
+ spec = importlib.util.spec_from_file_location(name, path)
+ assert spec is not None and spec.loader is not None
+ module = importlib.util.module_from_spec(spec)
+ sys.modules[name] = module # dataclasses resolve annotations through sys.modules
+ spec.loader.exec_module(module)
+ return module
+
+
+def _module_from_package(src: Path, name: str) -> ModuleType:
+ if not (src / name.replace(".", "/")).with_suffix(".py").is_file():
+ pytest.skip(f"source tree absent: {src}")
+ if str(src) not in sys.path:
+ sys.path.insert(0, str(src))
+ return importlib.import_module(name)
+
+
+def _parser_adapter(module: Any) -> Adapter:
+ return Adapter(module.list_fields, module.extract_field, module.replace_field, module.normalise)
+
+
+def _tracker_adapter(
+ module: Any, fields: Any, write: Callable[[str, str, str], str], **writer: Any
+) -> Adapter:
+ def replace(body: str, name: str, value: str) -> str:
+ # The trackers' writers append a missing field; the contract's replace does not.
+ if module.get_field(body, name) is None:
+ raise fields.FieldNotFoundError(name)
+ return write(body, name, value)
+
+ return Adapter(
+ module.list_fields if hasattr(module, "list_fields") else fields.list_fields,
+ module.get_field,
+ replace,
+ fields.normalise,
+ lenient_names=True,
+ stripped_values=True,
+ **writer,
+ )
+
+
+def _inert_text(body_module: Any) -> Callable[[str], str]:
+ def escape(text: str) -> str:
+ block = body_module.inert_block(text)
+ assert block["ok"], block
+ # The block's own fence wraps the escaped text: drop its first and last line.
+ return str(block["text"]).split("\n", 1)[1].rsplit("\n", 1)[0] + "\n"
+
+ return escape
+
+
+def _adapters() -> dict[str, Callable[[], Adapter]]:
+ def vetted_ops() -> Adapter:
+ path = TOOLS / "vetted-ops" / "src" / "vetted_ops" / "body_field_format.py"
+ return _parser_adapter(_module_from_file("_conformance_vetted_ops", path))
+
+ def local_tracker() -> Adapter:
+ sections = _module_from_package(TOOLS / "local-tracker" / "src", "magpie_local_tracker.sections")
+ return _tracker_adapter(
+ sections,
+ sections.fields,
+ lambda b, n, v: sections.set_field(b, n, v, 3)[0],
+ escape_text=sections.escape_field_lines,
+ escape_body=sections.escape_quoted_fields,
+ )
+
+ def jira() -> Adapter:
+ markup = _module_from_package(TOOLS / "jira" / "src", "jira_bridge.markup")
+ return _tracker_adapter(
+ markup,
+ markup.fields,
+ lambda b, n, v: markup.set_field(b, n, v)[0],
+ escape_body=markup.escape_quoted_fields,
+ )
+
+ def security_management() -> Adapter:
+ body = _module_from_package(TOOLS / "security-management" / "src", "security_management.shared.body")
+ return Adapter(escape_text=_inert_text(body), lf_only=True)
+
+ return {
+ "github-body-field": lambda: _parser_adapter(parser),
+ "vetted-ops": vetted_ops,
+ "local-tracker": local_tracker,
+ "jira": jira,
+ "security-management": security_management,
+ }
+
+
+ADAPTERS = _adapters()
+
+
+def run_case(adapter: Adapter, case: dict[str, Any]) -> dict[str, Any] | None:
+ """The case's outcome through ``adapter``, in the ``expect`` shape; None when it lacks the operation."""
+ args = case["args"]
+ body = case["body"]
+ op = getattr(adapter, case["op"])
+ if op is None:
+ return None
+ try:
+ if case["op"] in ("list_fields", "escape_text", "escape_body"):
+ return {"value": op(body)}
+ if case["op"] == "extract":
+ value = op(body, args["name"])
+ return {"error": "not_found"} if value is None else {"value": value}
+ if case["op"] == "replace":
+ return {"value": op(body, args["name"], args["value"])}
+ result = op(body, args.get("known_fields"), args.get("keep"))
+ return {
+ "value": {"text": result.text, "changes": result.changes, "needs_decision": result.needs_decision}
+ }
+ except LookupError as exc:
+ kind = ERROR_KINDS.get(type(exc).__name__)
+ if kind is None:
+ raise
+ return {"error": kind}
+
+
+def _lf(text: str) -> str:
+ return text.replace("\r\n", "\n").replace("\r", "\n")
+
+
+@pytest.mark.parametrize("implementation", sorted(ADAPTERS))
+@pytest.mark.parametrize("case", CASES, ids=[c["id"] for c in CASES])
+def test_conformance(implementation: str, case: dict[str, Any]) -> None:
+ adapter = ADAPTERS[implementation]()
+ if adapter.lenient_names and {"case-sensitive", "inner-whitespace"} & set(case["tags"]):
+ pytest.skip(f"{implementation} documents a lenient name lookup (BF-NAME-2)")
+ if not adapter.escapes_loose and "escape-loose" in case["tags"]:
+ pytest.skip(f"{implementation} escapes field boundaries only (BF-WRITE-1)")
+ if adapter.lf_only and case["op"] == "escape_text":
+ case = {**case, "body": _lf(case["body"]), "expect": {"value": _lf(case["expect"]["value"])}}
+ got = run_case(adapter, case)
+ if got is None:
+ pytest.skip(f"{implementation} does not provide {case['op']}")
+ expected = case["expect"]
+ if adapter.stripped_values and case["op"] == "extract" and "value" in expected and "value" in got:
+ expected, got = {"value": expected["value"].strip()}, {"value": got["value"].strip()}
+ assert got == expected, f"{case['id']} ({case['clause']})"
+
+
+def test_every_operation_has_an_implementation() -> None:
+ ops = {c["op"] for c in CASES}
+ for op in ops:
+ assert any(getattr(factory(), op) is not None for factory in ADAPTERS.values()), op
+
+
+def test_every_case_names_a_clause_of_the_contract() -> None:
+ contract = (TOOLS / "body-field-contract" / "contract.md").read_text(encoding="utf-8")
+ ids = [c["id"] for c in CASES]
+ assert len(ids) == len(set(ids))
+ for case in CASES:
+ assert f"**{case['clause']}" in contract, case["id"]
+
+
+def test_every_must_clause_has_a_case() -> None:
+ contract = (TOOLS / "body-field-contract" / "contract.md").read_text(encoding="utf-8")
+ clauses = {
+ line.split("**")[1].rstrip(".").split(".")[0]
+ for line in contract.splitlines()
+ if line.startswith("- **BF-")
+ }
+ assert clauses <= {c["clause"] for c in CASES}
diff --git a/tools/github/issue-template.md b/tools/github/issue-template.md
index 16b643ed..9b42146d 100644
--- a/tools/github/issue-template.md
+++ b/tools/github/issue-template.md
@@ -76,16 +76,14 @@ live in the project manifest.
## Body-field surgery
-Skills that update one field without touching the rest use the
-following pattern:
-
-1. **Read** the full body (`gh issue view <N> --json body --jq .body`).
-2. **Split** on `\n### ` to get per-field sections.
-3. **Replace** the target section's value (between its `### <name>\n\n`
- header and the next `### ` or end-of-body).
-4. **Join** the sections back together.
-5. **Write** the new body via
- `gh issue edit <N> --repo <tracker> --body-file <tmpfile>`.
+How a field is found, read and rewritten — field boundaries, code
+blocks, which heading is the field, and what is refused as ambiguous —
+is the [body-field contract](../body-field-contract/contract.md).
+Skills never split a body themselves: they read and write one field
+through an implementation of it, such as
+[`github-body-field`](../github-body-field/README.md) (`get` / `set`) or
+the `body-field-get` / `body-field-set` vetted operations, which keep
+everything outside the field byte-identical.
Never construct the body by string concatenation in a shell command —
literal backticks, `$(…)`, and newlines in the body are silently
diff --git a/tools/jira/README.md b/tools/jira/README.md
index 43929a12..e7ca9134 100644
--- a/tools/jira/README.md
+++ b/tools/jira/README.md
@@ -35,7 +35,7 @@
# JIRA bridge
-**Capability:** contract:tracker + contract:people + contract:security-tracker
+**Capability:** contract:tracker + contract:people + contract:security-tracker + contract:body-field
**Kind:** implementation
@@ -316,7 +316,7 @@ Under vetted-ops the URL, project and level are pinned by the policy's `[tracker
| `pending` / `publish` | No-ops: Jira writes are immediate. |
| `doctor` | URL, project, confirmed token, configured level, `/myself`, project reachability, and whether the level exists (403/404 on the listing reports *unverified*). |
-**Storage.** Body fields are `h3. <Heading>` wiki-markup sections of the description (markdown `###` sections are read too), read and written through a byte-identical copy of [`github-body-field`](../github-body-field/README.md)'s parser (`body_field_format.py`, kept exact by a test), so they follow the [body-field contract](../github/issue-template.md):
+**Storage.** Body fields are `h3. <Heading>` wiki-markup sections of the description (markdown `###` sections are read too), read and written through a byte-identical copy of [`github-body-field`](../github-body-field/README.md)'s parser (`body_field_format.py`, kept exact by a test), so they follow the [body-field contract](../body-field-contract/contract.md):
every column-0 `###` line ends a field, code block or not, a heading inside a closed code block is never a field, and a `{code}` / `{noformat}` macro opened mid-line before field headings is refused as ambiguous.
A wiki heading of level 1 to 3 outside closed blocks reads as `### <Heading>`; closed blocks are CommonMark fence pairs and `{code}` / `{code:…}` / `{noformat}` blocks opened at the start of a line and closed on the bare macro, and a block left open marks nothing.
`create` and `edit` escape every `###` line inside a closed block with a leading `\`, so quoted text never becomes a field copy. Names match with case and inner whitespace ignored; `field-get` and `field-set` exit `4` on a duplicate or disputed field, and `field-set` on a value that would add, hide or move a field heading.
diff --git a/tools/jira/src/jira_bridge/body_field_format.py b/tools/jira/src/jira_bridge/body_field_format.py
index 4e6e37b6..e10b42f5 100644
--- a/tools/jira/src/jira_bridge/body_field_format.py
+++ b/tools/jira/src/jira_bridge/body_field_format.py
@@ -21,7 +21,7 @@ each followed by the field's value. This module exposes a pure
parser/replacer so the CLI can run without ever bringing the body
into the agent's context, and so the (numerous) tricky edge cases
can be unit-tested in isolation. It is the one implementation of the
-body-field contract (tools/github/issue-template.md): every reader and
+body-field contract (tools/body-field-contract/contract.md): every reader and
writer of a field, generate-cve-json included, goes through it.
The contract:
diff --git a/tools/local-tracker/README.md b/tools/local-tracker/README.md
index 115c85e9..1def3f70 100644
--- a/tools/local-tracker/README.md
+++ b/tools/local-tracker/README.md
@@ -20,7 +20,7 @@
# Local file tracker
-**Capability:** contract:security-tracker
+**Capability:** contract:security-tracker + contract:body-field
**Kind:** implementation
@@ -78,7 +78,7 @@ It records:
| `title_source` | `key`, or `h1` when the title is the report's first `# ` heading. |
| `id` | `prefix`, zero-pad `width`, and `slug` when names carry a title slug (`2024-007-xss-in-login`). |
| `state` | `mode: field` (a metadata value) or `mode: directory` (a sub-folder per state, such as `open/` and `closed/`), and the values or folder names that count as open and closed. |
-| `field_heading_level` | The heading level of body fields (`###` by default). At `###` the [body-field contract](../github/issue-template.md) applies: every column-0 `###` line ends a field, code block or not, a heading inside a closed code block is never a field, a duplicate or disputed field is refused (exit `4`), and a field value has every line that would end a field escaped with a leading `\`; a whole report (`create`, `edit`) has every `###` line inside a closed block escaped and [...]
+| `field_heading_level` | The heading level of body fields (`###` by default). At `###` the [body-field contract](../body-field-contract/contract.md) applies: every column-0 `###` line ends a field, code block or not, a heading inside a closed code block is never a field, a duplicate or disputed field is refused (exit `4`), and a field value has every line that would end a field escaped with a leading `\`; a whole report (`create`, `edit`) has every `###` line inside a closed block escap [...]
| `comments_mode`, `rollup_mode` | `file` (beside the report) or `section` (a `## ` heading at the end of the report). |
| `url_template` | Optional private browse URL, for example a ViewVC or gitweb address. Without it, the `url` field is the path relative to the working copy. |
| `access_restricted` | The human-confirmed access check that unlocks writes. |
diff --git a/tools/local-tracker/src/magpie_local_tracker/body_field_format.py b/tools/local-tracker/src/magpie_local_tracker/body_field_format.py
index 4e6e37b6..e10b42f5 100644
--- a/tools/local-tracker/src/magpie_local_tracker/body_field_format.py
+++ b/tools/local-tracker/src/magpie_local_tracker/body_field_format.py
@@ -21,7 +21,7 @@ each followed by the field's value. This module exposes a pure
parser/replacer so the CLI can run without ever bringing the body
into the agent's context, and so the (numerous) tricky edge cases
can be unit-tested in isolation. It is the one implementation of the
-body-field contract (tools/github/issue-template.md): every reader and
+body-field contract (tools/body-field-contract/contract.md): every reader and
writer of a field, generate-cve-json included, goes through it.
The contract:
diff --git a/tools/skill-and-tool-validator/src/skill_and_tool_validator/__init__.py b/tools/skill-and-tool-validator/src/skill_and_tool_validator/__init__.py
index ffd341c2..7ff4677b 100644
--- a/tools/skill-and-tool-validator/src/skill_and_tool_validator/__init__.py
+++ b/tools/skill-and-tool-validator/src/skill_and_tool_validator/__init__.py
@@ -399,6 +399,7 @@ TOOL_CAPABILITIES = {
"contract:typed-decision",
"contract:people",
"contract:security-tracker",
+ "contract:body-field",
"substrate:analytics",
"substrate:sandbox",
"substrate:action-guard",
diff --git a/tools/spec-loop/specs/adapters.md b/tools/spec-loop/specs/adapters.md
index 3a62bf77..be3e6ed6 100644
--- a/tools/spec-loop/specs/adapters.md
+++ b/tools/spec-loop/specs/adapters.md
@@ -83,7 +83,9 @@ by swapping the adapter, not the skill.
for every reader and writer; `normalise`
returns the canonical body, its changes and the duplicate /
container-heading decisions it will not make, and reads and writes
- refuse an ambiguous field, #1672) and `tools/github-rollup/` (`contract:tracker`,
+ refuse an ambiguous field, #1672; the rules are the language-neutral
+ `tools/body-field-contract/` (`contract:body-field`), whose conformance
+ cases every implementation passes) and `tools/github-rollup/` (`contract:tracker`,
stdlib-only), which maintains the single status-rollup comment on a
tracker issue in a subprocess so the growing rollup body never enters
agent context.
diff --git a/tools/spec-loop/specs/security-issue-lifecycle.md b/tools/spec-loop/specs/security-issue-lifecycle.md
index 3031c3a6..8f4a2d41 100644
--- a/tools/spec-loop/specs/security-issue-lifecycle.md
+++ b/tools/spec-loop/specs/security-issue-lifecycle.md
@@ -202,7 +202,11 @@ publication, with a human gate and an audit-log entry at every step.
byte-identical copies of the parser (the Jira bridge after reading wiki
`h1.`–`h3.` headings outside closed blocks as `### <Heading>`), matching
names case-insensitively; a test runs every implementation over the same
- bodies and requires the same reads and writes.
+ bodies and requires the same reads and writes. The rules are stated once,
+ language-neutral, in `tools/body-field-contract/contract.md`
+ (`contract:body-field`, RFC 2119 clauses `BF-*`, with the writer
+ escapes for untrusted text), and its JSON Lines conformance cases, each
+ naming its clause, run against every implementation in the tree.
- **CVE fields come from the team or a confirmed proposal (#1672).** When
`generate-cve-json --report-json` lists missing or ambiguous fields,
sync, cve-allocate and deduplicate follow
diff --git a/tools/vendor-neutrality-score/src/vendor_neutrality_score/__init__.py b/tools/vendor-neutrality-score/src/vendor_neutrality_score/__init__.py
index a0c66b81..4047df9f 100644
--- a/tools/vendor-neutrality-score/src/vendor_neutrality_score/__init__.py
+++ b/tools/vendor-neutrality-score/src/vendor_neutrality_score/__init__.py
@@ -116,6 +116,7 @@ CONTRACT_POLICY: dict[str, tuple[str, str]] = {
VENDOR_BACKED,
"Security tracker for embargoed reports (GitHub / local files / private Jira)",
),
+ "contract:body-field": (AGNOSTIC, "Tracker body `### <Name>` field parsing and rewriting"),
}
# Which capability *contract* a skill actually invokes, keyed by
diff --git a/tools/vetted-ops/src/vetted_ops/body_field_format.py b/tools/vetted-ops/src/vetted_ops/body_field_format.py
index 4e6e37b6..e10b42f5 100644
--- a/tools/vetted-ops/src/vetted_ops/body_field_format.py
+++ b/tools/vetted-ops/src/vetted_ops/body_field_format.py
@@ -21,7 +21,7 @@ each followed by the field's value. This module exposes a pure
parser/replacer so the CLI can run without ever bringing the body
into the agent's context, and so the (numerous) tricky edge cases
can be unit-tested in isolation. It is the one implementation of the
-body-field contract (tools/github/issue-template.md): every reader and
+body-field contract (tools/body-field-contract/contract.md): every reader and
writer of a field, generate-cve-json included, goes through it.
The contract: