File size: 10,047 Bytes
8683ec7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env python3
"""
Register hadith_sahih_bukhari in sources/manifest.json (proposed_state: use) and
append the LICENSE_AUDIT.md addendum + NOTICE.md attribution section.

License basis: base classical Arabic text PD (author d. 256 AH / 870 CE). The
retrieval route is sunnah.com INDIVIDUAL hadith pages — explicitly permitted by
sunnah.com terms (section 8, verbatim-quoted in the manifest hadith_kutub_sittah
entry). No collection snapshots, no scraping of bulk endpoints, English
translations not stored.

Pipeline order: build_audit_mvp.py -> fetch_sunnah_bukhari_3350.py -> THIS
              -> ground_sunni_6_74.py -> verify.py

Idempotent: skips if the source id already present / markers already appended.
"""
import json
from pathlib import Path

ROOT = Path(__file__).resolve().parents[2]
MANIFEST = ROOT / "sources" / "manifest.json"
AUDIT = ROOT / "docs" / "LICENSE_AUDIT.md"
NOTICE = ROOT / "NOTICE.md"
REPORT = ROOT / "raw" / "sources" / "hadith_sahih_bukhari" / "extraction_report.json"

AUDIT_MARK = "<!-- bukhari-addendum-2026-11-27 -->"
NOTICE_MARK = "<!-- bukhari-notice-2026-11-27 -->"

ENTRY = {
    "id": "hadith_sahih_bukhari",
    "category": "hadith",
    "traditions": ["sunni"],
    "title_ar": "صحيح البخاري",
    "title_en": "Sahih al-Bukhari",
    "author": "Muhammad ibn Isma'il al-Bukhari",
    "author_death": "256 AH / 870 CE",
    "work_class": "classical",
    "license": {
        "value": "public_domain_base_text",
        "verified": "legal_analysis",
        "evidence_urls": [
            "https://sunnah.com/bukhari:3350",
            "https://sunnah.com/about",
        ],
        "summary": (
            "Base classical Arabic text is public domain (author d. 256 AH / 870 CE). "
            "Retrieval route: sunnah.com individual hadith pages — per sunnah.com terms "
            "section 8 ('Reproducing individual hadith or selections of hadith for a "
            "teaching/didactic/presentation purpose is permitted'), individual-hadith "
            "retrieval with attribution is permitted; mass reproduction of entire books/"
            "collections is NOT permitted and is not done. sunnah.com's English "
            "translations are not stored (stripped from captures). The structured API "
            "requires a key and was not used (403 without key)."
        ),
    },
    "redistribution": {
        "huggingface": "allowed",
        "basis": "PD base Arabic text via individual-hadith page retrieval with full "
                 "attribution (retrieval_url, retrieval_date, sha256); two individual "
                 "pages captured, not a collection snapshot; English translations excluded.",
    },
    "access": {
        "method": "programmatic_page_fetch",
        "urls": ["https://sunnah.com/bukhari:3350"],
        "terms_verified": True,
        "rate_or_key": "API key required for structured bulk access (sunnah.com API); "
                       "not needed for the two individual pages used here",
        "notes": (
            "VERBATIM from sunnah.com/about, section 8 'Reproduction, Copying, Scraping': "
            "'We do not permit the scraping of our data, nor mass reproduction of entire "
            "books or collections on other websites... Reproducing individual hadith or "
            "selections of hadith for a teaching/didactic/presentation purpose is "
            "permitted.' This source stores individual hadith pages only, each with "
            "attribution per retrieval; api.sunnah.com/v1 returned 403 without a key "
            "(attempted 2026-11-27) and no bulk route was used."
        ),
    },
    "format": "HTML individual-hadith pages (sunnah.com); G2 gate substrate = verbatim "
              "Arabic matn extraction (.txt) with sha256 sidecar",
    "provenance_plan": {
        "recorded_fields": [
            "source_id", "edition", "volume", "page", "sha256",
            "retrieval_url", "retrieval_date", "collection_numbering",
        ],
        "retrieval_date": None,
        "sha256": None,
    },
    "planned_use": [
        "Sunni hadith linked to 6:74 (audit MVP grounding)",
        "Kutub al-Sittah citations inside tafsir (mufassir_cited edges)",
    ],
    "proposed_state": "use",
    "blocking_phases": [],
    "flags": [
        "Numbering policy: primary keys use in-book numbering + edition reference, NOT "
        "sunnah.com IDs; site IDs stored only as external cross-reference (retrieval_url).",
        "One work per identity: per-work source entry, split out from the umbrella "
        "hadith_kutub_sittah entry (which remains for the other five collections).",
    ],
}

