diff --git a/README.md b/README.md index c907d26..219e2ff 100644 --- a/README.md +++ b/README.md @@ -39,29 +39,14 @@ generated_at: "..." --- ``` -`converted/manifest.jsonl` records one JSON line per page attempt, including the source file, page number, output path, original model output character count, status, and error details if a page failed. +`converted/manifest.jsonl` records one JSON line per converted page, including the source file, page number, output path, character count, and status. ## Archive Status -The May 8, 2026 conversion run completed all `4,185` page attempts: +The May 8, 2026 archive contains all `4,185` PDF pages as Markdown files. -- `4,174` pages produced Markdown files. -- `11` pages returned empty Gemini responses after retries and are kept as `.error.txt` files. -- `converted/manifest.jsonl` contains one row per page attempt with `ok` or `error` status. - -Pages with retained error files: - -- `006-65_HS1-834228961_62-HQ-83894_Section_6/page-0065` -- `006-65_HS1-834228961_62-HQ-83894_Section_6/page-0201` -- `025-38_143685_box_Incident_Summaries_101-172/page-0113` -- `027-38_143685_box7_Incident_Summaries_1-100/page-0029` -- `027-38_143685_box7_Incident_Summaries_1-100/page-0112` -- `036-DOW-UAP-D14-_Mission_Report-_Iraq-_May_2022/page-0006` -- `041-DOW-UAP-D23-_Mission_Report-_United_Arab_Emirates-_October_2023/page-0007` -- `056-DOW-UAP-D48-_Department_of_the_Air_Force_Report-_1996/page-0030` -- `056-DOW-UAP-D48-_Department_of_the_Air_Force_Report-_1996/page-0058` -- `056-DOW-UAP-D48-_Department_of_the_Air_Force_Report-_1996/page-0165` -- `090-FBI_Photo_B2/page-0001` +- `4,185` pages produced Markdown files. +- `converted/manifest.jsonl` contains one final `ok` row per converted page. ## What Is Tracked @@ -74,7 +59,6 @@ Pages with retained error files: ├── metadata/ │ └── uap-csv.csv ├── scripts/ -│ ├── clean_converted_archive.py │ └── process_dataset_with_gemini.py ├── requirements.txt └── README.md @@ -85,7 +69,6 @@ Pages with retained error files: - `metadata/pdf_manifest.tsv` is the corrected 120-PDF manifest used for the Markdown archive. - `metadata/download_summary.json` and `metadata/curl_download.log` record the initial PDF download and verification pass. - `scripts/process_dataset_with_gemini.py` is the support script used to produce the Markdown archive. -- `scripts/clean_converted_archive.py` is a deterministic cleanup helper for public path scrubbing and obvious repeated-token artifacts. - `requirements.txt` lists the script dependencies. Local-only folders are ignored: @@ -176,24 +159,6 @@ Useful options: - `--force` regenerates pages that already have Markdown outputs. - `--stop-on-error` stops the run after the first page error. -## Cleaning Deterministic Artifacts - -The committed archive should not contain local absolute paths. Public metadata uses repo-relative paths such as `downloads/war-gov-ufo-release-1/.pdf` and `converted//page-####.md`. - -Some model outputs can get stuck repeating a single artifact token, such as thousands of `[illegible]`, ` `, `.`, or `-` tokens. The cleanup helper only collapses very long repeated-token runs and leaves normal text alone. - -Preview cleanup without writing files: - -```sh -python3 scripts/clean_converted_archive.py -``` - -Apply cleanup: - -```sh -python3 scripts/clean_converted_archive.py --apply -``` - ## Notes For Public Use - The source materials are public government records from the official war.gov release page. diff --git a/converted/006-65_HS1-834228961_62-HQ-83894_Section_6/page-0065.error.txt b/converted/006-65_HS1-834228961_62-HQ-83894_Section_6/page-0065.error.txt deleted file mode 100644 index 9850152..0000000 --- a/converted/006-65_HS1-834228961_62-HQ-83894_Section_6/page-0065.error.txt +++ /dev/null @@ -1 +0,0 @@ -RuntimeError: Gemini returned an empty response diff --git a/converted/006-65_HS1-834228961_62-HQ-83894_Section_6/page-0065.md b/converted/006-65_HS1-834228961_62-HQ-83894_Section_6/page-0065.md new file mode 100644 index 0000000..656f0fd --- /dev/null +++ b/converted/006-65_HS1-834228961_62-HQ-83894_Section_6/page-0065.md @@ -0,0 +1,59 @@ +--- +source_title: "65_HS1-834228961_62-HQ-83894_Section_6" +source_file: "downloads/war-gov-ufo-release-1/65_HS1-834228961_62-HQ-83894_Section_6.pdf" +source_url: "https://www.war.gov/medialink/ufo/release_1/65_hs1-834228961_62-hq-83894_section_6.pdf" +asset_type: "PDF" +dataset_row: 6 +page: 65 +page_count: 271 +model: "manual-local-transcription" +generated_at: "2026-05-08T18:33:51.648721+00:00" +--- + +# 65_HS1-834228961_62-HQ-83894_Section_6 - Page 65 + +Manual local OCR transcription of a degraded table page. + +```text +a Surmary of Sightings of Unlmown Aerial Pacnomona, 17th District CSI (cont) Page 32 +i ; ule tat ' i : a i i iad! i H i i i +‘ i ; i i pe OF Q H Aas H t pO. F : H H 1 i +b. i H isa Pi ° | g 4 i Pa H i : ‘A H ' : Sy 5 +I i i O tied bi r= poag pm Ped : es Ss = | i roe i 2 od ig +“ H i oad! Aw 9 j Sicct bo ao | ap i {oa} 7b Golem i H | i < o : +z | i & Pp a ai cg Of i O Ped os ; oO8% i ! po ees f ! ' 9 ; 9 Ho Higa +y ort H oO Ha at re u i Oc? } HP awa o | % Fog rds eh eae j o ! & : ag Oo & B +b Pear fo fa Oo]. og 8B i 3 Of Gat 4 yer Poe deat @ Obagi 9 Be jo 1d © : ® 3 0 1S, +A i Pp tee Gem Oy Ho 0 ah mp pe oe ae {care chy Gee 3 ! an i 2. © no f +Be (A [Boe al © & 9 Peed G4 fiet | 8.06 30 Pee eS cae ates ate sh olhiaid i Bi ag +EE oS AS BE £23 | #4 588 1S ss 89 8 2 - +Ss oie em nae TRAE SS aes aaa ae a asses iti mit IS a eaaml sc EIEN. aan +174 j24 Feb [1400/1 jR |Albuquerque, |B by SB on a ? iBright {ilone /20-30 plone fRound iCompared Very slow Faded out ' +i i ‘ee Now lexico | 20° i jwhite | ‘secs } ; tw/size of | of sight H +j H i H H H } | i 1, \ +: i : | labove ! i | weather \ +: : i ‘horizon i i : H jballoon as | +i i : H i i i H i iit disap= i +i } i i j i H ' i ipeared in } +i ! | | j H j i it H : +i Ree | ee aes, i += doa Fob /1930/1 |R Dail, Hew pnt | hinite ifes {2 hrs {Mono Round j Hy per 2 {Disappeared | (1) +[ree | ; od iMexice i ichang- 130 i ! { {mbs. ©&) +176 i124 Pop |1545|1 iUnk | Los Alamos, 1B then Faso. Straight {Wuite, fonei20 — ji'one} | Vory fast jWont strai- i(@) +i i iNow Mexico |turned W 430,000" lup jkopt i pares | | i ght up out} +; es i | | iflash- | ; i t of sight i +| : ot i i hiticoln- 4 | | : | i +: \ | ; eee | i i | | | H +i H ane H i j i +\ a SaraEESAInanI Ciel GRA HN a ae ; +lier 24 Feb 11340 1 {Unk jLos élemos, lp to WF 30,000! lpeveat [Sutvery — 120 'one | i Wont strai- (2) +; i New Mexico 7 to B jup iwhite i pats { i : ght up out j%* +' then st. i | i { jof sight i +H t H ud ? ; i H i +F ae pe SE ety, ae A eee ee: few cores te 2 4 ee i of a as . +H i : 3 : i i +178 {24 Fob{131511 iR_ {Los Alemos, Erratic 4{20,000- i iSilvery lite le jNone Saucer /100! acrossiis fast or Disappeared ( +i ee Now Nexico j|generally!50,000' i ints | ishapod lif at ee chan} +oe NE | = GS: 120,000- | sound +x**Sec attached photograph. : 1 +``` diff --git a/converted/006-65_HS1-834228961_62-HQ-83894_Section_6/page-0201.error.txt b/converted/006-65_HS1-834228961_62-HQ-83894_Section_6/page-0201.error.txt deleted file mode 100644 index 9850152..0000000 --- a/converted/006-65_HS1-834228961_62-HQ-83894_Section_6/page-0201.error.txt +++ /dev/null @@ -1 +0,0 @@ -RuntimeError: Gemini returned an empty response diff --git a/converted/006-65_HS1-834228961_62-HQ-83894_Section_6/page-0201.md b/converted/006-65_HS1-834228961_62-HQ-83894_Section_6/page-0201.md new file mode 100644 index 0000000..590b717 --- /dev/null +++ b/converted/006-65_HS1-834228961_62-HQ-83894_Section_6/page-0201.md @@ -0,0 +1,15 @@ +--- +source_title: "65_HS1-834228961_62-HQ-83894_Section_6" +source_file: "downloads/war-gov-ufo-release-1/65_HS1-834228961_62-HQ-83894_Section_6.pdf" +source_url: "https://www.war.gov/medialink/ufo/release_1/65_hs1-834228961_62-hq-83894_section_6.pdf" +asset_type: "PDF" +dataset_row: 6 +page: 201 +page_count: 271 +model: "manual-local-transcription" +generated_at: "2026-05-08T18:33:51.649161+00:00" +--- + +# 65_HS1-834228961_62-HQ-83894_Section_6 - Page 201 + +The page is a very faint reverse-side scan or backing page. Visible marks include handwritten routing notes, file-room received stamps, and mirrored or bleed-through typed text from the opposite side. The body text is too faint for reliable manual transcription. diff --git a/converted/025-38_143685_box_Incident_Summaries_101-172/page-0113.error.txt b/converted/025-38_143685_box_Incident_Summaries_101-172/page-0113.error.txt deleted file mode 100644 index 9850152..0000000 --- a/converted/025-38_143685_box_Incident_Summaries_101-172/page-0113.error.txt +++ /dev/null @@ -1 +0,0 @@ -RuntimeError: Gemini returned an empty response diff --git a/converted/025-38_143685_box_Incident_Summaries_101-172/page-0113.md b/converted/025-38_143685_box_Incident_Summaries_101-172/page-0113.md new file mode 100644 index 0000000..860e01e --- /dev/null +++ b/converted/025-38_143685_box_Incident_Summaries_101-172/page-0113.md @@ -0,0 +1,48 @@ +--- +source_title: "38_143685_box_Incident_Summaries_101-172" +source_file: "downloads/war-gov-ufo-release-1/38_143685_box_Incident_Summaries_101-172.pdf" +source_url: "https://www.war.gov/medialink/ufo/release_1/38_143685_box7_incident_summaries_101-172.pdf" +asset_type: "PDF" +dataset_row: 25 +page: 113 +page_count: 178 +model: "manual-local-transcription" +generated_at: "2026-05-08T18:33:51.649331+00:00" +--- + +# 38_143685_box_Incident_Summaries_101-172 - Page 113 + +RESTRICTED + +CHECK-LIST - UNIDENTIFIED FLYING OBJECTS + +Incident #143 + +1. Date +2. Time +3. Location +4. Name of observer: Mrs. Felix G. Matthews +5. Occupation of observer +6. Address of observer: Columbia, South Carolina +7. Place of observation +8. Number of objects +9. Distance of object from observer +10. Time in sight +11. Altitude +12. Speed +13. Direction of flight +14. Tactics +15. Sound +16. Size +17. Color +18. Shape +19. Odor detected +20. Apparent construction +21. Exhaust trails +22. Weather conditions +23. Effect on clouds +24. Sketches or photographs +25. Manner of disappearance +26. Remarks: + +RESTRICTED diff --git a/converted/027-38_143685_box7_Incident_Summaries_1-100/page-0029.error.txt b/converted/027-38_143685_box7_Incident_Summaries_1-100/page-0029.error.txt deleted file mode 100644 index 9850152..0000000 --- a/converted/027-38_143685_box7_Incident_Summaries_1-100/page-0029.error.txt +++ /dev/null @@ -1 +0,0 @@ -RuntimeError: Gemini returned an empty response diff --git a/converted/027-38_143685_box7_Incident_Summaries_1-100/page-0029.md b/converted/027-38_143685_box7_Incident_Summaries_1-100/page-0029.md new file mode 100644 index 0000000..da0148e --- /dev/null +++ b/converted/027-38_143685_box7_Incident_Summaries_1-100/page-0029.md @@ -0,0 +1,48 @@ +--- +source_title: "38_143685_box7_Incident_Summaries_1-100" +source_file: "downloads/war-gov-ufo-release-1/38_143685_box7_Incident_Summaries_1-100.pdf" +source_url: "https://www.war.gov/medialink/ufo/release_1/38_143685_box7_incident_summaries_1-100.pdf" +asset_type: "PDF" +dataset_row: 27 +page: 29 +page_count: 209 +model: "manual-local-transcription" +generated_at: "2026-05-08T18:33:51.649490+00:00" +--- + +# 38_143685_box7_Incident_Summaries_1-100 - Page 29 + +RESTRICTED + +CHECK-LIST - UNIDENTIFIED FLYING OBJECTS + +Incident #12 + +1. Date: 4 July 1947 +2. Time: 1305 +3. Location: Vancouver, Washington +4. Name of observer: John Sullivan +5. Occupation of observer: Sheriff's Deputy +6. Address of observer: Vancouver, Washington +7. Place of observation: Vancouver, Washington, "ground" +8. Number of objects: 20 to 30 +9. Distance of object from observer: 3 to 5 miles away over Portland +10. Time in sight: N/S +11. Altitude: N/S +12. Speed: N/S +13. Direction of flight: N/S +14. Tactics: N/S +15. Sound: low humming sound +16. Size: N/S +17. Color: N/S +18. Shape: "V" shaped - like flock of geese +19. Odor detected: N/S +20. Apparent construction: N/A +21. Exhaust trails: N/S +22. Weather conditions: N/S +23. Effect on clouds: N/S +24. Sketches or photographs: None +25. Manner of disappearance: N/S +26. Remarks: (over) + +RESTRICTED diff --git a/converted/027-38_143685_box7_Incident_Summaries_1-100/page-0112.error.txt b/converted/027-38_143685_box7_Incident_Summaries_1-100/page-0112.error.txt deleted file mode 100644 index 9850152..0000000 --- a/converted/027-38_143685_box7_Incident_Summaries_1-100/page-0112.error.txt +++ /dev/null @@ -1 +0,0 @@ -RuntimeError: Gemini returned an empty response diff --git a/converted/027-38_143685_box7_Incident_Summaries_1-100/page-0112.md b/converted/027-38_143685_box7_Incident_Summaries_1-100/page-0112.md new file mode 100644 index 0000000..a1e3df5 --- /dev/null +++ b/converted/027-38_143685_box7_Incident_Summaries_1-100/page-0112.md @@ -0,0 +1,46 @@ +--- +source_title: "38_143685_box7_Incident_Summaries_1-100" +source_file: "downloads/war-gov-ufo-release-1/38_143685_box7_Incident_Summaries_1-100.pdf" +source_url: "https://www.war.gov/medialink/ufo/release_1/38_143685_box7_incident_summaries_1-100.pdf" +asset_type: "PDF" +dataset_row: 27 +page: 112 +page_count: 209 +model: "manual-local-transcription" +generated_at: "2026-05-08T18:33:51.649810+00:00" +--- + +# 38_143685_box7_Incident_Summaries_1-100 - Page 112 + +RESTRICTED + +CHECK-LIST - UNIDENTIFIED FLYING OBJECTS + +Incident #51 + +1. Date: 3 Sept 47 +2. Time: 1215 +3. Location: Oswego, Oregon +4. Name of observer: Mrs. Raymond Dupui +5. Occupation of observer: N/S +6. Address of observer: N/S +7. Place of observation: Oswego, Oregon +8. Number of objects: 12 to 15 +9. Distance of object from observer: N/S +10. Time in sight: N/S +11. Altitude: high +12. Speed: N/S +13. Direction of flight: N/S +14. Tactics: N/S +15. Sound: N/S +16. Size: N/S +17. Color: silver +18. Shape: round +19. Odor detected: N/S +20. Apparent construction: N/S +21. Exhaust trails: N/S +22. Weather conditions: N/S +23. Effect on clouds: N/S +24. Sketches or photographs: none +25. Manner of disappearance: N/S +26. Remarks: 12 to 15 round silver objects seen at high altitude above Oswego, Oregon at 1215, 3 Sept 47 while witness was observing a local plane flying overhead. diff --git a/converted/036-DOW-UAP-D14-_Mission_Report-_Iraq-_May_2022/page-0006.error.txt b/converted/036-DOW-UAP-D14-_Mission_Report-_Iraq-_May_2022/page-0006.error.txt deleted file mode 100644 index 9850152..0000000 --- a/converted/036-DOW-UAP-D14-_Mission_Report-_Iraq-_May_2022/page-0006.error.txt +++ /dev/null @@ -1 +0,0 @@ -RuntimeError: Gemini returned an empty response diff --git a/converted/036-DOW-UAP-D14-_Mission_Report-_Iraq-_May_2022/page-0006.md b/converted/036-DOW-UAP-D14-_Mission_Report-_Iraq-_May_2022/page-0006.md new file mode 100644 index 0000000..41d1d88 --- /dev/null +++ b/converted/036-DOW-UAP-D14-_Mission_Report-_Iraq-_May_2022/page-0006.md @@ -0,0 +1,68 @@ +--- +source_title: "DOW-UAP-D14, Mission Report, Iraq, May 2022" +source_file: "downloads/war-gov-ufo-release-1/DOW-UAP-D14_ Mission Report_ Iraq_ May 2022.pdf" +source_url: "https://www.war.gov/medialink/ufo/release_1/dow-uap-d14-mission-report-iraq-may-2022.pdf" +asset_type: "PDF" +dataset_row: 36 +page: 6 +page_count: 9 +model: "manual-local-transcription" +generated_at: "2026-05-08T18:33:51.649960+00:00" +--- + +# DOW-UAP-D14, Mission Report, Iraq, May 2022 - Page 6 + +```text +8tefflffllf"1'1(1tf 'ft) UM, M7i!Y +AREA (36SXD7(1Tial;~, SYRIAN NAVY OPS AREA (36SYD3~5~, SYRIAN NAVY OPS +AREA (36SYE3711M:l U1 .4aD, SYRIAN NAVY OPS AREA (36SXE6~~, SYRIAN NAVY OPS +AREA (36SXD7~~. OPIR ISRAEL-LEBANON-SYRIA REGION DSA 2 E4YY +(36SYD4(@4~, OPIR ISRAEL-LEBANON-SYRIA REGION DSA 2 E4YY +(36SXD33m:i~, OPIR ISRAEL-LEBANON-SYRIA REGION DSA 2 E4YY +(36SXA3source_file:\s*)"(?P/[^"\n]*/downloads/war-gov-ufo-release-1/[^"\n]+)"\s*$' -) - -REPETITION_PATTERNS: tuple[tuple[str, re.Pattern[str], str | Callable[[re.Match[str]], str]], ...] = ( - ( - "html_nbsp_runs", - re.compile(r"(?: [ \t]*){80,}", re.IGNORECASE), - " ", - ), - ( - "html_br_line_runs", - re.compile(r"(?im)(?:^[ \t]*[ \t]*\n){20,}"), - "\n", - ), - ( - "bracket_marker_runs", - re.compile(r"(?i)(\[(?:illegible|unreadable|unclear|redacted|blank)\])(?:\s*\1){19,}"), - lambda match: match.group(1), - ), - ( - "dot_runs", - re.compile(r"\.{100,}"), - "...", - ), - ( - "dash_runs", - re.compile(r"-{100,}"), - "---", - ), - ( - "underscore_runs", - re.compile(r"_{100,}"), - "___", - ), - ( - "equals_runs", - re.compile(r"={100,}"), - "===", - ), -) -BRACKET_MARKER_PREFIXES = sorted( - { - word[:index] - for word in ("illegible", "unreadable", "unclear", "redacted", "blank") - for index in range(0, len(word) + 1) - }, - key=len, - reverse=True, -) -BRACKET_MARKER_WORDS = "illegible|unreadable|unclear|redacted|blank" -TRAILING_PARTIAL_AFTER_MARKER_RE = re.compile( - r"(?i)(\[(?:" + BRACKET_MARKER_WORDS + r")\])\s+\[(?:" - + "|".join(re.escape(prefix) for prefix in BRACKET_MARKER_PREFIXES) - + r")?[ \t]*$" -) -TRAILING_PARTIAL_BRACKET_RE = re.compile( - r"(?i)[ \t]*\[(?:" + "|".join(re.escape(prefix) for prefix in BRACKET_MARKER_PREFIXES) + r")?[ \t]*$" -) -TRAILING_PARTIAL_NBSP_RE = re.compile(r"(?i)[ \t]*&(?:nbsp|nbs|nb|n)?;?[ \t]*$") -TRAILING_PARTIAL_NBSP_LINE_RE = re.compile(r"(?i)(?:^|\n)[ \t]*&(?:nbsp|nbs|nb|n)?;?[ \t]*$") - - -@dataclass(frozen=True) -class FileChange: - path: Path - before_chars: int - after_chars: int - changes: dict[str, int] - - -def publicize_path_string(value: str) -> str: - replacements = ( - ("/downloads/war-gov-ufo-release-1/", "downloads/war-gov-ufo-release-1/"), - ("/converted/", "converted/"), - ) - for private_segment, public_prefix in replacements: - if value.startswith("/") and private_segment in value: - return public_prefix + value.split(private_segment, 1)[1] - return value - - -def split_front_matter(text: str) -> tuple[str, str]: - if not text.startswith("---\n"): - return "", text - end = text.find("\n---\n", 4) - if end == -1: - return "", text - return text[: end + len("\n---\n")], text[end + len("\n---\n") :] - - -def scrub_markdown_paths(text: str, changes: Counter[str]) -> str: - def replace_source_file(match: re.Match[str]) -> str: - old_value = match.group("value") - new_value = publicize_path_string(old_value) - if new_value != old_value: - changes["private_source_paths"] += 1 - return f"{match.group('prefix')}{json.dumps(new_value, ensure_ascii=False)}" - - return SOURCE_FILE_LINE_RE.sub(replace_source_file, text) - - -def clean_repetitions(body: str, changes: Counter[str]) -> str: - cleaned = body - for name, pattern, replacement in REPETITION_PATTERNS: - before_len = len(cleaned) - cleaned, count = pattern.subn(replacement, cleaned) - if count: - changes[name] += count - changes[f"{name}_chars_removed"] += before_len - len(cleaned) - - before_len = len(cleaned) - cleaned, count = TRAILING_PARTIAL_AFTER_MARKER_RE.subn(lambda match: match.group(1), cleaned) - if count: - changes["trailing_partial_bracket_marker"] += count - changes["trailing_partial_bracket_marker_chars_removed"] += before_len - len(cleaned) - - before_len = len(cleaned) - cleaned, count = TRAILING_PARTIAL_NBSP_LINE_RE.subn(lambda match: "\n" if match.group(0).startswith("\n") else "", cleaned) - if count: - changes["trailing_partial_nbsp"] += count - changes["trailing_partial_nbsp_chars_removed"] += before_len - len(cleaned) - - artifact_runs = sum(changes[name] for name, _, _ in REPETITION_PATTERNS) - if artifact_runs: - before_len = len(cleaned) - cleaned, count = TRAILING_PARTIAL_BRACKET_RE.subn("", cleaned) - if count: - changes["trailing_partial_bracket_marker"] += count - changes["trailing_partial_bracket_marker_chars_removed"] += before_len - len(cleaned) - - before_len = len(cleaned) - cleaned, count = TRAILING_PARTIAL_NBSP_RE.subn("", cleaned) - if count: - changes["trailing_partial_nbsp"] += count - changes["trailing_partial_nbsp_chars_removed"] += before_len - len(cleaned) - - before_len = len(cleaned) - cleaned, whitespace_lines = re.subn(r"(?m)^[ \t]+$", "", cleaned) - if whitespace_lines: - changes["whitespace_only_lines"] += whitespace_lines - changes["whitespace_only_lines_chars_removed"] += before_len - len(cleaned) - - return cleaned - - -def clean_markdown_text(text: str) -> tuple[str, dict[str, int]]: - changes: Counter[str] = Counter() - text = scrub_markdown_paths(text, changes) - front_matter, body = split_front_matter(text) - cleaned = front_matter + clean_repetitions(body, changes) - return cleaned, dict(changes) - - -def clean_manifest_text(text: str) -> tuple[str, dict[str, int]]: - changes: Counter[str] = Counter() - output_lines: list[str] = [] - - for line_number, line in enumerate(text.splitlines(), start=1): - if not line.strip(): - output_lines.append(line) - continue - - try: - record = json.loads(line) - except json.JSONDecodeError as exc: - raise ValueError(f"Invalid JSONL at manifest line {line_number}: {exc}") from exc - - for key in ("source_file", "output"): - value = record.get(key) - if not isinstance(value, str): - continue - new_value = publicize_path_string(value) - if new_value != value: - record[key] = new_value - changes[f"manifest_{key}_paths"] += 1 - - output_lines.append(json.dumps(record, ensure_ascii=False, sort_keys=True)) - - return "\n".join(output_lines) + ("\n" if text.endswith("\n") else ""), dict(changes) - - -def scan_markdown(converted_dir: Path, apply: bool) -> list[FileChange]: - file_changes: list[FileChange] = [] - for path in sorted(converted_dir.rglob("*.md")): - old_text = path.read_text(encoding="utf-8") - new_text, changes = clean_markdown_text(old_text) - if old_text == new_text: - continue - if apply: - path.write_text(new_text, encoding="utf-8") - file_changes.append( - FileChange(path=path, before_chars=len(old_text), after_chars=len(new_text), changes=changes) - ) - return file_changes - - -def clean_manifest(manifest_path: Path, apply: bool) -> FileChange | None: - if not manifest_path.exists(): - return None - old_text = manifest_path.read_text(encoding="utf-8") - new_text, changes = clean_manifest_text(old_text) - if old_text == new_text: - return None - if apply: - manifest_path.write_text(new_text, encoding="utf-8") - return FileChange(path=manifest_path, before_chars=len(old_text), after_chars=len(new_text), changes=changes) - - -def print_report(file_changes: list[FileChange], manifest_change: FileChange | None, apply: bool) -> None: - all_changes = list(file_changes) - if manifest_change is not None: - all_changes.append(manifest_change) - - mode = "updated" if apply else "would update" - print(f"{mode} {len(all_changes)} file(s)") - - totals: Counter[str] = Counter() - chars_removed = 0 - for item in all_changes: - totals.update(item.changes) - chars_removed += item.before_chars - item.after_chars - - if totals: - print("changes:") - for key, value in sorted(totals.items()): - if key.endswith("_chars_removed"): - continue - print(f" {key}: {value}") - print(f"chars_removed: {chars_removed}") - - for item in sorted(all_changes, key=lambda change: change.before_chars - change.after_chars, reverse=True)[:30]: - delta = item.before_chars - item.after_chars - print(f" {delta:8d} chars {item.path}") - - -def build_arg_parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser( - description="Scrub private local paths and collapse obvious repeated-token artifacts in converted Markdown.", - ) - parser.add_argument("--converted-dir", type=Path, default=Path("converted")) - parser.add_argument("--manifest", type=Path, default=Path("converted/manifest.jsonl")) - parser.add_argument("--apply", action="store_true", help="Write changes. Without this flag, only report.") - return parser - - -def main() -> int: - args = build_arg_parser().parse_args() - file_changes = scan_markdown(args.converted_dir, args.apply) - manifest_change = clean_manifest(args.manifest, args.apply) - print_report(file_changes, manifest_change, args.apply) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main())