/* * make-a309-rev4.mjs — research/a3-09-histogram-operator.md plus a fourth section: the fold-local exactness * verdict at every reachable fold (`exactness-ladder.mjs`). * * Chain, so applying this alone loses nothing: a309-revised3.md (the revision of return #266) already carries * the sections of returns #251 and #254, and is the served file plus a tail. This producer refuses to write * unless the served file's footer is unique and revised3 is that served file plus a tail, so a re-fetched or * re-integrated source fails loudly instead of half applying. * * Inputs: a309-served.md (served, sha 9fb18274…), a309-revised3.md (sha be31bab7…), a309-section4.md. * Output: a309-revised4.md. Deterministic; stdout is the artifact. Node >= 18, stdlib only, about 0.05 s. */ import { readFileSync, writeFileSync } from 'node:fs'; import crypto from 'node:crypto'; const SRC = 'a309-served.md'; const PREV = 'a309-revised3.md'; const SECTION = 'a309-section4.md'; const OUT = 'a309-revised4.md'; const FOOTER = '*This document states current understanding. Superseded claims, retired numbers and the reasons they changed are in [history/CHANGELOG.md](history/CHANGELOG.md), indexed by document.*'; const sha = (s) => crypto.createHash('sha256').update(s).digest('hex'); const served = readFileSync(SRC, 'utf8'); const prev = readFileSync(PREV, 'utf8'); const section = readFileSync(SECTION, 'utf8'); if (served.split(FOOTER).length !== 2) throw new Error(`${SRC}: the footer anchor is not unique`); if (prev.split(FOOTER).length !== 2) throw new Error(`${PREV}: the footer anchor is not unique`); if (!prev.startsWith(served.split(FOOTER)[0])) throw new Error(`${PREV} is not the served file plus a tail: re-fetch and rebuild`); if (section.includes('\n## ')) throw new Error('the new section must be a single section (no ## headings inside)'); if (!/^## The fold-local exactness verdict/.test(section)) throw new Error('the new section is not the one this producer was written for'); const [head, tailPart] = prev.split(FOOTER); const out = `${head.trimEnd()}\n\n${section.trimEnd()}\n\n${FOOTER}${tailPart}`; writeFileSync(OUT, out); console.log('# make-a309-rev4.mjs'); console.log(''); console.log(`served ${SRC} sha256 ${sha(served)} lines ${served.split('\n').length}`); console.log(`earlier rev ${PREV} sha256 ${sha(prev)} lines ${prev.split('\n').length}`); console.log(`new section ${SECTION} sha256 ${sha(section)} lines ${section.split('\n').length}`); console.log(`output ${OUT} sha256 ${sha(out)} lines ${out.split('\n').length} lines added over revised3: ${out.split('\n').length - prev.split('\n').length}`); console.log(''); console.log('sections in the output:'); for (const l of out.split('\n')) if (l.startsWith('## ')) console.log(' ' + l);