Files
SGF/scripts/archive-ledger-cost-scope.mjs
2026-11-04 09:37:20 +02:00

5 lines
1.6 KiB
JavaScript

import fs from 'node:fs';import path from 'node:path';import crypto from 'node:crypto';
const read=p=>JSON.parse(fs.readFileSync(p,'utf8')),hash=b=>crypto.createHash('sha256').update(b).digest('hex'),state=read('C:/laragon/data/sgf-tempo/run/modular-regression-current.json'),file='docs/GENERAL_LEDGER_DIRECT_COST_SCOPE.md',expected=read('docs/proofs/common-ledger-reports-20261103.json').next_scope.sha256,archive=path.join(state.root,'private/ledger-cost-approved-scope.md');if(state.port!==55439)throw Error('Owned archive root required');const current=fs.readFileSync(file,'utf8');
if(fs.existsSync(archive)){if(hash(fs.readFileSync(archive))!==expected)throw Error('Approved archive changed');}else{if(hash(current)!==expected)throw Error('Current scope differs from presented proposal');fs.writeFileSync(archive,current);}
const original=fs.readFileSync(archive,'utf8'),authorized='03/11/2026. **Autorização expressa recebida: «Autorizar o ciclo sintético proposto». Implementação/provas concluídas no recorte sintético; ver [entrega e limites](GENERAL_LEDGER_DIRECT_COST_DELIVERY.md).** O texto seguinte conserva o recorte apresentado; a decisão pedida no final é histórica. Não equivale a aceitação ou autorização de correcção de custo já lançado.';const updated=original.replace(/^03\/11\/2026\..+$/m,authorized);if(current!==original&&current!==updated)throw Error('Unexpected scope edits; preserve and inspect');if(current!==updated)fs.writeFileSync(file,updated);console.log(JSON.stringify({archive_matches_presented_scope:true,approved_scope_sha256:expected,authorization_recorded:true}));