AUDIT_ADDENDUM = """
## Addendum 2026-11-27 — Sahih al-Bukhari grounding from sunnah.com individual pages

- Work: Sahih al-Bukhari (Muhammad ibn Isma'il al-Bukhari, d. 256 AH / 870 CE). The
  classical Arabic base text is public domain by duration everywhere.
- Registered as per-work source `hadith_sahih_bukhari` (split out of the umbrella
  `hadith_kutub_sittah` entry; the umbrella entry keeps the verbatim terms quote and
  remains the plan for the other five collections).
- Acquisition channel: sunnah.com INDIVIDUAL hadith pages. api.sunnah.com/v1 was
  attempted first (X-API-Key without a registered key) and returned 403 Forbidden —
  the key-gated API was NOT used. Two individual pages fetched, 2026-11-27:
  bukhari:3350 (grounding target for h_006-074_sunni, linked to 6:74) and
  bukhari:3351 (auxiliary conflation check for the legacy 'hyena-like creature'
  summary element). This is "reproducing individual hadith", explicitly permitted by
  sunnah.com terms section 8 (verbatim-quoted in the manifest); no scraping of
  listing/bulk endpoints; no collection snapshot; no API snapshot dump.
- Copyright hygiene: sunnah.com's English translations (Muhsin Khan) are present on
  the live pages but REMOVED from the stored captures before commit — the published
  dataset stores the Arabic matn only. Full-page capture sha256 of the original
  response is recorded in extraction_report.json as retrieval evidence; the stored
  HTML sha256 is of the English-stripped artifact.
- Text integrity: substrate = verbatim Arabic matn block extracted from the page
  (raw/sources/hadith_sahih_bukhari/sunnah_com_bukhari_3350.txt, sha256 sidecar);
  data/hadith.jsonl text_ar is a byte-level substring of that substrate (verify.py
  gate G2). Chain (sanad) and matn are stored exactly as displayed, including the
  full Isma'il ibn Abdillah -> Abu Hurayrah chain.
- Verification uplift: h_006-074_sunni moves from verification=unverified_recall
  (memory-based legacy enrichment, empty text_ar) to verification=verified
  (verbatim text_ar, stored substrate, full provenance). The rijal/audit states stay
  unresolved by design: isnaad evaluation still requires stored Tahdhib al-Kamal /
  Taqrib text (not ingested), and the ghayb rule keeps the matn audited for
  transmission and internal coherence only.
- Honesty finding recorded in the audit: the legacy memory-based summary claimed
  Azar is "transformed into a hyena-like creature and cast into the Fire". The
  verbatim #3350 text contains NO transformation/hyena wording (تعحول absent); what
  the matn says is that Azar is shown a blood-stained dhabh (ذِيخٍ مُلْتَطِخ) caught
  by its legs and thrown into the Fire. The auxiliary check of bukhari:3351 under
  sunnah.com numbering found an entirely different hadith (Ka'ba images of Ibrahim
  and Maryam), so the legacy hyena element cannot be attributed to that number
  either; its source narration is recorded as UNRESOLVED, not guessed.
"""

NOTICE_SECTION = """
## 3c. Sahih al-Bukhari — sunnah.com individual-page grounding

The classical Arabic text of Sahih al-Bukhari (al-Bukhari, d. 256 AH / 870 CE) is
public domain. The hadith grounded in `data/hadith.jsonl` (`h_006-074_sunni`,
linked to 6:74) was retrieved from the individual page
<https://sunnah.com/bukhari:3350> on 2026-11-27 (sha256 sidecars recorded in
`raw/sources/hadith_sahih_bukhari/`). This is reproduction of an individual hadith
with attribution for research/teaching purposes, permitted by sunnah.com's terms of
use (section 8); no collection snapshot, no bulk/scraped retrieval, and no API
snapshot was used (the key-gated API returned 403 and was not used).
sunnah.com's English translations are not stored — they were removed from the page
captures before storage. Retrieval URL, date and sha256 hashes are recorded in
`raw/sources/hadith_sahih_bukhari/extraction_report.json` and in the hadith record's
provenance. Attribution: text via sunnah.com (https://sunnah.com).
"""


def main() -> None:
    m = json.loads(MANIFEST.read_text(encoding="utf-8"))
    if not any(s["id"] == ENTRY["id"] for s in m["sources"]):
        m["sources"].append(ENTRY)
        sc = m.setdefault("summary_counts", {})
        sc["total_sources"] = len(m["sources"])
        state = ENTRY["proposed_state"]
        key = "proposed_use" if state == "use" else "proposed_use_with_notice" if state == "use_with_notice" else None
        if key:
            sc[key] = sc.get(key, 0) + 1
        MANIFEST.write_text(json.dumps(m, ensure_ascii=False, indent=1) + "\n",
                            encoding="utf-8")
        print(f"manifest: registered {ENTRY['id']} (summary_counts bumped)")
    else:
        print(f"manifest: {ENTRY['id']} already present — skipped")

    if AUDIT_MARK not in AUDIT.read_text(encoding="utf-8"):
        with AUDIT.open("a", encoding="utf-8") as f:
            f.write(AUDIT_MARK + AUDIT_ADDENDUM)
        print("LICENSE_AUDIT.md: addendum appended")
    else:
        print("LICENSE_AUDIT.md: addendum marker present — skipped")

    if NOTICE_MARK not in NOTICE.read_text(encoding="utf-8"):
        with NOTICE.open("a", encoding="utf-8") as f:
            f.write(NOTICE_MARK + NOTICE_SECTION)
        print("NOTICE.md: section 3c appended")
    else:
        print("NOTICE.md: notice marker present — skipped")


if __name__ == "__main__":
    main()