Documentation Index
Fetch the complete documentation index at: https://mintlify.com/xxyoudeadpunkxx/canon-boundary-guard-for-gpt-project/llms.txt
Use this file to discover all available pages before exploring further.
extract_proof.py extracts mechanical proof-of-read from text or Markdown files. Given a file and an optional heading, it returns the exact section heading, the first 5 words, the last 5 words, and the line range — the required fields for Canon Boundary Guard proof-of-read. The output can be embedded directly into an active_l0_sources entry or used to anchor a source inspection claim in a CANON_STATE_DELTA.
This script does not make provenance decisions. It only extracts mechanical evidence from a file’s content. The operator is responsible for determining whether the extracted section constitutes valid L0 evidence.
Usage
Arguments
Positional argument. Path to the text or Markdown file to inspect. The file is read with
utf-8-sig encoding. If the file does not exist, the script exits with an error message.Markdown heading to select, including the
# prefix characters. Example: "## L0 Evidence". If omitted, the script inspects the full file content and reports "FULL_FILE" as the heading.See Heading selection logic for exact matching rules.Emit output as a JSON object. When omitted, output is human-readable key-value lines.
Output
- Human-readable
- JSON report
source, heading, line_range, first_5_words, last_5_words, word_count. The line_range is printed as start-end (both inclusive, 1-based).Heading selection logic
When--heading is provided, the script uses a two-pass lookup:
-
Exact full-line match — scans every line in the file for a line whose stripped content is identical to the
--headingvalue. For example,--heading "## L0 Evidence"matches a line that reads exactly## L0 Evidence(after stripping trailing newline). This is the preferred match. -
Heading-text match — if no exact match is found, the script strips leading
#characters and surrounding whitespace from both the--headingvalue and each line in the file, then matches on the resulting text. For example,--heading "## L0 Evidence"would match a line reading### L0 Evidencevia this path.
ValueError and exits with an error message. To avoid ambiguity, always provide the full heading including # characters when the heading level is known.
Section boundary
A section begins at the matched heading line and ends immediately before the next heading of equal or higher level (i.e., the same number of# characters or fewer). The final section in a file extends to the last line.
The word_count field counts all whitespace-separated tokens in the section, including the heading line itself.
Short sections
If a section contains 10 words or fewer in total, bothfirst_5_words and last_5_words return the complete word list rather than truncating to 5. This prevents misleading output for very short sections such as headings with a single sentence of body text.
Encoding
Files are read withencoding="utf-8-sig". A UTF-8 BOM at the start of the file is silently stripped before processing. This matches the encoding behavior of validate_state.py and artifact_fingerprint.py for consistency across the toolchain.