/* * make-a309-rev3.mjs — the served research/a3-09-histogram-operator.md plus both earlier sections from * this session (return #251's fold-29 localization and return #254's fold-37 / local-test section, already * carried by a309-revised2.md) plus this pass's fold 37 -> 41 section. It is therefore a strict superset of * either earlier revision, so applying it loses nothing if they land first. * * Anchors: the served file's footer, and the superset property against it. Refuses to write if the footer is * not unique or if revised2 is not the served file plus a tail — a re-fetched or re-integrated source fails * loudly instead of half applying. * * Inputs: a309-served.md (served, sha 9fb18274…), ../job617/a309-revised2.md (sha b106fe5c…), a309-section3.md. * Output: a309-revised3.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 = '../job617/a309-revised2.md'; const SECTION = 'a309-section3.md'; const OUT = 'a309-revised3.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)'); 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-rev3.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 revised2: ${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);